Skip to content

Commit e361e48

Browse files
committed
[Feat] AppFlow Coordinator 작성
1 parent 899217f commit e361e48

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//
2+
// AppFlowCoordinatorFeature.swift
3+
// Presentation
4+
//
5+
// Created by 박민서 on 2/4/25.
6+
// Copyright © 2025 yapp25thTeamTnT. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
import ComposableArchitecture
11+
12+
import Domain
13+
14+
@Reducer
15+
public struct AppFlowCoordinatorFeature {
16+
@ObservableState
17+
public struct State: Equatable {
18+
var userType: UserType?
19+
20+
// MARK: SubFeature state
21+
var trainerMainState: TrainerMainFlowFeature.State?
22+
var traineeMainState: TraineeMainFlowFeature.State?
23+
var onboardingState: OnboardingFlowFeature.State?
24+
25+
public init(
26+
userType: UserType? = nil,
27+
onboardingState: OnboardingFlowFeature.State? = .init(),
28+
trainerMainState: TrainerMainFlowFeature.State? = nil,
29+
traineeMainState: TraineeMainFlowFeature.State? = nil
30+
) {
31+
self.userType = userType
32+
self.onboardingState = onboardingState
33+
self.trainerMainState = trainerMainState
34+
self.traineeMainState = traineeMainState
35+
}
36+
}
37+
38+
public enum Action {
39+
/// 하위 코디네이터에서 일어나는 액션을 처리합니다
40+
case subFeature(SubFeatureAction)
41+
case onAppear
42+
43+
@CasePathable
44+
public enum SubFeatureAction: Sendable {
45+
/// 온보딩 플로우 코디네이터에서 발생하는 액션 처리
46+
case onboardingFlow(OnboardingFlowFeature.Action)
47+
/// 트레이너 메인탭 플로우 코디네이터에서 발생하는 액션 처리
48+
case trainerMainFlow(TrainerMainFlowFeature.Action)
49+
/// 트레이니 메인탭 플로우 코디네이터에서 발생하는 액션 처리
50+
case traineeMainFlow(TraineeMainFlowFeature.Action)
51+
}
52+
}
53+
54+
public init() {}
55+
56+
public var body: some Reducer<State, Action> {
57+
Reduce { state, action in
58+
switch action {
59+
case .subFeature(let internalAction):
60+
switch internalAction {
61+
case .onboardingFlow:
62+
return .none
63+
64+
case .trainerMainFlow:
65+
return .none
66+
67+
case .traineeMainFlow:
68+
return .none
69+
}
70+
71+
case .onAppear:
72+
return .none
73+
}
74+
}
75+
.ifLet(\.onboardingState, action: \.subFeature.onboardingFlow) { OnboardingFlowFeature() }
76+
.ifLet(\.trainerMainState, action: \.subFeature.trainerMainFlow) { TrainerMainFlowFeature() }
77+
.ifLet(\.traineeMainState, action: \.subFeature.traineeMainFlow) { TraineeMainFlowFeature() }
78+
}
79+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// AppFlowCoordinatorView.swift
3+
// Presentation
4+
//
5+
// Created by 박민서 on 2/4/25.
6+
// Copyright © 2025 yapp25thTeamTnT. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
import ComposableArchitecture
11+
12+
public struct AppFlowCoordinatorView: View {
13+
let store: StoreOf<AppFlowCoordinatorFeature>
14+
15+
public init(store: StoreOf<AppFlowCoordinatorFeature>) {
16+
self.store = store
17+
}
18+
19+
public var body: some View {
20+
Group {
21+
if let userType = store.userType {
22+
switch userType {
23+
case .trainee:
24+
if let store = store.scope(state: \.traineeMainState, action: \.subFeature.traineeMainFlow) {
25+
TraineeMainFlowView(store: store)
26+
}
27+
case .trainer:
28+
if let store = store.scope(state: \.trainerMainState, action: \.subFeature.trainerMainFlow) {
29+
TrainerMainFlowView(store: store)
30+
}
31+
}
32+
} else {
33+
if let store = store.scope(state: \.onboardingState, action: \.subFeature.onboardingFlow) {
34+
OnboardingFlowView(store: store)
35+
}
36+
}
37+
}
38+
.onAppear {
39+
store.send(.onAppear)
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)