mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-06-05 21:38:50 +00:00
Better TabView support
This commit is contained in:
parent
f377e5970e
commit
30c5c36aa1
1 changed files with 29 additions and 72 deletions
|
@ -53,53 +53,28 @@ struct AppView: View {
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
var tabBarView: some View {
|
var tabBarView: some View {
|
||||||
if #available(iOS 18.0, *) {
|
TabView(selection: .init(get: {
|
||||||
TabView(selection: .init(get: {
|
selectedTab
|
||||||
selectedTab
|
}, set: { newTab in
|
||||||
}, set: { newTab in
|
updateTab(with: newTab)
|
||||||
updateTab(with: newTab)
|
})) {
|
||||||
})) {
|
ForEach(availableTabs) { tab in
|
||||||
ForEach(availableTabs) { tab in
|
Tab(value: tab) {
|
||||||
Tab(value: tab) {
|
|
||||||
tab.makeContentView(selectedTab: $selectedTab)
|
|
||||||
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.30), for: .tabBar)
|
|
||||||
} label: {
|
|
||||||
if userPreferences.showiPhoneTabLabel {
|
|
||||||
tab.label
|
|
||||||
.environment(\.symbolVariants, tab == selectedTab ? .fill : .none)
|
|
||||||
} else {
|
|
||||||
Image(systemName: tab.iconName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.badge(badgeFor(tab: tab))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.id(appAccountsManager.currentClient.id)
|
|
||||||
.withSheetDestinations(sheetDestinations: $appRouterPath.presentedSheet)
|
|
||||||
} else {
|
|
||||||
TabView(selection: .init(get: {
|
|
||||||
selectedTab
|
|
||||||
}, set: { newTab in
|
|
||||||
updateTab(with: newTab)
|
|
||||||
})) {
|
|
||||||
ForEach(availableTabs) { tab in
|
|
||||||
tab.makeContentView(selectedTab: $selectedTab)
|
tab.makeContentView(selectedTab: $selectedTab)
|
||||||
.tabItem {
|
|
||||||
if userPreferences.showiPhoneTabLabel {
|
|
||||||
tab.label
|
|
||||||
.environment(\.symbolVariants, tab == selectedTab ? .fill : .none)
|
|
||||||
} else {
|
|
||||||
Image(systemName: tab.iconName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.tag(tab)
|
|
||||||
.badge(badgeFor(tab: tab))
|
|
||||||
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.30), for: .tabBar)
|
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.30), for: .tabBar)
|
||||||
|
} label: {
|
||||||
|
if userPreferences.showiPhoneTabLabel {
|
||||||
|
tab.label
|
||||||
|
.environment(\.symbolVariants, tab == selectedTab ? .fill : .none)
|
||||||
|
} else {
|
||||||
|
Image(systemName: tab.iconName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
.badge(badgeFor(tab: tab))
|
||||||
}
|
}
|
||||||
.id(appAccountsManager.currentClient.id)
|
|
||||||
.withSheetDestinations(sheetDestinations: $appRouterPath.presentedSheet)
|
|
||||||
}
|
}
|
||||||
|
.id(appAccountsManager.currentClient.id)
|
||||||
|
.withSheetDestinations(sheetDestinations: $appRouterPath.presentedSheet)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateTab(with newTab: AppTab) {
|
private func updateTab(with newTab: AppTab) {
|
||||||
|
@ -133,40 +108,22 @@ struct AppView: View {
|
||||||
tabs: availableTabs)
|
tabs: availableTabs)
|
||||||
{
|
{
|
||||||
HStack(spacing: 0) {
|
HStack(spacing: 0) {
|
||||||
if #available(iOS 18.0, *) {
|
TabView(selection: $selectedTab) {
|
||||||
TabView(selection: $selectedTab) {
|
ForEach(availableTabs) { tab in
|
||||||
ForEach(availableTabs) { tab in
|
tab
|
||||||
Tab(value: tab) {
|
.makeContentView(selectedTab: $selectedTab)
|
||||||
tab.makeContentView(selectedTab: $selectedTab)
|
.toolbar(horizontalSizeClass == .regular ? .hidden : .visible, for: .tabBar)
|
||||||
} label: {
|
.tabItem {
|
||||||
tab.label
|
tab.label
|
||||||
}
|
}
|
||||||
.defaultVisibility(.hidden, for: .automatic)
|
.tag(tab)
|
||||||
}
|
|
||||||
}
|
|
||||||
.tabViewStyle(.tabBarOnly)
|
|
||||||
.introspect(.tabView, on: .iOS(.v18)) { (tabview: UITabBarController) in
|
|
||||||
tabview.tabBar.isHidden = horizontalSizeClass == .regular
|
|
||||||
tabview.customizableViewControllers = []
|
|
||||||
tabview.moreNavigationController.isNavigationBarHidden = true
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
TabView(selection: $selectedTab) {
|
|
||||||
ForEach(availableTabs) { tab in
|
|
||||||
tab
|
|
||||||
.makeContentView(selectedTab: $selectedTab)
|
|
||||||
.tabItem {
|
|
||||||
tab.label
|
|
||||||
}
|
|
||||||
.tag(tab)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.introspect(.tabView, on: .iOS(.v17)) { (tabview: UITabBarController) in
|
|
||||||
tabview.tabBar.isHidden = horizontalSizeClass == .regular
|
|
||||||
tabview.customizableViewControllers = []
|
|
||||||
tabview.moreNavigationController.isNavigationBarHidden = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.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,
|
||||||
userPreferences.showiPadSecondaryColumn
|
userPreferences.showiPadSecondaryColumn
|
||||||
|
|
Loading…
Reference in a new issue