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
`DrawerActions` is an object containing methods for generating actions specific to drawer-based navigators. Its methods expand upon the actions available in [NavigationActions](navigation-actions.html).
8
+
9
+
The following actions are supported:
10
+
*[openDrawer](#openDrawer) - open the drawer
11
+
*[closeDrawer](#closeDrawer) - close the drawer
12
+
*[toggleDrawer](#toggleDrawer) - toggle the state, ie. switche from closed to open and vice versa
Copy file name to clipboardExpand all lines: docs/navigation-prop.md
+60-8Lines changed: 60 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: Navigation prop reference
4
4
sidebar_label: Navigation prop
5
5
---
6
6
7
-
Each `screen` component in your app is provided with the `navigation` prop automatically. It looks like this:
7
+
Each `screen` component in your app is provided with the `navigation` prop automatically. The prop contains various convenience functions that dispatch navigation actions on the route's router. It looks like this:
8
8
9
9
*`this.props.navigation`
10
10
*`navigate` - go to another screen, figures out the action it needs to take to do it
@@ -15,27 +15,44 @@ Each `screen` component in your app is provided with the `navigation` prop autom
15
15
*`setParams` - make changes to route's params
16
16
*`getParam` - get a specific param with fallback
17
17
*`dispatch` - send an action to router
18
+
*`dangerouslyGetParent` - function that returns the parent navigator, if any
18
19
19
-
It's important to highlight the `navigation` prop is _not_ passed in to _all_ components; only `screen` components receive this prop automatically! React Navigation doesn't do anything magic here. For example, if you were to define a `MyBackButton` component and render it as a child of a screen component, you would not be able to access the `navigation` prop on it.
20
+
It's important to highlight the `navigation` prop is _not_ passed in to _all_ components; only `screen` components receive this prop automatically! React Navigation doesn't do anything magic here. For example, if you were to define a `MyBackButton` component and render it as a child of a screen component, you would not be able to access the `navigation` prop on it. If, however, you wish to access the `navigation` prop in any of your components, you may use the [`withNavigation`](docs/with-navigation.html) HOC.
20
21
21
-
There are several additional functions on `this.props.navigation` that only if the current navigator is a stack navigator. These functions are alternatives to `navigate` and `goBack` and you can use whichever you prefer. The functions are:
22
+
### Navigator-dependent functions
23
+
24
+
There are several additional functions present on `this.props.navigation` based on the kind of the current navigator.
25
+
26
+
If the navigator is a stack navigator, several alternatives to `navigate` and `goBack` are provided and you can use whichever you prefer. The functions are:
22
27
23
28
*`this.props.navigation`
24
-
*`push` - navigate forward to new route in stack
29
+
*`push` - push a new route onto the stack
25
30
*`pop` - go back in the stack
26
31
*`popToTop` - go to the top of the stack
27
32
*`replace` - replace the current route with a new one
33
+
*`reset` - wipe the navigator state and replace it with the result of several actions
34
+
*`dismiss` - dismiss the current stack
35
+
36
+
37
+
If the navigator is a drawer navigator, the following are also available:
38
+
39
+
*`this.props.navigation`
40
+
*`openDrawer` - open the drawer
41
+
*`closeDrawer` - close the drawer
42
+
*`toggleDrawer` - toggle the state, ie. switch from closed to open and vice versa
28
43
29
44
## Common API reference
30
45
31
-
The vast majority of your interactions with the `navigation` prop will involve `navigate`, `goBack`, `state`, and `setParams`.
46
+
The vast majority of your interactions with the `navigation` prop will involve `navigate`, `goBack`, `state`, and `setParams` / `getParams`.
32
47
33
48
### `navigate` - Link to other screens
34
49
35
50
Call this to link to another screen in your app. Takes the following arguments:
*`routeName` - A destination routeName that has been registered somewhere in the app's router
@@ -108,8 +125,8 @@ Alternatively, as _screen A_ is the top of the stack, you can use `navigation.po
108
125
React Navigation emits events to screen components that subscribe to them:
109
126
110
127
*`willFocus` - the screen will focus
111
-
*`willBlur` - the screen will be unfocused
112
128
*`didFocus` - the screen focused (if there was a transition, the transition completed)
129
+
*`willBlur` - the screen will be unfocused
113
130
*`didBlur` - the screen unfocused (if there was a transition, the transition completed)
114
131
115
132
Example:
@@ -218,7 +235,7 @@ The following actions will work within any stack navigator:
218
235
219
236
### Push
220
237
221
-
Similar to navigate, push will move you forward to a new route in the stack.
238
+
Similar to navigate, push will move you forward to a new route in the stack. This differs from `navigate` in that `navigate will` pop back to earlier in the stack if a route of the given name is already present there. `push` will always add on top, so a route can be present multiple times.
222
239
223
240
`navigation.push(routeName, params, action)`
224
241
@@ -244,6 +261,19 @@ Call this to replace the current screen with the given route, with params and su
244
261
245
262
`navigation.replace(routeName, params, action)`
246
263
264
+
### Reset
265
+
266
+
Wipe the navigator state and replace it with the result of several actions.
If, for example, you have a screen component that can be presented within multiple navigators, you may use this to influence its behavior based on what navigator it is in. Be sure to always check that the call returns a valid value.
Copy file name to clipboardExpand all lines: docs/stack-actions.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,7 @@ The `replace` action replaces the route at the given key with another route.
64
64
65
65
### push
66
66
67
-
The `push` action adds a route on top of the stack and navigates forward to it. This differs from `navigate` in that `navigate` will pop back to earlier in the stack if a component is already mounted there. `push` will always add on top, so a component can be mounted multiple times.
67
+
The `push` action adds a route on top of the stack and navigates forward to it. This differs from `navigate` in that `navigate` will pop back to earlier in the stack if a route of the given name is already present there. `push` will always add on top, so a route can be present multiple times.
68
68
69
69
*`routeName` - _string_ - `routeName` to push onto the stack.
70
70
*`params` - _object_ - Screen params to merge into the destination route (found in the pushed screen through `this.props.navigation.state.params`).
0 commit comments