metatext/Shared/Views/RootView.swift
Justin Mazzocchi 54f8c82fcd
Refactoring
2020-08-08 22:37:04 -07:00

46 lines
1.3 KiB
Swift

// Copyright © 2020 Metabolist. All rights reserved.
import SwiftUI
#if os(macOS)
typealias MainNavigationViewModel = SidebarNavigationViewModel
#else
typealias MainNavigationViewModel = TabNavigationViewModel
#endif
struct RootView: View {
@StateObject var viewModel: RootViewModel
var body: some View {
if let mainNavigationViewModel = viewModel.mainNavigationViewModel {
Self.mainNavigation(mainNavigationViewModel: mainNavigationViewModel)
.id(UUID())
.environmentObject(viewModel)
.transition(.opacity)
} else {
AddIdentityView(viewModel: viewModel.addIdentityViewModel())
.environmentObject(viewModel)
.transition(.opacity)
}
}
}
private extension RootView {
@ViewBuilder
private static func mainNavigation(mainNavigationViewModel: MainNavigationViewModel) -> some View {
#if os(macOS)
SidebarNavigationView(viewModel: mainNavigationViewModel)
.frame(minWidth: 900, maxWidth: .infinity, minHeight: 500, maxHeight: .infinity)
#else
TabNavigationView(viewModel: mainNavigationViewModel)
#endif
}
}
#if DEBUG
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
RootView(viewModel: .development)
}
}
#endif