Files
Sybil-2/ios/Packages/Sybil/Sources/Sybil/SplitView.swift

66 lines
2.2 KiB
Swift

import SwiftUI
public struct SplitView: View {
@State private var viewModel = SybilViewModel()
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
@Environment(\.scenePhase) private var scenePhase
@State private var shouldRefreshOnForeground = false
@MainActor public init() {
SybilFontRegistry.registerIfNeeded()
SybilTheme.applySystemAppearance()
}
public var body: some View {
ZStack {
SybilTheme.backgroundGradient
.ignoresSafeArea()
if viewModel.isCheckingSession {
ProgressView("Checking session…")
.tint(SybilTheme.primary)
.foregroundStyle(SybilTheme.textMuted)
} else if !viewModel.isAuthenticated {
SybilConnectionView(viewModel: viewModel)
.padding()
} else if horizontalSizeClass == .compact {
SybilPhoneShellView(viewModel: viewModel)
} else {
NavigationSplitView {
SybilSidebarView(viewModel: viewModel)
} detail: {
SybilWorkspaceView(viewModel: viewModel)
}
.navigationSplitViewStyle(.balanced)
.tint(SybilTheme.primary)
}
}
.font(.sybil(.body))
.preferredColorScheme(.dark)
.task {
await viewModel.bootstrap()
}
.onChange(of: scenePhase) { _, nextPhase in
switch nextPhase {
case .background:
shouldRefreshOnForeground = true
case .active:
guard shouldRefreshOnForeground, horizontalSizeClass != .compact else {
return
}
shouldRefreshOnForeground = false
Task {
await viewModel.refreshVisibleContent(
refreshCollections: true,
refreshSelection: viewModel.hasRefreshableSelection
)
}
case .inactive:
break
@unknown default:
break
}
}
}
}