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

Reseting route state #78

Open
MohsenKhosravinia opened this issue Jan 30, 2022 · 5 comments
Open

Reseting route state #78

MohsenKhosravinia opened this issue Jan 30, 2022 · 5 comments

Comments

@MohsenKhosravinia
Copy link

Hit @nalexn, great job on you repo.
I have a question. How and when do you reset your routing states? Currently I have a hierarchy like below:
SplashView -> AuthenticationView -> SignUpView -> HomeView
I want to log out on home view and go back (move forward) to authentication view. when I change the routing state on home view and go to authentication view, all the previous flags for navigation are true and therefore the view goes forward again and again.

@nalexn
Copy link
Owner

nalexn commented Jan 30, 2022

Hey,

How and when do you reset your routing states?

If we're talking about a real "reset" of the state, there is one place I do this to essentially restart the app after appearance settings are changed by EnvironmentOverrides panel (a UI/UX testing tool I built, which is also demoed as part of this project).

Normally you don't want a full reset, but toggle a few flags at once to pop back to your AuthenticationView. That is, there should be a flag that presented SignUpView and another one that displayed HomeView, so as soon as you toggle both off you should be good.

If this tip does not help, please do provide the code of how you're changing the routing state to pop back and the routing state structure itself.

@MohsenKhosravinia
Copy link
Author

@nalexn Would you please take a look at this project?
https://gitlab.com/MohsenKhosravinia/cleanarchvaiyo

@nalexn
Copy link
Owner

nalexn commented Jan 30, 2022

Ok, after a quick glance I think you should remove NavigationLink here and leave just the Button:

NavigationLink(destination: AuthenticationView(), isActive: routingBinding.shouldNavigateToAuthetication) {
    Button {
        logout()
    } label: {
        Image(systemName: "power")
            //...
    }
}

then, I'd removed the var shouldNavigateToAuthetication: Bool = false in the HomeView.Routing. In your logout, instead of

injected.appState[\.routing.home.shouldNavigateToAuthetication] = true

you should toggle the container.interactors.splashInteractor.isLogin, since I can see it toggles between AuthenticationView and HomeView:

if container.interactors.splashInteractor.isLogin {
    NavigationLink(
        destination: HomeView(),
        isActive: $showHomeView) { EmptyView() }
} else {
    NavigationLink(
        destination: AuthenticationView(),
        isActive: $showAuthenticationView) { EmptyView() }
}

@MohsenKhosravinia
Copy link
Author

Thank you for the effort but I want to go forward (after log out I want to instantiate new authentication view). I did follow your steps but the log out button does nothing without navigation link. When we instantiate a view twice (based on a UX situation) we don't get the proper result because the app state holds the routing last states and the automatic navigation happens afterward. Do you have any suggestion on that? I was trying to reset the AppState.Routing struct on the .onAppear or .onDisappear but the result was messy and not satisfying.

@nalexn
Copy link
Owner

nalexn commented Jan 30, 2022

Ok, then if you actually need to show another AuthenticationView and not pop back to the original, the second one has to rely on separate routing parameters. Introduce a secondary set of routing params for AuthenticationView, and then control which set to use by providing an enum or a bool value as init parameter for the AuthenticationView

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

2 participants