Fix TabView on Catalyst

This commit is contained in:
Thomas Ricouard 2024-09-06 08:58:24 +02:00
parent aa91d16cd9
commit 1af3cf4bf9

View file

@ -108,22 +108,14 @@ struct AppView: View {
tabs: availableTabs) tabs: availableTabs)
{ {
HStack(spacing: 0) { HStack(spacing: 0) {
TabView(selection: $selectedTab) { if #available(macCatalyst 18.0, *) {
ForEach(availableTabs) { tab in baseTabView
tab .tabViewStyle(.sidebarAdaptable)
.makeContentView(selectedTab: $selectedTab) .introspect(.tabView, on: .iOS(.v17, .v18)) { (tabview: UITabBarController) in
.toolbar(horizontalSizeClass == .regular ? .hidden : .visible, for: .tabBar) tabview.sidebar.isHidden = true
.tabItem {
tab.label
}
.tag(tab)
} }
} } else {
.id(availableTabs.count) /// Resets the TabView state when the number of tabs changes to avoid navigation bar issues and prevent crashes baseTabView
.introspect(.tabView, on: .iOS(.v17, .v18)) { (tabview: UITabBarController) in
tabview.tabBar.isHidden = horizontalSizeClass == .regular
tabview.customizableViewControllers = []
tabview.moreNavigationController.isNavigationBarHidden = true
} }
if horizontalSizeClass == .regular, if horizontalSizeClass == .regular,
appAccountsManager.currentClient.isAuth, appAccountsManager.currentClient.isAuth,
@ -137,6 +129,26 @@ struct AppView: View {
.environment(appRouterPath) .environment(appRouterPath)
} }
#endif #endif
private var baseTabView: some View {
TabView(selection: $selectedTab) {
ForEach(availableTabs) { tab in
tab
.makeContentView(selectedTab: $selectedTab)
.toolbar(horizontalSizeClass == .regular ? .hidden : .visible, for: .tabBar)
.tabItem {
tab.label
}
.tag(tab)
}
}
.id(availableTabs.count) /// Resets the TabView state when the number of tabs changes to avoid navigation bar issues and prevent crashes
.introspect(.tabView, on: .iOS(.v17, .v18)) { (tabview: UITabBarController) in
tabview.tabBar.isHidden = horizontalSizeClass == .regular
tabview.customizableViewControllers = []
tabview.moreNavigationController.isNavigationBarHidden = true
}
}
var notificationsSecondaryColumn: some View { var notificationsSecondaryColumn: some View {
NotificationsTab(selectedTab: .constant(.notifications) NotificationsTab(selectedTab: .constant(.notifications)