Separate tab and sidebar selection

This commit is contained in:
Thomas Ricouard 2023-01-04 12:55:09 +01:00
parent 73f3fef738
commit 1baa02948b

View file

@ -17,7 +17,8 @@ struct IceCubesApp: App {
@StateObject private var quickLook = QuickLook() @StateObject private var quickLook = QuickLook()
@StateObject private var theme = Theme() @StateObject private var theme = Theme()
@State private var selectedTab: Tab? = .timeline @State private var selectedTab: Tab = .timeline
@State private var selectSidebarItem: Tab? = .timeline
@State private var popToRootTab: Tab = .other @State private var popToRootTab: Tab = .other
private var availableTabs: [Tab] { private var availableTabs: [Tab] {
@ -73,11 +74,9 @@ struct IceCubesApp: App {
/// Stupid hack to trigger onChange binding in tab views. /// Stupid hack to trigger onChange binding in tab views.
popToRootTab = .other popToRootTab = .other
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) { DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
if let selectedTab {
popToRootTab = selectedTab popToRootTab = selectedTab
} }
} }
}
selectedTab = newTab selectedTab = newTab
})) { })) {
ForEach(availableTabs) { tab in ForEach(availableTabs) { tab in
@ -94,7 +93,7 @@ struct IceCubesApp: App {
private var splitView: some View { private var splitView: some View {
NavigationSplitView { NavigationSplitView {
List(availableTabs, selection: $selectedTab) { tab in List(availableTabs, selection: $selectSidebarItem) { tab in
NavigationLink(value: tab) { NavigationLink(value: tab) {
tab.label tab.label
} }
@ -102,7 +101,7 @@ struct IceCubesApp: App {
.scrollContentBackground(.hidden) .scrollContentBackground(.hidden)
.background(theme.secondaryBackgroundColor) .background(theme.secondaryBackgroundColor)
} detail: { } detail: {
selectedTab?.makeContentView(popToRootTab: $popToRootTab) selectSidebarItem?.makeContentView(popToRootTab: $popToRootTab)
} }
} }