-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRootView.swift
More file actions
65 lines (62 loc) · 2.23 KB
/
RootView.swift
File metadata and controls
65 lines (62 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// RootView.swift
// SwiftUI_DevLog
//
// Created by opfic on 5/2/25.
//
import SwiftUI
struct RootView: View {
@Environment(\.diContainer) var container: DIContainer
@State var viewModel: RootViewModel
@State private var selectedRoute: AppRoute?
var body: some View {
ZStack {
Color(UIColor.systemGroupedBackground).ignoresSafeArea()
if let signIn = viewModel.state.signIn {
if signIn {
MainView(viewModel: MainViewModel(
observeUnreadPushCountUseCase: container.resolve(ObserveUnreadPushCountUseCase.self)
))
} else {
LoginView(viewModel: LoginViewModel(
signInUseCase: container.resolve(SignInUseCase.self))
)
}
}
}
.preferredColorScheme(viewModel.state.theme.colorScheme)
.onAppear { viewModel.send(.onAppear) }
.alert(viewModel.state.alertTitle, isPresented: Binding(
get: { viewModel.state.showAlert },
set: { viewModel.send(.setAlert($0)) }
)) {
Button("확인", role: .cancel) { }
} message: {
Text(viewModel.state.alertMessage)
}
.sheet(item: $selectedRoute) { route in
switch route {
case .todoDetail(let todoId):
NavigationStack {
TodoDetailView(viewModel: TodoDetailViewModel(
fetchUseCase: container.resolve(FetchTodoByIdUseCase.self),
upsertUseCase: container.resolve(UpsertTodoUseCase.self),
todoId: todoId,
showEditButton: false
))
.toolbar {
ToolbarLeadingButton {
selectedRoute = nil
}
}
}
.background(Color(.secondarySystemBackground))
.presentationDragIndicator(.visible)
}
}
.onReceive(PushNotificationRoute.shared.publisher) { route in
selectedRoute = route
PushNotificationRoute.shared.clear()
}
}
}