Skip to content

Commit d569012

Browse files
committed
Feat: 추천 루틴 화면 동작 분기 처리 (#T3-187)
1 parent e3d878c commit d569012

File tree

5 files changed

+70
-27
lines changed

5 files changed

+70
-27
lines changed

Projects/Presentation/Sources/MyPage/View/MypageView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ final class MypageView: BaseViewController<MypageViewModel> {
4141

4242
override func viewWillAppear(_ animated: Bool) {
4343
super.viewWillAppear(animated)
44+
45+
navigationController?.setNavigationBarHidden(false, animated: animated)
46+
4447
let appearance = UINavigationBarAppearance()
4548
appearance.configureWithOpaqueBackground()
4649
appearance.backgroundColor = .white

Projects/Presentation/Sources/ResultRecommendedRoutine/View/ResultRecommendedRoutineViewController.swift

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ final class ResultRecommendedRoutineViewController: BaseViewController<ResultRec
3737

3838
var confirmButtonLabel: String {
3939
switch self {
40-
case .onboarding: "등록하기"
41-
case .mypage: "확인"
40+
case .onboarding, .mypage: "등록하기"
4241
case .emotion: "맞춤 추천 루틴 보러 가기"
4342
}
4443
}
@@ -54,9 +53,9 @@ final class ResultRecommendedRoutineViewController: BaseViewController<ResultRec
5453

5554
var isRoutineButtonEnabled: Bool {
5655
switch self {
57-
case .onboarding, .emotion:
56+
case .onboarding, .mypage:
5857
true
59-
case .mypage:
58+
case .emotion:
6059
false
6160
}
6261
}
@@ -132,7 +131,7 @@ final class ResultRecommendedRoutineViewController: BaseViewController<ResultRec
132131
case .onboarding, .mypage:
133132
configureCustomNavigationBar(navigationBarStyle: .withProgressBar(step: OnboardingType.allCases.count + 1))
134133
case .emotion:
135-
configureCustomNavigationBar(navigationBarStyle: .withBackButton(title: ""))
134+
configureCustomNavigationBar(navigationBarStyle: .withTitle(title: ""))
136135
}
137136

138137
let mainLabelText = entryPoint.mainLabelText
@@ -216,9 +215,9 @@ final class ResultRecommendedRoutineViewController: BaseViewController<ResultRec
216215
case .onboarding:
217216
confirmButton = PrimaryButton(buttonState: .disabled, buttonTitle: entryPoint.confirmButtonLabel)
218217
case .mypage:
219-
confirmButton = PrimaryButton(buttonState: .default, buttonTitle: entryPoint.confirmButtonLabel)
220-
case .emotion:
221218
confirmButton = PrimaryButton(buttonState: .disabled, buttonTitle: entryPoint.confirmButtonLabel)
219+
case .emotion:
220+
confirmButton = PrimaryButton(buttonState: .default, buttonTitle: entryPoint.confirmButtonLabel)
222221
}
223222
}
224223

@@ -312,20 +311,27 @@ final class ResultRecommendedRoutineViewController: BaseViewController<ResultRec
312311
}
313312

314313
private func configureSkipButton() {
315-
skipButton.addAction(UIAction { [weak self] _ in
316-
guard let self else { return }
317-
switch entryPoint {
318-
case .emotion:
319-
if let navigationController = self.navigationController {
320-
let viewControllers = navigationController.viewControllers
321-
if viewControllers.count >= 3 {
322-
navigationController.popToViewController(viewControllers[viewControllers.count - 3], animated: false)
314+
skipButton.addAction(
315+
UIAction { [weak self] _ in
316+
guard let self else { return }
317+
switch entryPoint {
318+
case .emotion:
319+
if
320+
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
321+
let window = windowScene.windows.first(where: { $0.isKeyWindow }),
322+
let tabBarView = window.rootViewController as? TabBarView {
323+
self.navigationController?.popToRootViewController(animated: false)
324+
tabBarView.selectedIndex = 0
323325
}
326+
327+
case .onboarding:
328+
goToNextView()
329+
330+
case .mypage:
331+
break
324332
}
325-
case .onboarding, .mypage:
326-
goToNextView()
327-
}
328-
}, for: .touchUpInside)
333+
},
334+
for: .touchUpInside)
329335
}
330336

331337
private func goToNextView() {
@@ -337,6 +343,9 @@ final class ResultRecommendedRoutineViewController: BaseViewController<ResultRec
337343
}
338344

339345
case .mypage:
346+
viewModel.action(input: .fetchSelectedRoutineId)
347+
348+
case .emotion:
340349
if
341350
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
342351
let window = windowScene.windows.first(where: { $0.isKeyWindow }),
@@ -345,16 +354,16 @@ final class ResultRecommendedRoutineViewController: BaseViewController<ResultRec
345354
tabBarView.selectedIndex = 1
346355
}
347356
viewModel.action(input: .showRecommendedRoutineToastMessageView)
348-
349-
case .emotion:
350-
viewModel.action(input: .fetchSelectedRoutineId)
351357
}
352358
}
353359

