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)
.opacity(tab == selectedTab ? 1 : 0) .tabItem {
.transition(.opacity) tab.label
.id("\(tab)\(appAccountsManager.currentAccount.id)")
.onAppear {
sideBarLoadedTabs.insert(tab)
} }
} else { .tag(tab)
EmptyView()
} }
} }
.introspect(.tabView, on: .iOS(.v17)) { (tabview: UITabBarController) in
tabview.tabBar.isHidden = horizontalSizeClass == .regular
tabview.customizableViewControllers = []
tabview.moreNavigationController.isNavigationBarHidden = true
} }
if appAccountsManager.currentClient.isAuth, 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,6 +133,7 @@ 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) {
if horizontalSizeClass == .regular {
ScrollView { ScrollView {
VStack(alignment: .center) { VStack(alignment: .center) {
if appAccounts.availableAccounts.isEmpty { if appAccounts.availableAccounts.isEmpty {
@ -152,8 +155,8 @@ struct SideBarView<Content: View>: View {
.frame(width: .sidebarWidth) .frame(width: .sidebarWidth)
.scrollContentBackground(.hidden) .scrollContentBackground(.hidden)
.background(.thinMaterial) .background(.thinMaterial)
Divider() Divider().edgesIgnoringSafeArea(.all)
.edgesIgnoringSafeArea(.top) }
content() content()
} }
.background(.thinMaterial) .background(.thinMaterial)