Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pops back when updating @ObservableObject #133

Open
undertaker28 opened this issue Apr 6, 2024 · 0 comments
Open

Pops back when updating @ObservableObject #133

undertaker28 opened this issue Apr 6, 2024 · 0 comments

Comments

@undertaker28
Copy link

undertaker28 commented Apr 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant