Post

Replies

Boosts

Views

Activity

Reply to Additional Appearance Calls Triggered When Removing TabView or NavigationView/Stack From View Tree
I faced the same problem recently and my workaround is to create a view modifier for authenticated views and use it only for such screens/views: import SwiftUI struct GuardedOnAppearViewModifier: ViewModifier { let perform: () -> Void @EnvironmentObject private var accountState: AccountState func body(content: Content) -> some View { content .onAppear { guard accountState.isAuthorized else { return } perform() } } } extension View { func onGuardedAppear(perform: @escaping () -> Void) -> some View { modifier(GuardedOnAppearViewModifier(perform: perform)) } } So when I'm logging out none of my onAppear method of authorized views will be called during the removal of NavigationView.
May ’23