Skip to content

Commit 2021873

Browse files
committed
Tweak nesting navigators docs
1 parent 83eb00f commit 2021873

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

versioned_docs/version-5.x/nesting-navigators.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,29 @@ For example, if you're calling `navigation.goBack()` in a nested screen, it'll o
6060

6161
### Navigator specific methods are available in the navigators nested inside
6262

63-
For example, if you have a stack inside a drawer navigator, the drawer's `openDrawer`, `closeDrawer` methods etc. will also be available on the `navigation` prop in the screen's inside the stack navigator. But say you have a stack navigator as the parent of the drawer, then the screens inside the stack navigator won't have access to these methods, because they aren't nested inside the drawer.
63+
For example, if you have a stack inside a drawer navigator, the drawer's `openDrawer`, `closeDrawer`, `toggleDrawer` methods etc. will also be available on the `navigation` prop in the screen's inside the stack navigator. But say you have a stack navigator as the parent of the drawer, then the screens inside the stack navigator won't have access to these methods, because they aren't nested inside the drawer.
6464

6565
Similarly, if you have a tab navigator inside stack navigator, the screens in the tab navigator will get the `push` and `replace` methods for stack in their `navigation` prop.
6666

67+
If you need to dispatch actions to the nested child navigators from a parent, you can use [`navigation.dispatch`](navigation-prop.md#dispatch):
68+
69+
```js
70+
navigation.dispatch(DrawerActions.toggleDrawer());
71+
```
72+
6773
### Nested navigators don't receive parent's events
6874

69-
For example, if you have a stack navigator nested inside a tab navigator, the screens in the stack navigator won't receive the events emitted by the parent tab navigator such as (`tabPress`) when using `navigation.addListener`. To receive events from parent navigator, you can explicitly listen to parent's events with `navigation.dangerouslyGetParent().addListener`.
75+
For example, if you have a stack navigator nested inside a tab navigator, the screens in the stack navigator won't receive the events emitted by the parent tab navigator such as (`tabPress`) when using `navigation.addListener`.
76+
77+
To receive events from parent navigator, you can explicitly listen to parent's events with `navigation.dangerouslyGetParent()`:
78+
79+
```js
80+
const unsubscribe = navigation
81+
.dangerouslyGetParent()
82+
.addListener('tabPress', (e) => {
83+
// Do something
84+
});
85+
```
7086

7187
### Parent navigator's UI is rendered on top of child navigator
7288

0 commit comments

Comments
 (0)