2020-08-03 15:20:51 +00:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import SwiftUI
|
2022-11-13 20:03:19 +00:00
|
|
|
import UIKit
|
2020-09-01 07:33:49 +00:00
|
|
|
import ViewModels
|
2020-08-03 15:20:51 +00:00
|
|
|
|
|
|
|
struct RootView: View {
|
|
|
|
@StateObject var viewModel: RootViewModel
|
|
|
|
|
|
|
|
var body: some View {
|
2020-09-09 22:48:56 +00:00
|
|
|
if let navigationViewModel = viewModel.navigationViewModel {
|
2021-01-20 23:33:53 +00:00
|
|
|
MainNavigationView { navigationViewModel }
|
2021-01-26 00:06:35 +00:00
|
|
|
.id(navigationViewModel.identityContext.identity.id)
|
2020-08-07 01:41:59 +00:00
|
|
|
.environmentObject(viewModel)
|
|
|
|
.transition(.opacity)
|
2021-01-20 23:33:53 +00:00
|
|
|
.edgesIgnoringSafeArea(.all)
|
2022-11-13 20:03:19 +00:00
|
|
|
.onReceive(navigationViewModel.identityContext.$appPreferences.map(\.colorScheme),
|
|
|
|
perform: setColorScheme)
|
2020-08-07 01:41:59 +00:00
|
|
|
} else {
|
2020-09-11 09:55:06 +00:00
|
|
|
NavigationView {
|
2021-01-27 20:31:32 +00:00
|
|
|
AddIdentityView(
|
|
|
|
viewModelClosure: { viewModel.addIdentityViewModel() },
|
|
|
|
displayWelcome: true)
|
2022-11-13 20:03:19 +00:00
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
|
.navigationBarHidden(true)
|
2020-09-11 09:55:06 +00:00
|
|
|
}
|
|
|
|
.environmentObject(viewModel)
|
2020-09-12 07:36:59 +00:00
|
|
|
.navigationViewStyle(StackNavigationViewStyle())
|
2020-09-11 09:55:06 +00:00
|
|
|
.transition(.opacity)
|
2020-08-03 15:20:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-13 20:03:19 +00:00
|
|
|
private extension RootView {
|
|
|
|
func setColorScheme(_ colorScheme: AppPreferences.ColorScheme) {
|
|
|
|
for scene in UIApplication.shared.connectedScenes.compactMap({ $0 as? UIWindowScene }) {
|
|
|
|
for window in scene.windows {
|
|
|
|
window.overrideUserInterfaceStyle = colorScheme.uiKit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension AppPreferences.ColorScheme {
|
|
|
|
var uiKit: UIUserInterfaceStyle {
|
|
|
|
switch self {
|
|
|
|
case .system:
|
|
|
|
return .unspecified
|
|
|
|
case .light:
|
|
|
|
return .light
|
|
|
|
case .dark:
|
|
|
|
return .dark
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 15:20:51 +00:00
|
|
|
#if DEBUG
|
2020-09-08 02:12:38 +00:00
|
|
|
import Combine
|
2020-09-01 07:33:49 +00:00
|
|
|
import PreviewViewModels
|
|
|
|
|
2020-08-03 15:20:51 +00:00
|
|
|
struct ContentView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2020-09-08 02:12:38 +00:00
|
|
|
RootView(viewModel: .preview)
|
2020-08-03 15:20:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|