From 5ab9566ca558939d881a72d88844b82e4d6d2967 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Thu, 9 Feb 2023 18:48:31 +0100 Subject: [PATCH] Ensure account and tab switching is done without animations --- IceCubesApp/App/IceCubesApp.swift | 16 ++++++++++------ IceCubesApp/App/SideBarView.swift | 4 +++- .../Sources/AppAccount/AppAccountView.swift | 6 +++++- .../AppAccount/AppAccountsSelectorView.swift | 6 +++++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/IceCubesApp/App/IceCubesApp.swift b/IceCubesApp/App/IceCubesApp.swift index bc37af5b..70302ba4 100644 --- a/IceCubesApp/App/IceCubesApp.swift +++ b/IceCubesApp/App/IceCubesApp.swift @@ -133,14 +133,18 @@ struct IceCubesApp: App { 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 + var transaction = Transaction() + transaction.disablesAnimations = true + withTransaction(transaction) { + if newTab == selectedTab { + /// Stupid hack to trigger onChange binding in tab views. + popToRootTab = .other + DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) { + popToRootTab = selectedTab + } } + selectedTab = newTab } - selectedTab = newTab HapticManager.shared.fireHaptic(of: .tabSelection) })) { ForEach(availableTabs) { tab in diff --git a/IceCubesApp/App/SideBarView.swift b/IceCubesApp/App/SideBarView.swift index 2ab16117..11a7e38a 100644 --- a/IceCubesApp/App/SideBarView.swift +++ b/IceCubesApp/App/SideBarView.swift @@ -75,7 +75,9 @@ struct SideBarView: View { if account.id == appAccounts.currentAccount.id { selectedTab = .profile } else { - withAnimation { + var transation = Transaction() + transation.disablesAnimations = true + withTransaction(transation) { appAccounts.currentAccount = account } } diff --git a/Packages/AppAccount/Sources/AppAccount/AppAccountView.swift b/Packages/AppAccount/Sources/AppAccount/AppAccountView.swift index a251de5e..f0fbfb3e 100644 --- a/Packages/AppAccount/Sources/AppAccount/AppAccountView.swift +++ b/Packages/AppAccount/Sources/AppAccount/AppAccountView.swift @@ -74,7 +74,11 @@ public struct AppAccountView: View { { routerPath.navigate(to: .accountSettingsWithAccount(account: account, appAccount: viewModel.appAccount)) } else { - appAccounts.currentAccount = viewModel.appAccount + var transation = Transaction() + transation.disablesAnimations = true + withTransaction(transation) { + appAccounts.currentAccount = viewModel.appAccount + } } } } diff --git a/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift b/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift index 69562576..c0d16cb6 100644 --- a/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift +++ b/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift @@ -75,7 +75,11 @@ public struct AppAccountsSelectorView: View { { routerPath.navigate(to: .accountDetailWithAccount(account: account)) } else { - appAccounts.currentAccount = viewModel.appAccount + var transation = Transaction() + transation.disablesAnimations = true + withTransaction(transation) { + appAccounts.currentAccount = viewModel.appAccount + } } HapticManager.shared.fireHaptic(of: .buttonPress)