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

Add support for passing params on navigate to tabs #969

Merged
merged 1 commit into from
Apr 9, 2017

Conversation

mgtitimoli
Copy link

@mgtitimoli mgtitimoli commented Apr 9, 2017

@satya164
Copy link
Member

satya164 commented Apr 9, 2017

Can you describe the API changes a bit more? For example, what was the behaviour earlier and what is the behaviour now.

I'm assuming it allows passing params to another tab in the same tab router with navigate('Tab2', params). I see few issues with the approach,

Unlike stack navigator, screens in tab navigator are not rendered when you navigate to them, they are rendered in advance when the tab navigator gets rendered. Also you can navigate to other screens by swipe, or pressing the icon/label on the tab bar, and you cannot pass params this way. So the params need to be available when all the screens render.

You should be able to do navigate('TabsScreen', params), and those params will be available to all screens.

To change the params after rendering, as you might need sometimes, you should be able to use updateParams(params) to update the params.

@mgtitimoli
Copy link
Author

Hi @satya164, let me go through your questions one by one:

Can you describe the API changes a bit more? For example, what was the behaviour earlier and what is the behaviour now.

Sure:

  • earlier: there was no way to pass params to tabs, that this not only included TabNavigator, but also DrawerNavigator as it is made by TabRouters
  • now: you can pass params to tabs

Unlike stack navigator, screens in tab navigator are not rendered when you navigate to them, they are rendered in advance when the tab navigator gets rendered. Also you can navigate to other screens by swipe, or pressing the icon/label on the tab bar, and you cannot pass params this way. So the params need to be available when all the screens render.

This can easily be fixed by adding an onNavigate handler to the route definition so you could receive a navigation event, that would let you do the following that currently none of this is supported

  • cancel navigation
  • transform params (if there is no params and you need some, here is where you can set the defaults)

I find it crucial to widely support the ability of passing params no matter which kind of navigator/router are you using, as otherwise forces us to share information by using an external module with state, that as you know this should be avoided as much as possible, since complicates testing, and other stuff.

I also thing that in the future we should try to introduce a change that let us separate route params and route state as I described here since IMHO this concepts are different, but this is a subject of a different conversation.

@mgtitimoli mgtitimoli changed the title Add support to navigation to other tabs passing params Add support of passing params on navigate to tabs Apr 9, 2017
@mgtitimoli mgtitimoli changed the title Add support of passing params on navigate to tabs Add support for passing params on navigate to tabs Apr 9, 2017
@ericvicenti
Copy link
Contributor

Ok, this looks like a well-documented fix to a pretty common problem. Thanks for the contribution!

@nonameolsson
Copy link

Awesome! Is this somewhere in the documentation? Couldn't find it.

sourcecode911 pushed a commit to sourcecode911/react-navigation that referenced this pull request Mar 9, 2020
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

Successfully merging this pull request may close these issues.

None yet

4 participants