2020-07-30 01:50:30 +02:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import SwiftUI
|
2020-08-03 07:54:47 +02:00
|
|
|
import KingfisherSwiftUI
|
|
|
|
import struct Kingfisher.DownsamplingImageProcessor
|
|
|
|
import struct Kingfisher.RoundCornerImageProcessor
|
2020-07-30 01:50:30 +02:00
|
|
|
|
|
|
|
struct SidebarNavigation: View {
|
2020-08-04 02:48:22 +02:00
|
|
|
@StateObject var viewModel: MainNavigationViewModel
|
2020-08-04 22:26:09 +02:00
|
|
|
@EnvironmentObject var rootViewModel: RootViewModel
|
|
|
|
@Environment(\.displayScale) var displayScale: CGFloat
|
2020-07-30 01:50:30 +02:00
|
|
|
|
|
|
|
var sidebar: some View {
|
2020-08-03 17:20:51 +02:00
|
|
|
List(selection: $viewModel.selectedTab) {
|
|
|
|
ForEach(MainNavigationViewModel.Tab.allCases) { tab in
|
|
|
|
NavigationLink(destination: view(topLevelNavigation: tab)) {
|
|
|
|
Label(tab.title, systemImage: tab.systemImageName)
|
2020-07-30 01:50:30 +02:00
|
|
|
}
|
2020-08-03 17:20:51 +02:00
|
|
|
.accessibility(label: Text(tab.title))
|
|
|
|
.tag(tab)
|
2020-07-30 01:50:30 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-04 22:26:09 +02:00
|
|
|
.overlay(Pocket()
|
|
|
|
.environmentObject(viewModel)
|
|
|
|
.environmentObject(rootViewModel),
|
|
|
|
alignment: .bottom)
|
2020-07-30 01:50:30 +02:00
|
|
|
.listStyle(SidebarListStyle())
|
2020-08-04 02:48:22 +02:00
|
|
|
.onAppear(perform: viewModel.refreshIdentity)
|
|
|
|
.onReceive(NotificationCenter.default
|
|
|
|
.publisher(for: NSWindow.didBecomeKeyNotification)
|
|
|
|
.dropFirst()
|
|
|
|
.map { _ in () },
|
|
|
|
perform: viewModel.refreshIdentity)
|
2020-07-30 01:50:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
NavigationView {
|
|
|
|
sidebar
|
|
|
|
.frame(minWidth: 100, idealWidth: 150, maxWidth: 200, maxHeight: .infinity)
|
|
|
|
Text("Content")
|
|
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private extension SidebarNavigation {
|
2020-08-03 17:20:51 +02:00
|
|
|
func view(topLevelNavigation: MainNavigationViewModel.Tab) -> some View {
|
2020-07-30 01:50:30 +02:00
|
|
|
Group {
|
|
|
|
switch topLevelNavigation {
|
|
|
|
case .timelines:
|
|
|
|
TimelineView()
|
|
|
|
default: Text(topLevelNavigation.title)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-03 07:54:47 +02:00
|
|
|
|
|
|
|
struct Pocket: View {
|
2020-08-03 17:20:51 +02:00
|
|
|
@EnvironmentObject var viewModel: MainNavigationViewModel
|
2020-08-04 22:26:09 +02:00
|
|
|
@EnvironmentObject var rootViewModel: RootViewModel
|
2020-08-03 07:54:47 +02:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
|
|
Divider()
|
2020-08-03 17:20:51 +02:00
|
|
|
Button(action: { viewModel.presentingSettings.toggle() }) {
|
2020-08-04 22:26:09 +02:00
|
|
|
KFImage(viewModel.identity.image,
|
2020-08-03 07:54:47 +02:00
|
|
|
options: [
|
|
|
|
.processor(
|
|
|
|
DownsamplingImageProcessor(size: CGSize(width: 50, height: 50))
|
|
|
|
.append(another: RoundCornerImageProcessor(radius: .widthFraction(0.5)))
|
|
|
|
),
|
2020-08-04 22:26:09 +02:00
|
|
|
.scaleFactor(displayScale),
|
2020-08-03 07:54:47 +02:00
|
|
|
.cacheOriginalImage
|
|
|
|
])
|
|
|
|
.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-03 17:20:51 +02:00
|
|
|
.sheet(isPresented: $viewModel.presentingSettings) {
|
|
|
|
SettingsView(viewModel: viewModel.settingsViewModel())
|
|
|
|
.environmentObject(viewModel)
|
2020-08-04 22:26:09 +02:00
|
|
|
.environmentObject(rootViewModel)
|
2020-08-03 07:54:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-30 01:50:30 +02:00
|
|
|
}
|
|
|
|
|
2020-08-03 00:23:01 +02:00
|
|
|
#if DEBUG
|
2020-07-30 01:50:30 +02:00
|
|
|
struct SidebarNavigation_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2020-08-04 02:48:22 +02:00
|
|
|
SidebarNavigation(viewModel: .development)
|
2020-08-04 22:26:09 +02:00
|
|
|
.environmentObject(RootViewModel.development)
|
2020-07-30 01:50:30 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-03 00:23:01 +02:00
|
|
|
#endif
|