-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Render available scenes based on app state #2824
Comments
Hi @Matt33, have you been able to find a solution to your problem? |
Hey @mnogueron , I did a workaround that I thought would be the most beneficial in terms of keeping all the redirection logic within router component (meaning keeping the navigation component a pure function of state) like this:
|
@Matt33 Really like your solution, but it seems to not work when you try to switch between two stacks. Just before moving to the next stack, it pops and try to render the previous page in the stack, thus render things that may not be available anymore (for example in the case of a logout). |
@mnogueron Sorry for late response - yes I've came across the same problem. The solution is either not using type='reset' for scenes in another stack but rather using 'replace'.
instead of:
|
@Matt33 I've ben trying to get your solution working with our product, but I always get stuck at the moment where I need to switch between two stacks. Your solution is working fine when you don't have multiple scenes pushed in the history and that depend on an object from the reducer that can be changed. I explain my self: -> LoginStack If we consider that architecture (Settings is pushed on top of Profile), and that you can log out from Settings. Logging out will remove content of object X that may be displayed in Profile. Then when you log out in Settings, the app will try to render Profile with data that don't exist anymore before switching to the LoginStack, leading to a crash. |
@mnogueron I understand your problem, was dealing with the same one - had to change my app logic cause of that which was fortunately just an easy change for me but believe it might not be for other cases. |
Is this the best way to approach the v3 equivalent of Switch/selector ? Basically, in v3 I had:
Basically, if redux has app.persisted truthy, show 'wait', otherwise show 'loggedIn' if auth.token is set, otherwise default to 'auth'. The migration does says "Switch is removed - you may use onEnter/onExit handlers for more flexible logic." - but I don't see any examples, not even in the example app. The confusing part is that onEnter/onExit only seems to work where component is defined in a scene, ie for each subscreen, and not the scene/tab container itself. But it almost seems like onEnter would be an appropriate place to navigate to a specific tab. The problem in my case is that I have multiple levels of scenes deep - there the switch between logged in user and not logged in, among others. It seems like it's doable your way (via componentWillRecieveProps) but then I have to have several nested if statements to do so to manage the distinct tab systems (ie handling post-login welcome screens or not). Suggestions? |
onEnter/onExit params are equivalent of Switch (i.e. control of flow). We may restore Switch if it is really needed (feel free to submit PR) |
Version
Tell us which versions you are using:
Expected behaviour
I want to be able to render available scenes based on the app state stored in redux.
Something like:
Actual behaviour
Using the above code I am getting:
This worked pretty well in v3 but trying to migrate to v4 it's not working (pretty sure I might be missing something obvious). Would really appreciate any kind of input.
Thanks a lot.
The text was updated successfully, but these errors were encountered: