70 lines
2.5 KiB
Swift
70 lines
2.5 KiB
Swift
//
|
|
// DrawerView.swift - The main screen of the app with
|
|
// a tab view at the bottom.
|
|
//
|
|
// Created by Marcus Handte on 28.05.22.
|
|
//
|
|
import SwiftUI
|
|
|
|
/// The drawer view with tabs at the bottom.
|
|
struct DrawerView: View {
|
|
|
|
|
|
@ObservedObject var state = AppState.shared
|
|
@State var searchState = SearchState()
|
|
@State var stationsState = StationsState()
|
|
|
|
|
|
func buildDevicesTab() -> HideableTabItem {
|
|
if state.credentials != nil {
|
|
if state.credentialFailure {
|
|
return HideableTabItem(id: 2, text: "navigation_devices", image: Image("icon_devices")) {
|
|
AnyView(LoginView(mode: .changePassword))
|
|
}
|
|
} else {
|
|
return HideableTabItem(id: 2, text: "navigation_devices", image: Image("icon_devices")) {
|
|
AnyView(DevicesView())
|
|
}
|
|
}
|
|
} else {
|
|
return HideableTabItem(id: 2, text: "navigation_account", image: Image(systemName: "person.crop.circle")) {
|
|
AnyView(LoginView(mode: .linkAccount))
|
|
}
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
GeometryReader { proxy in
|
|
VStack(spacing: 0) {
|
|
HideableTabView("main", proxy.safeAreaInsets) {
|
|
[
|
|
HideableTabItem(id: 0, text: "navigation_favorites", image: Image(systemName: "heart")) {
|
|
AnyView(FavoritesView())
|
|
},
|
|
HideableTabItem(id: 1, text: "navigation_stations", image: Image("icon_station")) {
|
|
AnyView(StationsView(state: stationsState))
|
|
},
|
|
buildDevicesTab(),
|
|
HideableTabItem(id: 4, text: "navigation_settings", image: Image(systemName: "gear")) {
|
|
AnyView(SettingsView())
|
|
},
|
|
HideableTabItem(id: 5, text: "navigation_search", image: Image(systemName: "magnifyingglass")) {
|
|
AnyView(SearchView(state: searchState))
|
|
}
|
|
]
|
|
}
|
|
Color("PrimaryColor")
|
|
.frame(height: proxy.safeAreaInsets.bottom)
|
|
.frame(maxWidth: .infinity)
|
|
}.ignoresSafeArea(.all, edges: [.bottom, .trailing, .leading])
|
|
}
|
|
}
|
|
}
|
|
|
|
struct DrawerView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
DrawerView()
|
|
}
|
|
}
|
|
|