metatext/Shared/Views/RootView.swift

47 lines
1.3 KiB
Swift
Raw Normal View History

2020-08-03 15:20:51 +00:00
// Copyright © 2020 Metabolist. All rights reserved.
import SwiftUI
2020-08-08 06:01:45 +00:00
#if os(macOS)
typealias MainNavigationViewModel = SidebarNavigationViewModel
#else
typealias MainNavigationViewModel = TabNavigationViewModel
#endif
2020-08-03 15:20:51 +00:00
struct RootView: View {
@StateObject var viewModel: RootViewModel
var body: some View {
2020-08-09 05:37:04 +00:00
if let mainNavigationViewModel = viewModel.mainNavigationViewModel {
2020-08-07 01:41:59 +00:00
Self.mainNavigation(mainNavigationViewModel: mainNavigationViewModel)
2020-08-09 05:37:04 +00:00
.id(UUID())
2020-08-07 01:41:59 +00:00
.environmentObject(viewModel)
.transition(.opacity)
} else {
AddIdentityView(viewModel: viewModel.addIdentityViewModel())
.environmentObject(viewModel)
.transition(.opacity)
2020-08-03 15:20:51 +00:00
}
}
}
private extension RootView {
2020-08-04 20:26:09 +00:00
@ViewBuilder
private static func mainNavigation(mainNavigationViewModel: MainNavigationViewModel) -> some View {
2020-08-03 15:20:51 +00:00
#if os(macOS)
2020-08-08 06:01:45 +00:00
SidebarNavigationView(viewModel: mainNavigationViewModel)
2020-08-03 15:20:51 +00:00
.frame(minWidth: 900, maxWidth: .infinity, minHeight: 500, maxHeight: .infinity)
#else
2020-08-08 06:01:45 +00:00
TabNavigationView(viewModel: mainNavigationViewModel)
2020-08-03 15:20:51 +00:00
#endif
}
}
#if DEBUG
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
RootView(viewModel: .development)
}
}
#endif