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
Containers are responsible for managing your app state and linking your top-level navigator to the app environment. On Android, the app container uses the Linking API to handle the back button. The container can also be configured to persist your navigation state. On web, you'd use different containers than React Native.
8
+
9
+
> Note: In v2 and earlier, the containers in React Navigation were automatically provided by the `create*Navigator` functions. Now you are required to use the container directly. In v3 we also renamed `createNavigationContainer` to `createAppContainer`.
10
+
11
+
A quick example of `createAppContainer`:
12
+
13
+
```
14
+
import { createAppContainer } from 'react-navigation';
15
+
// you can also import from @react-navigation/native
Function that gets called every time navigation state managed by the navigator changes. It receives the previous state, the new state of the navigation and the action that issued state change. By default it prints state changes to the console.
38
+
39
+
### `uriPrefix`
40
+
41
+
The prefix of the URIs that the app might handle. This will be used when handling a [deep link](deep-linking.html) to extract the path passed to the router.
42
+
43
+
## Calling Dispatch or Navigate on App Container
44
+
45
+
In case you want to dispatch actions on an app container, you can use a React [`ref`](https://facebook.github.io/react/docs/refs-and-the-dom.html#the-ref-callback-attribute) to call the `dispatch` method on it:
Copy file name to clipboardExpand all lines: docs/custom-navigator-overview.md
+1-42Lines changed: 1 addition & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,47 +22,6 @@ Under the hood, navigators are plain React components.
22
22
The navigators render application screens which are just React components.
23
23
24
24
To learn how to create screens, read about:
25
+
25
26
-[Screen `navigation` prop](navigation-prop.html) to allow the screen to dispatch navigation actions, such as opening another screen
26
27
- Screen `navigationOptions` to customize how the screen gets presented by the navigator (e.g. [header title](stack-navigator.html#navigationoptions-used-by-stacknavigator), tab label)
27
-
28
-
### Calling Navigate on Top Level Component
29
-
30
-
In case you want to use Navigator from the same level you declare it you can use react's [`ref`](https://facebook.github.io/react/docs/refs-and-the-dom.html#the-ref-callback-attribute) option:
Please notice that this solution should only be used on the top level navigator.
51
-
52
-
## Navigation Containers
53
-
54
-
The built in navigators can automatically behave like top-level navigators when the navigation prop is missing. This functionality provides a transparent navigation container, which is where the top-level navigation prop comes from.
55
-
56
-
When rendering one of the included navigators, the navigation prop is optional. When it is missing, the container steps in and manages its own navigation state. It also handles URLs, external linking, and Android back button integration.
57
-
58
-
For the purpose of convenience, the built-in navigators have this ability because behind the scenes they use `createNavigationContainer`. Usually, navigators require a navigation prop in order to function.
Function that gets called every time navigation state managed by the navigator changes. It receives the previous state, the new state of the navigation and the action that issued state change. By default it prints state changes to the console.
65
-
66
-
### `uriPrefix`
67
-
68
-
The prefix of the URIs that the app might handle. This will be used when handling a [deep link](deep-linking.html) to extract the path passed to the router.
Copy file name to clipboardExpand all lines: docs/custom-navigators.md
+2-8Lines changed: 2 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,6 @@ class CustomNavigator extends React.Component {
52
52
}
53
53
```
54
54
55
-
56
55
## Navigator Navigation Prop
57
56
58
57
The navigation prop passed down to a navigator only includes `state`, `dispatch`, and `addListener`. This is the current state of the navigator, and an event channel to send action requests.
@@ -102,7 +101,7 @@ To help developers implement custom navigators, the following utilities are prov
102
101
This utility combines a [router](routers.html) and a [navigation view](navigation-views.html) together in a standard way:
@@ -127,7 +126,7 @@ Then the view will be rendered in the following way:
127
126
/>
128
127
```
129
128
130
-
The `navigation` prop is the same navigation prop that was passed into the navigator.
129
+
The `navigation` prop is the same navigation prop that was passed into the navigator.
131
130
132
131
Both `navigationConfig` and `screenProps` are simply passed through, as defined above.
133
132
@@ -142,8 +141,3 @@ A scene descriptor has the following properties:
142
141
-`navigation`, the child navigation prop, including actions and the route `state`
143
142
-`state`, the navigation state for the child screen (a shortcut for `navigation.state`)
144
143
-`key`, the key of the route (a shortcut for `navigation.state.key`)
145
-
146
-
147
-
### `createNavigationContainer`
148
-
149
-
If you want your navigator to be usable as a top-level component, (without a navigation prop being passed in), you can use `createNavigationContainer`. This utility will make your navigator act like a top-level navigator when the navigation prop is missing. It will manage the app state, and integrate with app-level nav features, like handling incoming and outgoing links, and Android back button behavior.
Copy file name to clipboardExpand all lines: docs/hello-react-navigation.md
+21-23Lines changed: 21 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ In a web browser, you can link to different pages using an anchor (`<a>`) tag. W
8
8
9
9
React Navigation's stack navigator provides a way for your app to transition between screens and manage navigation history. If your app uses only one stack navigator then it is conceptually similar to how a web browser handles navigation state - your app pushes and pops items from the navigation stack as users interact with it, and this results in the user seeing different screens. A key difference between how this works in a web browser and in React Navigation is that React Navigation's stack navigator provides the gestures and animations that you would expect on Android and iOS when navigating between routes in the stack.
10
10
11
-
All we need to get started using React Navigation is a function called`createStackNavigator`.
11
+
Lets start by demonstrating the most common navigator,`createStackNavigator`.
12
12
13
13
## Creating a stack navigator
14
14
@@ -17,47 +17,45 @@ All we need to get started using React Navigation is a function called `createSt
<ahref="https://snack.expo.io/@react-navigation/hello-world-v2"target="blank"class="run-code-button">→ Run this code</a>
43
+
<ahref="https://snack.expo.io/@react-navigation/hello-world-v2"target="blank"class="run-code-button">→ Run this code</a>
42
44
43
45
If you run this code, you will see a screen with an empty navigation bar and a grey content area containing your `HomeScreen` component. The styles you see for the navigation bar and the content area are the default configuration for a stack navigator, we'll learn how to configure those later.
44
46
45
47
> The casing of the route name doesn't matter -- you can use lowercase `home` or capitalized `Home`, it's up to you. We prefer capitalizing our route names.
46
48
47
49
> The only required configuration for a route is the `screen` component. You can read more about the other options available in the [StackNavigator reference](stack-navigator.html).
48
50
49
-
In React Native, the component exported from `App.js` is the entry point (or root component) for your app -- it is the component from which every other component descends. It's often useful to have more control over the component at the root of your app than you would get from exporting the result of `createStackNavigator`, so let's export a component that just renders our `RootStack` stack navigator.
51
+
In React Native, the component exported from `App.js` is the entry point (or root component) for your app -- it is the component from which every other component descends. It's often useful to have more control over the component at the root of your app than you would get from exporting the result of `createAppContainer`, so let's export a component that just renders our `AppNavigator` stack navigator.
@@ -92,10 +90,10 @@ class DetailsScreen extends React.Component {
92
90
constRootStack=createStackNavigator(
93
91
{
94
92
Home: HomeScreen,
95
-
Details: DetailsScreen,
93
+
Details: DetailsScreen
96
94
},
97
95
{
98
-
initialRouteName:'Home',
96
+
initialRouteName:"Home"
99
97
}
100
98
);
101
99
@@ -106,8 +104,8 @@ Now our stack has two _routes_, a `Home` route and a `Details` route. The `Home`
106
104
107
105
## Summary
108
106
109
-
* React Native doesn't have a built-in API for navigation like a web browser does. React Navigation provides this for you, along with the iOS and Android gestures and animations to transition between screens.
110
-
*`createStackNavigator` is a function that takes a route configuration object and an options object and returns a React component.
111
-
* The keys in the route configuration object are the route names and the values are the configuration for that route. The only required property on the configuration is the `screen` (the component to use for the route).
112
-
* To specify what the initial route in a stack is, provide an `initialRouteName` on the stack options object.
113
-
*[Full source of what we have built so far](https://snack.expo.io/@react-navigation/hello-react-navigation-v2).
107
+
- React Native doesn't have a built-in API for navigation like a web browser does. React Navigation provides this for you, along with the iOS and Android gestures and animations to transition between screens.
108
+
-`createStackNavigator` is a function that takes a route configuration object and an options object and returns a React component.
109
+
- The keys in the route configuration object are the route names and the values are the configuration for that route. The only required property on the configuration is the `screen` (the component to use for the route).
110
+
- To specify what the initial route in a stack is, provide an `initialRouteName` on the stack options object.
111
+
-[Full source of what we have built so far](https://snack.expo.io/@react-navigation/hello-react-navigation-v2).
We ship a utility out of the box which automatically sets up an `<a>` tag for you with the correct `href`.
25
+
26
+
This is necessary to properly support server rendering, critical for accessibility, and nice to provide a good user experience when the browser displays what URL the link will go to.
27
+
28
+
When the app is running, the default browser behavior will be blocked and a navigation action will be dispatched instead.
For a full example, [see a full server+client React web app here](https://github.com/react-navigation/web-server-example)
72
+
73
+
## Custom navigators for the web
74
+
75
+
The built-in navigator components such as Stack are often not well suited for web sites, so you may want to create custom navigators yourself.
76
+
77
+
Your view can use `props.descriptors` to see the current set of screens, get their navigation object, and see the current navigation options. You should use `SceneView` to present your child screen components.
78
+
79
+
See ["Custom Navigators"](custom-navigators.html) for more details.
80
+
81
+
For an example of this, see how the custom `SidebarView` and `AppView` are used from [`App.js` in the web server example](https://github.com/react-navigation/web-server-example/blob/master/src/App.js).
0 commit comments