-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
HMH_Tuist_iOS/Projects/App/Sources/Coordinator/AppCoordinator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// AppCoordinator.swift | ||
// Coordinator | ||
// | ||
// Created by 이지희 on 11/7/24. | ||
// Copyright © 2024 HMH-iOS. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
import Core | ||
import LoginFeature | ||
import OnboardingFeature | ||
import MyPageFeature | ||
|
||
|
||
final class AppCoordinator: ObservableObject, CoordinatorType { | ||
@Published var currentView: AnyView = AnyView(SplashView(coordinator: AppCoordinator(navigationPath: .init()))) | ||
@Published var appState: AppState = .login | ||
|
||
var navigationPath: NavigationPath | ||
var parentCoordinator: (any CoordinatorType)? | ||
|
||
init(navigationPath: NavigationPath) { | ||
self.navigationPath = navigationPath | ||
} | ||
|
||
func start() -> AnyView { | ||
// 초기 상태에 따라 적절한 뷰를 설정합니다. | ||
showSplashScreen() | ||
return currentView | ||
} | ||
|
||
private func showSplashScreen() { | ||
currentView = AnyView(SplashView(coordinator: self)) // 코디네이터 주입 | ||
|
||
/// 스플래쉬에서 토큰 검사 과정 (혹은 홈뷰 API 호출) 로 로그인 필요 여부 확인 | ||
} | ||
|
||
func transitionToNextView() { | ||
switch UserManager.shared.appState { | ||
case .onboarding: | ||
currentView = AnyView(OnboardingContentView()) | ||
case .onboardingComplete: | ||
currentView = AnyView(OnboardingCompleteView()) | ||
case .servicePrepare: | ||
currentView = AnyView(ServicePrepareView()) | ||
case .home: | ||
startTabBar() | ||
case .login: | ||
startLogin() | ||
} | ||
} | ||
|
||
func startLogin() { | ||
let authCoordinator = AuthCoordinator(parentCoordinator: self, navigationPath: navigationPath) | ||
currentView = authCoordinator.start() | ||
} | ||
|
||
func startTabBar() { | ||
let tabBarCoordinator = TabBarCoordinator(parentCoordinator: self, navigationPath: self.navigationPath) | ||
currentView = tabBarCoordinator.start() | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
HMH_Tuist_iOS/Projects/App/Sources/Coordinator/BaseCoordinator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// BaseCoordinator.swift | ||
// Coordinator | ||
// | ||
// Created by 이지희 on 11/7/24. | ||
// Copyright © 2024 HMH-iOS. All rights reserved. | ||
// | ||
import SwiftUI | ||
import Combine | ||
|
||
import Core | ||
|
||
// MARK: - BaseCoordinator 프로토콜 | ||
public protocol CoordinatorType: AnyObject { | ||
|
||
var parentCoordinator: (any CoordinatorType)? { get set } | ||
var navigationPath: NavigationPath { get set } | ||
|
||
func start() -> AnyView | ||
|
||
func push(to view: any Hashable) | ||
func pop() | ||
func popToRoot() | ||
} | ||
|
||
extension CoordinatorType { | ||
func push(to view: any Hashable) { | ||
navigationPath.append(view) | ||
} | ||
|
||
func pop() { | ||
navigationPath.removeLast() | ||
} | ||
|
||
func popToRoot() { | ||
navigationPath.removeLast(navigationPath.count) | ||
} | ||
} |