-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRootView.swift
More file actions
81 lines (78 loc) · 2.84 KB
/
Copy pathRootView.swift
File metadata and controls
81 lines (78 loc) · 2.84 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// 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?
@State private var selectedMainTab = MainTab.home
var body: some View {
ZStack {
Color(UIColor.systemGroupedBackground).ignoresSafeArea()
if let signIn = viewModel.state.signIn {
if signIn {
MainView(
container: container,
selectedTab: $selectedMainTab
)
} else {
LoginView(viewModel: LoginViewModel(
signInUseCase: container.resolve(SignInUseCase.self))
)
}
}
}
.preferredColorScheme(viewModel.state.theme.colorScheme)
.onAppear { viewModel.send(.onAppear) }
.onChange(of: viewModel.state.signIn) { _, value in
guard value == false else { return }
selectedMainTab = .home
}
.onOpenURL { url in
guard let mainTab = MainTab(widgetURL: url) else { return }
switch viewModel.state.signIn {
case .some(false):
selectedMainTab = .home
case .some(true), .none:
selectedMainTab = mainTab
}
}
.alert(viewModel.state.alertTitle, isPresented: Binding(
get: { viewModel.state.showAlert },
set: { viewModel.send(.setAlert($0)) }
)) {
Button(String(localized: "common_close"), role: .cancel) { }
} message: {
Text(viewModel.state.alertMessage)
}
.sheet(item: $selectedRoute) { route in
switch route {
case .todoDetail(let todoId):
NavigationStack {
TodoDetailView(viewModel: TodoDetailViewModel(
fetchTodoUseCase: container.resolve(FetchTodoByIdUseCase.self),
fetchReferenceItemsUseCase: container.resolve(FetchReferenceItemsUseCase.self),
upsertUseCase: container.resolve(UpsertTodoUseCase.self),
todoId: todoId,
showEditButton: false
))
.toolbar {
ToolbarLeadingButton {
selectedRoute = nil
}
}
}
.background(Color(.secondarySystemBackground))
.presentationDragIndicator(.visible)
}
}
.onReceive(PushNotificationRoute.shared.observe()) { route in
selectedRoute = route
PushNotificationRoute.shared.clear()
}
}
}