stinsen icon indicating copy to clipboard operation
stinsen copied to clipboard

Pops back when updating @ObservableObject

Open undertaker28 opened this issue 10 months ago • 0 comments

Hi, I have the same problem, which is described in the link below. https://forums.developer.apple.com/forums/thread/693137 In short:

  1. I navigate to: LoginView -> SignUpView or LoginView -> ForgotPasswordView
  2. I update the environmentObject in SignUpView or ForgotPasswordView but then I get immediately pushed back to LoginView

Main:

@main
struct ARVisioApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
    @StateObject private var userStateViewModel = UserStateViewModel(networkMonitor: NetworkMonitor())
    
    var body: some Scene {
        WindowGroup {
            NavigationViewCoordinator(AuthenticationCoordinator(userStateViewModel: userStateViewModel)).view()
        }
        .modelContainer(for: ARObject.self)
    }
}

AuthenticationCoordinator:

final class AuthenticationCoordinator: NavigationCoordinatable {
    let stack = NavigationStack(initial: \AuthenticationCoordinator.start)
    var userStateViewModel: UserStateViewModel
    
    init(userStateViewModel: UserStateViewModel) {
        self.userStateViewModel = userStateViewModel
    }
    
    @Root var start = makeStart
    @Route(.push) var signUp = makeSignUp
    @Route(.push) var forgotPassword = makeForgotPassword
}

AuthenticationCoordinator+Factory:

extension AuthenticationCoordinator {
    @ViewBuilder func makeStart() -> some View {
        LoginView()
            .environmentObject(userStateViewModel)
    }
    
    @ViewBuilder func makeSignUp() -> some View {
        SignUpView()
            .environmentObject(userStateViewModel)
    }
    
    @ViewBuilder func makeForgotPassword() -> some View {
        ForgotPasswordView()
            .environmentObject(userStateViewModel)
    }
}

Could you please tell me how this problem can be solved? Without Stinsen, using NavigationView and NavigationStack, everything works.

undertaker28 avatar Apr 06 '24 13:04 undertaker28