React Navigation understanding navigator nestings

Xyz*_*zor 5 javascript navigation react-native redux react-navigation

I've been using react-navigation for almost half a year, but I still don't understand the nesting part of it. How the navigation prop is inherited, how to communicate, etc..

I created a demo on snack, from the redux example app.

Demo

I'd like to understand these:

  1. What happens with the navigation prop if I navigate to a child navigator?

  2. How to navigate from a child navigators screen to the parents screen or the parents other child's screen

  3. How to remove a child navigator from the state?

The simplest example: On a login event I reset the navigator with the Main StackNavigator. The problem with this is, that I have to rebuild manually the whole Main state. It would be much easier If I could just remove somehow the Auth StackNavigator and keep the Main Stack.

  1. Is it possible to trigger redux event with the child navigators navigate actions?

I wrapped the Main navigation (StackNavigator) component with a redux component as the doc says. It works fine until I navigate into a child component. The navigation props niavigate method stops dispatching redux actions.

  1. This, I couldn't recreate in the demo

I have a Component and a DrawerNavigator inside a StackNavigator. If i navigate into the DrawerNavigator (there is only 1 screen there) from the Component, I can't go back to that Component with this:

this.props.navigation.goBack()
Run Code Online (Sandbox Code Playgroud)

The odd part is that its only impossible inside the screen's component. From the screen's header component its working.

inD*_*eam 1

  1. 它始终可以访问props.navigation.

  2. reset需要执行操作才能导航到父/子导航器。
    另外,由于需要#1127 key: null

  3. navigation.replace是登录导航到主屏幕的另一个选项(如果屏幕位于同一导航器中),reset如果需要动画过渡,请使用。或者参见#295中的其他方法

  4. navigate只能在同一个导航器中导航到屏幕,其他方法请参考答案3。

  5. 也许该组件缺少navigationprops

工作演示