react-navigation / react-navigation.github.io

Home of the documentation and other miscellanea
https://reactnavigation.org/
MIT License
313 stars 1.9k forks source link

Clarify the example in # Navigation actions are handled by current navigator and bubble up if couldn't be handled #730

Open yilinjuang opened 4 years ago

yilinjuang commented 4 years ago

https://reactnavigation.org/docs/nesting-navigators/#navigation-actions-are-handled-by-current-navigator-and-bubble-up-if-couldnt-be-handled

In the above example, when calling navigate('Settings'), inside Profile screen, the nested stack navigator will handle it, but if you call navigate('Home'), the parent tab navigator will handle it.

This example doesn't sound right to me but not sure how to correct it.

GoudekettingRM commented 4 years ago

I was reading through the docs and noticed the same issue with this example.

The example that is in the docs right now actually calls navigate("Settings") while it is in the same Navigator if I am correct. Therefore, nothing will bubble up, if I read this correctly.

I think the example should be something like this:

In the above example, when calling navigate('Messages'), inside Feed screen, the nested tab navigator will handle it, but if you call navigate('Settings'), the parent stack navigator will handle it.

This will call navigate('Messages') from the Feed screen, which is in the same Navigator. This will be handled locally, by the Home component's Tab Navigator. Calling navigate('Settings') from the Feed screen will actually bubble up to the Stack Navigator, since the Home component's Tab Navigator does not have a 'Settings' screen.

I made a PR for this: #740

P.S. This is my first open source PR so if any information you need is missing or the docs also need to be updated for previous versions I'll update my PR! :ok_hand: