From 1baa02948b3b3ee3ab9cebfa39dd234611977b5a Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Wed, 4 Jan 2023 12:55:09 +0100 Subject: [PATCH] Separate tab and sidebar selection --- IceCubesApp/App/IceCubesApp.swift | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/IceCubesApp/App/IceCubesApp.swift b/IceCubesApp/App/IceCubesApp.swift index 355e6dea..1be9d803 100644 --- a/IceCubesApp/App/IceCubesApp.swift +++ b/IceCubesApp/App/IceCubesApp.swift @@ -17,7 +17,8 @@ struct IceCubesApp: App { @StateObject private var quickLook = QuickLook() @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 private var availableTabs: [Tab] { @@ -73,9 +74,7 @@ struct IceCubesApp: App { /// Stupid hack to trigger onChange binding in tab views. popToRootTab = .other DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) { - if let selectedTab { - popToRootTab = selectedTab - } + popToRootTab = selectedTab } } selectedTab = newTab @@ -94,7 +93,7 @@ struct IceCubesApp: App { private var splitView: some View { NavigationSplitView { - List(availableTabs, selection: $selectedTab) { tab in + List(availableTabs, selection: $selectSidebarItem) { tab in NavigationLink(value: tab) { tab.label } @@ -102,7 +101,7 @@ struct IceCubesApp: App { .scrollContentBackground(.hidden) .background(theme.secondaryBackgroundColor) } detail: { - selectedTab?.makeContentView(popToRootTab: $popToRootTab) + selectSidebarItem?.makeContentView(popToRootTab: $popToRootTab) } }