metatext/iOS/TabNavigation.swift

73 lines
2.8 KiB
Swift
Raw Normal View History

// Copyright © 2020 Metabolist. All rights reserved.
import SwiftUI
2020-07-31 21:40:57 +00:00
import KingfisherSwiftUI
import struct Kingfisher.DownsamplingImageProcessor
import struct Kingfisher.RoundCornerImageProcessor
struct TabNavigation: View {
2020-07-31 21:40:57 +00:00
let identity: Identity
@EnvironmentObject var sceneViewModel: SceneViewModel
var body: some View {
TabView(selection: $sceneViewModel.selectedTopLevelNavigation) {
ForEach(SceneViewModel.TopLevelNavigation.allCases) { topLevelNavigation in
NavigationView {
view(topLevelNavigation: topLevelNavigation)
}
2020-07-31 21:40:57 +00:00
.navigationViewStyle(StackNavigationViewStyle())
.tabItem {
Label(topLevelNavigation.title, systemImage: topLevelNavigation.systemImageName)
.accessibility(label: Text(topLevelNavigation.title))
}
.tag(topLevelNavigation)
}
}
2020-07-31 21:40:57 +00:00
.sheet(isPresented: $sceneViewModel.presentingSettings) {
SettingsView(viewModel: SettingsViewModel(identity: identity))
.environmentObject(sceneViewModel)
}
}
}
private extension TabNavigation {
func view(topLevelNavigation: SceneViewModel.TopLevelNavigation) -> some View {
Group {
switch topLevelNavigation {
case .timelines:
TimelineView()
2020-07-31 21:40:57 +00:00
.navigationBarTitle(identity.handle, displayMode: .inline)
.navigationBarItems(
leading: Button {
sceneViewModel.presentingSettings.toggle()
} label: {
KFImage(identity.account?.avatar
?? identity.instance?.thumbnail,
options: [
.processor(
DownsamplingImageProcessor(size: CGSize(width: 28, height: 28))
.append(another: RoundCornerImageProcessor(radius: .widthFraction(0.5)))
),
2020-08-02 00:15:45 +00:00
.scaleFactor(Screen.scale),
2020-07-31 21:40:57 +00:00
.cacheOriginalImage
])
.placeholder { Image(systemName: "gear") }
.renderingMode(.original)
})
default: Text(topLevelNavigation.title)
}
}
}
}
// MARK: Preview
2020-07-31 21:40:57 +00:00
#if DEBUG
struct TabNavigation_Previews: PreviewProvider {
static var previews: some View {
2020-07-31 21:40:57 +00:00
TabNavigation(identity: .development)
.environmentObject(SceneViewModel.development)
}
}
2020-07-31 21:40:57 +00:00
#endif