Optimize tabbar selection

This commit is contained in:
Thomas Ricouard 2023-03-04 09:30:27 +01:00
parent ab06c0ab17
commit cfee153050
1 changed files with 14 additions and 12 deletions

View File

@ -158,17 +158,20 @@ struct IceCubesApp: App {
TabView(selection: .init(get: { TabView(selection: .init(get: {
selectedTab selectedTab
}, set: { newTab in }, set: { newTab in
var transaction = Transaction() if newTab == selectedTab {
transaction.disablesAnimations = true /// Stupid hack to trigger onChange binding in tab views.
withTransaction(transaction) { popToRootTab = .other
if newTab == selectedTab { DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
/// Stupid hack to trigger onChange binding in tab views. popToRootTab = selectedTab
popToRootTab = .other
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
popToRootTab = selectedTab
}
} }
selectedTab = newTab }
selectedTab = newTab
DispatchQueue.main.async {
HapticManager.shared.fireHaptic(of: .tabSelection)
SoundEffectManager.shared.playSound(of: .tabSelection)
if selectedTab == .notifications, if selectedTab == .notifications,
let token = appAccountsManager.currentAccount.oauthToken let token = appAccountsManager.currentAccount.oauthToken
{ {
@ -176,8 +179,7 @@ struct IceCubesApp: App {
watcher.unreadNotificationsCount = 0 watcher.unreadNotificationsCount = 0
} }
} }
HapticManager.shared.fireHaptic(of: .tabSelection)
SoundEffectManager.shared.playSound(of: .tabSelection)
})) { })) {
ForEach(availableTabs) { tab in ForEach(availableTabs) { tab in
tab.makeContentView(popToRootTab: $popToRootTab) tab.makeContentView(popToRootTab: $popToRootTab)