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

Prevent certain scenes in stack from always being mounted? #2254

Closed
stuffmattdoes opened this issue Aug 17, 2017 · 5 comments
Closed

Prevent certain scenes in stack from always being mounted? #2254

stuffmattdoes opened this issue Aug 17, 2017 · 5 comments

Comments

@stuffmattdoes
Copy link

stuffmattdoes commented Aug 17, 2017

Hey folks!

Question:
Is it possible to prevent certain scenes in the nav stack from always being mounted?

This question has been asked before, but was considered "closed" once V3 became obsolete; however, I'm still seeing this behavior without any viable solutions.

I've got a few scenes in a todo-like app. The hierarchy looks like:
Lists -> List Todos -> List Options.

On the List Options scene, you have the ability to delete the list. Upon doing so, I send you back to the Lists scene (which is 2 scenes back). However, the List Todos, being still mounted in the stack, tries to pull in props from the now non-existent list, and therefore throws errors.

This would not be the case if previous stack scenes became unmounted. I try to catch this error before the component is updated like so, but to no avail:

componentWillReceiveProps(nextProps) { if (!nextProps.currentList) { console.log('NO LIST'); Actions.pop(); } }

I have been racking by brain over this the past few days. This behavior doesn't seem right, but the current RNRF framework doesn't allude to supporting anything like this. It would be very helpful.

On the other hand, I'm open to rethinking my code architecture if that is the issue. I am at a complete production standstill, so any advice is welcome. Thank you!

Versions:
"react-native": "0.45.1",
"react-native-router-flux": "^4.0.0-beta.17",

@stuffmattdoes stuffmattdoes changed the title Prevent all scenes from rendering? Prevent all scenes in stack from always being mounted? Aug 17, 2017
@stuffmattdoes stuffmattdoes changed the title Prevent all scenes in stack from always being mounted? Prevent certain scenes in stack from always being mounted? Aug 17, 2017
@aksonov
Copy link
Owner

aksonov commented Aug 21, 2017

All screens in nav stack must be mounted, it is by design for any navigation. You really need to rethink your architecture. I'd just catch exception for non-exist ID (i.e. render empty screen) and do 'double' pop after item removing.

@aksonov
Copy link
Owner

aksonov commented Aug 22, 2017

Another option is to 'reset' whole stack to Lists instead of Actions.pop usage.

@stuffmattdoes
Copy link
Author

stuffmattdoes commented Aug 22, 2017

Hey Pavel, thanks for your replies!

I do currently pop twice in an attempt to navigate back two screens after deleting the item. The code snippet I posted above should catch if the list exists or not (since that scene is still mounted before/after the deletion) but the component still renders before pop() happens.

As for the reset - how would you recommend handling this? I have <Scene ...props type='reset' /> which does replace the screen without the transition animation, but throws the same errors I've been seeing immediately following. It's as if the stack is reset but the components have not yet been unmounted.

As far as architecture, I'll probably rework it as you suggested. Instead of deleting the item immediately, I'll throw it into a queue and resolve the queue once I've reached the initial scene in the stack after pop()

@aksonov
Copy link
Owner

aksonov commented Aug 23, 2017

As far as architecture, I'll probably rework it as you suggested. Instead of deleting the item immediately, I'll throw it into a queue and resolve the queue once I've reached the initial scene in the stack after pop()

Yes, it seems to be good idea - I think you could just try Actions.pop();Actions.pop();delete_item() or Actions.Lists({type:'reset'});delete_item()

@aksonov aksonov closed this as completed Aug 23, 2017
@stuffmattdoes
Copy link
Author

Sounds good. Alternatively, I've begun to check if certain props exist in shouldComponentUpdate. Thank you for your help!

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

No branches or pull requests

2 participants