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

Proper way of using onEnter / success? #2109

Closed
EnriqueDev opened this issue Jul 25, 2017 · 9 comments
Closed

Proper way of using onEnter / success? #2109

EnriqueDev opened this issue Jul 25, 2017 · 9 comments

Comments

@EnriqueDev
Copy link

Hi! First of all congratulations for this awesome work you have done so far, it has been very useful. I would like to know what is the correct way to use the onEnter/success props of the scene and if can I call component methods from there.

Thanks.

PD: If someone explains it properly I could maybe write a doc/example and make a pull request.

@aksonov
Copy link
Owner

aksonov commented Jul 25, 2017

You can call static function onEnter of component or just pass it as prop to Scene. If it returns non-null value RNRF makes automatic transition to scene defined by success (failure otherwise)

@aksonov
Copy link
Owner

aksonov commented Jul 25, 2017

Sorry, no access to component methods - it just accesses to your navigation state, like navBar static methods.

@EnriqueDev
Copy link
Author

So inside my component I should call:

static onEnter = (callback) => {
    callback()
}

?

@aksonov
Copy link
Owner

aksonov commented Jul 25, 2017

Current state params are passed to onEnter. So you could try to pass callback, like
Actions.login({callback}) and then your onEnter will be executed with {callback} param.

@EnriqueDev
Copy link
Author

EnriqueDev commented Jul 25, 2017

My main problem here is that as ReactNavigation does not unmount tabs, all the component's lifecycle methods are not called and it's impossible to perform requests in the usual place. Using the current API v4 what would you recommend as an approach (not code, I just need some guidance)?.

Thanks for your time!

@aksonov
Copy link
Owner

aksonov commented Jul 25, 2017

I believe onEnter is way to go. Another way is to use type=replace instead of tabs, so your scenes will be unmounted.

@EnriqueDev
Copy link
Author

EnriqueDev commented Jul 26, 2017

good enough. Is there a way to set the lazy prop when using TabNavigator?

@aksonov
Copy link
Owner

aksonov commented Jul 26, 2017 via email

@EnriqueDev
Copy link
Author

Awesome. Thank you so much!

@aksonov aksonov closed this as completed Jul 30, 2017
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