mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-12-28 07:50:15 +01:00
49 lines
1.3 KiB
Swift
49 lines
1.3 KiB
Swift
import Env
|
|
import SwiftUI
|
|
|
|
extension IceCubesApp {
|
|
var tabBarView: some View {
|
|
TabView(selection: .init(get: {
|
|
selectedTab
|
|
}, set: { newTab in
|
|
if newTab == selectedTab {
|
|
/// Stupid hack to trigger onChange binding in tab views.
|
|
popToRootTab = .other
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
|
|
popToRootTab = selectedTab
|
|
}
|
|
}
|
|
|
|
HapticManager.shared.fireHaptic(.tabSelection)
|
|
SoundEffectManager.shared.playSound(.tabSelection)
|
|
|
|
selectedTab = newTab
|
|
})) {
|
|
ForEach(availableTabs) { tab in
|
|
tab.makeContentView(popToRootTab: $popToRootTab)
|
|
.tabItem {
|
|
if userPreferences.showiPhoneTabLabel {
|
|
tab.label
|
|
} else {
|
|
Image(systemName: tab.iconName)
|
|
}
|
|
}
|
|
.tag(tab)
|
|
.badge(badgeFor(tab: tab))
|
|
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .tabBar)
|
|
}
|
|
}
|
|
.id(appAccountsManager.currentClient.id)
|
|
.environment(\.selectedTab, selectedTab)
|
|
}
|
|
|
|
private func badgeFor(tab: Tab) -> Int {
|
|
if tab == .notifications, selectedTab != tab,
|
|
let token = appAccountsManager.currentAccount.oauthToken
|
|
{
|
|
return watcher.unreadNotificationsCount + (userPreferences.notificationsCount[token] ?? 0)
|
|
}
|
|
return 0
|
|
}
|
|
}
|