Sidebar is now backed by TabView + restore slideover tabbar transition

This commit is contained in:
Thomas Ricouard 2024-01-04 16:21:15 +01:00
parent fd190378c6
commit 469b99f3c9
2 changed files with 37 additions and 39 deletions

View File

@ -18,13 +18,14 @@ struct AppView: View {
@Environment(Theme.self) private var theme @Environment(Theme.self) private var theme
@Environment(StreamWatcher.self) private var watcher @Environment(StreamWatcher.self) private var watcher
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
@Binding var selectedTab: Tab @Binding var selectedTab: Tab
@Binding var sidebarRouterPath: RouterPath @Binding var sidebarRouterPath: RouterPath
@State var popToRootTab: Tab = .other @State var popToRootTab: Tab = .other
@State var iosTabs = iOSTabs.shared @State var iosTabs = iOSTabs.shared
@State var sideBarLoadedTabs: Set<Tab> = Set()
var body: some View { var body: some View {
if UIDevice.current.userInterfaceIdiom == .pad || UIDevice.current.userInterfaceIdiom == .mac { if UIDevice.current.userInterfaceIdiom == .pad || UIDevice.current.userInterfaceIdiom == .mac {
@ -90,34 +91,29 @@ struct AppView: View {
tabs: availableTabs) tabs: availableTabs)
{ {
HStack(spacing: 0) { HStack(spacing: 0) {
ZStack { TabView(selection: $selectedTab) {
if selectedTab == .profile {
ProfileTab(popToRootTab: $popToRootTab)
}
ForEach(availableTabs) { tab in ForEach(availableTabs) { tab in
if tab == selectedTab || sideBarLoadedTabs.contains(tab) { tab
tab .makeContentView(selectedTab: $selectedTab, popToRootTab: $popToRootTab)
.makeContentView(selectedTab: $selectedTab, popToRootTab: $popToRootTab) .tabItem {
.opacity(tab == selectedTab ? 1 : 0) tab.label
.transition(.opacity) }
.id("\(tab)\(appAccountsManager.currentAccount.id)") .tag(tab)
.onAppear {
sideBarLoadedTabs.insert(tab)
}
} else {
EmptyView()
}
} }
} }
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 userPreferences.showiPadSecondaryColumn
{ {
Divider().edgesIgnoringSafeArea(.all) Divider().edgesIgnoringSafeArea(.all)
notificationsSecondaryColumn notificationsSecondaryColumn
} }
} }
}.onChange(of: appAccountsManager.currentAccount.id) {
sideBarLoadedTabs.removeAll()
} }
.environment(sidebarRouterPath) .environment(sidebarRouterPath)
} }
@ -130,4 +126,3 @@ struct AppView: View {
.id(appAccountsManager.currentAccount.id) .id(appAccountsManager.currentAccount.id)
} }
} }

View File

@ -4,10 +4,12 @@ import DesignSystem
import Env import Env
import Models import Models
import SwiftUI import SwiftUI
import SwiftUIIntrospect
@MainActor @MainActor
struct SideBarView<Content: View>: View { struct SideBarView<Content: View>: View {
@Environment(\.openWindow) private var openWindow @Environment(\.openWindow) private var openWindow
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
@Environment(AppAccountsManager.self) private var appAccounts @Environment(AppAccountsManager.self) private var appAccounts
@Environment(CurrentAccount.self) private var currentAccount @Environment(CurrentAccount.self) private var currentAccount
@ -131,29 +133,30 @@ struct SideBarView<Content: View>: View {
var body: some View { var body: some View {
@Bindable var routerPath = routerPath @Bindable var routerPath = routerPath
HStack(spacing: 0) { HStack(spacing: 0) {
ScrollView { if horizontalSizeClass == .regular {
VStack(alignment: .center) { ScrollView {
if appAccounts.availableAccounts.isEmpty { VStack(alignment: .center) {
tabsView if appAccounts.availableAccounts.isEmpty {
} else { tabsView
ForEach(appAccounts.availableAccounts) { account in } else {
makeAccountButton(account: account, ForEach(appAccounts.availableAccounts) { account in
showBadge: account.id != appAccounts.currentAccount.id) makeAccountButton(account: account,
if account.id == appAccounts.currentAccount.id { showBadge: account.id != appAccounts.currentAccount.id)
tabsView 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() content()
} }
.background(.thinMaterial) .background(.thinMaterial)