diff --git a/IceCubesApp/App/Main/AppView.swift b/IceCubesApp/App/Main/AppView.swift index 83181c1c..6c88d880 100644 --- a/IceCubesApp/App/Main/AppView.swift +++ b/IceCubesApp/App/Main/AppView.swift @@ -18,13 +18,14 @@ struct AppView: View { @Environment(Theme.self) private var theme @Environment(StreamWatcher.self) private var watcher + @Environment(\.horizontalSizeClass) private var horizontalSizeClass + @Binding var selectedTab: Tab @Binding var sidebarRouterPath: RouterPath @State var popToRootTab: Tab = .other @State var iosTabs = iOSTabs.shared - @State var sideBarLoadedTabs: Set = Set() var body: some View { if UIDevice.current.userInterfaceIdiom == .pad || UIDevice.current.userInterfaceIdiom == .mac { @@ -90,34 +91,29 @@ struct AppView: View { tabs: availableTabs) { HStack(spacing: 0) { - ZStack { - if selectedTab == .profile { - ProfileTab(popToRootTab: $popToRootTab) - } + TabView(selection: $selectedTab) { ForEach(availableTabs) { tab in - if tab == selectedTab || sideBarLoadedTabs.contains(tab) { - tab - .makeContentView(selectedTab: $selectedTab, popToRootTab: $popToRootTab) - .opacity(tab == selectedTab ? 1 : 0) - .transition(.opacity) - .id("\(tab)\(appAccountsManager.currentAccount.id)") - .onAppear { - sideBarLoadedTabs.insert(tab) - } - } else { - EmptyView() - } + tab + .makeContentView(selectedTab: $selectedTab, popToRootTab: $popToRootTab) + .tabItem { + tab.label + } + .tag(tab) } } - if appAccountsManager.currentClient.isAuth, + .introspect(.tabView, on: .iOS(.v17)) { (tabview: UITabBarController) in + tabview.tabBar.isHidden = horizontalSizeClass == .regular + tabview.customizableViewControllers = [] + tabview.moreNavigationController.isNavigationBarHidden = true + } + if horizontalSizeClass == .regular, + appAccountsManager.currentClient.isAuth, userPreferences.showiPadSecondaryColumn { Divider().edgesIgnoringSafeArea(.all) notificationsSecondaryColumn } } - }.onChange(of: appAccountsManager.currentAccount.id) { - sideBarLoadedTabs.removeAll() } .environment(sidebarRouterPath) } @@ -130,4 +126,3 @@ struct AppView: View { .id(appAccountsManager.currentAccount.id) } } - diff --git a/IceCubesApp/App/SideBarView.swift b/IceCubesApp/App/SideBarView.swift index 76c155e9..1c3ff90b 100644 --- a/IceCubesApp/App/SideBarView.swift +++ b/IceCubesApp/App/SideBarView.swift @@ -4,10 +4,12 @@ import DesignSystem import Env import Models import SwiftUI +import SwiftUIIntrospect @MainActor struct SideBarView: View { @Environment(\.openWindow) private var openWindow + @Environment(\.horizontalSizeClass) private var horizontalSizeClass @Environment(AppAccountsManager.self) private var appAccounts @Environment(CurrentAccount.self) private var currentAccount @@ -131,29 +133,30 @@ struct SideBarView: View { var body: some View { @Bindable var routerPath = routerPath HStack(spacing: 0) { - ScrollView { - VStack(alignment: .center) { - if appAccounts.availableAccounts.isEmpty { - tabsView - } else { - ForEach(appAccounts.availableAccounts) { account in - makeAccountButton(account: account, - showBadge: account.id != appAccounts.currentAccount.id) - if account.id == appAccounts.currentAccount.id { - tabsView + if horizontalSizeClass == .regular { + ScrollView { + VStack(alignment: .center) { + if appAccounts.availableAccounts.isEmpty { + tabsView + } else { + ForEach(appAccounts.availableAccounts) { account in + makeAccountButton(account: account, + showBadge: account.id != appAccounts.currentAccount.id) + if account.id == appAccounts.currentAccount.id { + tabsView + } } } + postButton + .padding(.top, 12) + Spacer() } - postButton - .padding(.top, 12) - Spacer() } + .frame(width: .sidebarWidth) + .scrollContentBackground(.hidden) + .background(.thinMaterial) + Divider().edgesIgnoringSafeArea(.all) } - .frame(width: .sidebarWidth) - .scrollContentBackground(.hidden) - .background(.thinMaterial) - Divider() - .edgesIgnoringSafeArea(.top) content() } .background(.thinMaterial)