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(selectedTab: $selectedTab, 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) } 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 } }