354360
private func goToRoutineCreationView(routineId: Int) {
355361
guard let routineCreationViewModel = DIContainer.shared.resolve(type: RoutineCreationViewModel.self)
356362
else { fatalError("routineCreationViewModel 의존성이 등록되지 않았습니다.") }
357-
let routineCreationView = RoutineCreationViewController(viewModel: routineCreationViewModel, recommendRoutineId: routineId)
363+
let routineCreationView = RoutineCreationViewController(
364+
viewModel: routineCreationViewModel,
365+
recommendRoutineId: routineId,
366+
isFromMypage: true)
358367
routineCreationView.hidesBottomBarWhenPushed = true
359368
self.navigationController?.pushViewController(routineCreationView, animated: true)
360369
}

Projects/Presentation/Sources/ResultRecommendedRoutine/ViewModel/ResultRecommendedRoutineViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ final class ResultRecommendedRoutineViewModel: ViewModel {
128128
if selectedRoutines.contains(routine) {
129129
selectedRoutines.remove(routine)
130130
} else {
131-
if case .emotion = viewModelType {
131+
if case .mypage = viewModelType {
132132
selectedRoutines.removeAll()
133133
}
134134
selectedRoutines.insert(routine)

Projects/Presentation/Sources/RoutineCreation/View/RoutineCreationViewController.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ final class RoutineCreationViewController: BaseViewController<RoutineCreationVie
6767
private let registerButton = UIButton()
6868
private let navigationTitle: String
6969
private let registerButtonTitle: String
70+
private let isFromMypage: Bool
7071
private var cancellables = Set<AnyCancellable>()
7172

7273
init(
@@ -75,6 +76,7 @@ final class RoutineCreationViewController: BaseViewController<RoutineCreationVie
7576
) {
7677
navigationTitle = updateInfo?.routineId == nil ? "루틴 등록" : "루틴 수정"
7778
registerButtonTitle = updateInfo?.routineId == nil ? "등록하기" : "수정하기"
79+
self.isFromMypage = false
7880

7981
super.init(viewModel: viewModel)
8082

@@ -85,9 +87,14 @@ final class RoutineCreationViewController: BaseViewController<RoutineCreationVie
8587
}
8688
}
8789

88-
init(viewModel: RoutineCreationViewModel, recommendRoutineId: Int) {
90+
init(
91+
viewModel: RoutineCreationViewModel,
92+
recommendRoutineId: Int,
93+
isFromMypage: Bool = false
94+
) {
8995
navigationTitle = "루틴 등록"
9096
registerButtonTitle = "등록하기"
97+
self.isFromMypage = isFromMypage
9198

9299
super.init(viewModel: viewModel)
93100

@@ -136,8 +143,20 @@ final class RoutineCreationViewController: BaseViewController<RoutineCreationVie
136143
registerButton.titleLabel?.font = BitnagilFont.init(style: .body1, weight: .semiBold).font
137144
registerButton.addAction(
138145
UIAction { [weak self] _ in
139-
self?.viewModel.action(input: .registerRoutine)
140-
self?.navigationController?.popViewController(animated: true)
146+
guard let self else { return }
147+
self.viewModel.action(input: .registerRoutine)
148+
if self.isFromMypage {
149+
if
150+
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
151+
let window = windowScene.windows.first(where: { $0.isKeyWindow }),
152+
let tabBarView = window.rootViewController as? TabBarView {
153+
self.navigationController?.popToRootViewController(animated: false)
154+
tabBarView.selectedIndex = 1
155+
viewModel.action(input: .showRecommendedRoutineToastMessageView)
156+
}
157+
} else {
158+
self.navigationController?.popViewController(animated: true)
159+
}
141160
},
142161
for: .touchUpInside)
143162
bindCreationCardViews()

Projects/Presentation/Sources/RoutineCreation/ViewModel/RoutineCreationViewModel.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ final class RoutineCreationViewModel: ViewModel {
3333
case configureEndDate(date: Date)
3434
case configureExecution(type: ExecutionTime)
3535
case registerRoutine
36+
case showRecommendedRoutineToastMessageView
3637
}
3738

3839
struct Output {
@@ -108,6 +109,8 @@ final class RoutineCreationViewModel: ViewModel {
108109
periodStartSubject.send(date)
109110
case .configureEndDate(let date):
110111
periodEndSubject.send(date)
112+
case .showRecommendedRoutineToastMessageView:
113+
showRecommendedRoutineToastMessageView()
111114
}
112115

113116
updateIsRoutineValid()
@@ -279,4 +282,13 @@ final class RoutineCreationViewModel: ViewModel {
279282
}
280283
}
281284
}
285+
286+
private func showRecommendedRoutineToastMessageView() {
287+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
288+
NotificationCenter.default.post(
289+
name: .showRecommendedRoutineToast,
290+
object: nil,
291+
userInfo: nil)
292+
}
293+
}
282294
}

0 commit comments

Comments
 (0)