metatext/macOS/Views/SidebarNavigationView.swift

83 lines
2.7 KiB
Swift
Raw Normal View History

// Copyright © 2020 Metabolist. All rights reserved.
import SwiftUI
2020-08-03 05:54:47 +00:00
import KingfisherSwiftUI
2020-08-08 06:01:45 +00:00
struct SidebarNavigationView: View {
@StateObject var viewModel: SidebarNavigationViewModel
2020-08-04 20:26:09 +00:00
@EnvironmentObject var rootViewModel: RootViewModel
var sidebar: some View {
2020-08-03 15:20:51 +00:00
List(selection: $viewModel.selectedTab) {
2020-08-08 06:01:45 +00:00
ForEach(SidebarNavigationViewModel.Tab.allCases) { tab in
2020-08-03 15:20:51 +00:00
NavigationLink(destination: view(topLevelNavigation: tab)) {
Label(tab.title, systemImage: tab.systemImageName)
}
2020-08-03 15:20:51 +00:00
.accessibility(label: Text(tab.title))
.tag(tab)
}
}
2020-08-04 20:26:09 +00:00
.overlay(Pocket()
.environmentObject(viewModel)
.environmentObject(rootViewModel),
alignment: .bottom)
.listStyle(SidebarListStyle())
}
var body: some View {
NavigationView {
sidebar
.frame(minWidth: 100, idealWidth: 150, maxWidth: 200, maxHeight: .infinity)
Text("Content")
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
}
2020-08-08 06:01:45 +00:00
private extension SidebarNavigationView {
func view(topLevelNavigation: SidebarNavigationViewModel.Tab) -> some View {
Group {
switch topLevelNavigation {
case .timelines:
TimelineView()
default: Text(topLevelNavigation.title)
}
}
}
2020-08-03 05:54:47 +00:00
struct Pocket: View {
2020-08-08 06:01:45 +00:00
@EnvironmentObject var viewModel: SidebarNavigationViewModel
2020-08-04 20:26:09 +00:00
@EnvironmentObject var rootViewModel: RootViewModel
2020-08-07 10:14:14 +00:00
@Environment(\.displayScale) var displayScale: CGFloat
2020-08-03 05:54:47 +00:00
var body: some View {
VStack(alignment: .leading, spacing: 0) {
Divider()
2020-08-08 06:01:45 +00:00
Button(action: { /*viewModel.presentingSecondaryNavigation.toggle()*/ }) {
2020-08-04 20:26:09 +00:00
KFImage(viewModel.identity.image,
2020-08-07 10:14:14 +00:00
options: .downsampled(dimension: 28, scaleFactor: displayScale))
2020-08-03 05:54:47 +00:00
.placeholder { Image(systemName: "gear") }
.renderingMode(.original)
.resizable()
.padding(6)
.contentShape(Rectangle())
}
.frame(width: 50, height: 50)
.accessibility(label: Text("Rewards"))
.padding(.vertical, 8)
.padding(.horizontal, 16)
.buttonStyle(PlainButtonStyle())
}
}
}
}
2020-08-02 22:23:01 +00:00
#if DEBUG
struct SidebarNavigation_Previews: PreviewProvider {
static var previews: some View {
2020-08-08 06:01:45 +00:00
SidebarNavigationView(viewModel: .development)
2020-08-04 20:26:09 +00:00
.environmentObject(RootViewModel.development)
}
}
2020-08-02 22:23:01 +00:00
#endif