You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-5.x/navigation-events.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,8 +21,6 @@ Each callback registered as an event listener receive an event object as its arg
21
21
-`target` - The route key for the screen that should receive the event. For some events, this maybe `undefined` if the event wasn't related to a specific screen.
22
22
-`preventDefault` - For some events, there may be a `preventDefault` method on the event object. Calling this method will prevent the default action performed by the event (such as switching tabs on `tabPress`). Support for preventing actions are only available for certain events like `tabPress` and won't work for all events.
23
23
24
-
One thing to keep in mind is that you can only listen to events from the immediate parent navigator. For example, if you try to add a listener in a screen is inside a stack that's nested in a tab, it won't get the `tabPress` event. If you need to listen to an event from a parent navigator, you may use `navigation.getParent()` to get a reference to parent navigator's navigation prop and add a listener.
25
-
26
24
There are 2 ways to listen to events:
27
25
28
26
### `navigation.addListener`
@@ -78,6 +76,8 @@ class Profile extends React.Component {
78
76
}
79
77
```
80
78
79
+
One thing to keep in mind is that you can only listen to events from the immediate navigator with `addListener`. For example, if you try to add a listener in a screen that's inside a stack that's nested in a tab, it won't get the `tabPress` event. If you need to listen to an event from a parent navigator, you may use `navigation.getParent()` to get a reference to parent navigator's navigation prop and add a listener.
80
+
81
81
### `listeners` prop on `Screen`
82
82
83
83
Sometimes you might want to add a listener from the component where you defined the navigator rather than inside the screen. You can use the `listeners` prop on the `Screen` component to add listeners. The `listeners` prop takes an object with the event names as keys and the listener callbacks as values.
Copy file name to clipboardExpand all lines: versioned_docs/version-6.x/navigation-events.md
+14-4Lines changed: 14 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,9 +32,7 @@ This event is emitted when the user is leaving the screen, there's a chance to [
32
32
33
33
## Listening to events
34
34
35
-
There are multiple ways to listen to events from the navigators. Before we get into how to add listeners, one thing to keep in mind is that you can only listen to events from the immediate parent navigator. For example, if you try to add a listener in a screen is inside a stack that's nested in a tab, it won't get the `tabPress` event. If you need to listen to an event from a parent navigator, you may use [`navigation.getParent`](navigation-prop.md#getparent) to get a reference to parent navigator's navigation prop and add a listener.
36
-
37
-
Each callback registered as an event listener receive an event object as its argument. The event object contains few properties:
35
+
There are multiple ways to listen to events from the navigators. Each callback registered as an event listener receives an event object as its argument. The event object contains few properties:
38
36
39
37
-`data` - Additional data regarding the event passed by the navigator. This can be `undefined` if no data was passed.
40
38
-`target` - The route key for the screen that should receive the event. For some events, this maybe `undefined` if the event wasn't related to a specific screen.
@@ -95,6 +93,18 @@ class Profile extends React.Component {
95
93
}
96
94
```
97
95
96
+
One thing to keep in mind is that you can only listen to events from the immediate navigator with `addListener`. For example, if you try to add a listener in a screen that's inside a stack that's nested in a tab, it won't get the `tabPress` event. If you need to listen to an event from a parent navigator, you may use [`navigation.getParent`](navigation-prop.md#getparent) to get a reference to parent navigator's navigation prop and add a listener.
97
+
98
+
```js
99
+
constunsubscribe= navigation
100
+
.getParent('MyTabs')
101
+
.addListener('tabPress', (e) => {
102
+
// Do something
103
+
});
104
+
```
105
+
106
+
Here `'MyTabs'` refers to the value you pass in the `id` prop of the parent `Tab.Navigator` whose event you want to listen to.
107
+
98
108
### `listeners` prop on `Screen`
99
109
100
110
Sometimes you might want to add a listener from the component where you defined the navigator rather than inside the screen. You can use the `listeners` prop on the `Screen` component to add listeners. The `listeners` prop takes an object with the event names as keys and the listener callbacks as values.
@@ -136,7 +146,7 @@ Example:
136
146
137
147
### `screenListeners` prop on the navigator
138
148
139
-
You can pass a prop named `screenListeners` to the navigator component, where you can specify listeners for events from all screens. This can be useful if you want to listen to specific events regardless of the screen, or want to listen to common events such as `state` which is emitted to all screens.
149
+
You can pass a prop named `screenListeners` to the navigator component, where you can specify listeners for events from all screens for this navigator. This can be useful if you want to listen to specific events regardless of the screen, or want to listen to common events such as `state` which is emitted to all screens.
Here `'MyTabs'` refers to the value you pass in the `id` prop of the parent `Tab.Navigator` whose event you want to listen to.
98
+
95
99
### Parent navigator's UI is rendered on top of child navigator
96
100
97
101
For example, when you nest a stack navigator inside a drawer navigator, you'll see that the drawer appears above the stack navigator's header. However, if you nest the drawer navigator inside a stack, the drawer will appear below the header of the stack. This is an important point to consider when deciding how to nest your navigators.
Copy file name to clipboardExpand all lines: versioned_docs/version-6.x/upgrading-from-5.x.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ React Navigation 6 requires newer versions of following libraries:
22
22
To upgrade `react-native-safe-area-context` and `react-native-screens` to the latest supported versions, do the following:
23
23
24
24
> **NOTE:**
25
-
>
25
+
>
26
26
> If your react-native Version is <= 0.63.4, don't use `react-native-safe-area-context` in Version 4, but only till 3.4.1. [More Information see here](https://github.com/th3rdwave/react-native-safe-area-context/issues/248)
27
27
28
28
For Expo managed projects:
@@ -177,7 +177,7 @@ A common scenario where you should use `merge: true` is if you have a custom tab
177
177
178
178
### Dropped `dangerously` from `dangerouslyGetParent` and `dangerouslyGetState`
179
179
180
-
The `dangerouslyGetParent` and `dangerouslyGetState` methods on the `navigation` prop are useful in many scenarios, and sometimes necessary. So we dropped the `dangerously` prefix to make it clear that it's safe to use. Now you can use [`navigation.getParent()`](navigation-prop.md#getparent) and [`navigation.getState()`](navigation-prop.md#getstate).
180
+
The `dangerouslyGetParent` and `dangerouslyGetState` methods on the `navigation` prop are useful in many scenarios, and sometimes necessary. So we dropped the `dangerously` prefix to make it clear that it's safe to use. Now you can use [`navigation.getParent`](navigation-prop.md#getparent) and [`navigation.getState()`](navigation-prop.md#getstate).
0 commit comments