Skip to content

Commit 7d4f9e0

Browse files
docs: use native-stack in hello-react-navigation
1 parent 7c3e33f commit 7d4f9e0

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

static/examples/6.x/hello-react-navigation-full.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { View, Text } from 'react-native';
33
import { NavigationContainer } from '@react-navigation/native';
4-
import { createStackNavigator } from '@react-navigation/stack';
4+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
55

66
function HomeScreen() {
77
return (
@@ -19,7 +19,7 @@ function DetailsScreen() {
1919
);
2020
}
2121

22-
const Stack = createStackNavigator();
22+
const Stack = createNativeStackNavigator();
2323

2424
function App() {
2525
return (

static/examples/6.x/hello-react-navigation-with-options.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { View, Text } from 'react-native';
33
import { NavigationContainer } from '@react-navigation/native';
4-
import { createStackNavigator } from '@react-navigation/stack';
4+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
55

66
function HomeScreen() {
77
return (
@@ -11,7 +11,7 @@ function HomeScreen() {
1111
);
1212
}
1313

14-
const Stack = createStackNavigator();
14+
const Stack = createNativeStackNavigator();
1515

1616
function App() {
1717
return (

static/examples/6.x/hello-react-navigation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { View, Text } from 'react-native';
33
import { NavigationContainer } from '@react-navigation/native';
4-
import { createStackNavigator } from '@react-navigation/stack';
4+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
55

66
function HomeScreen() {
77
return (
@@ -11,7 +11,7 @@ function HomeScreen() {
1111
);
1212
}
1313

14-
const Stack = createStackNavigator();
14+
const Stack = createNativeStackNavigator();
1515

1616
function App() {
1717
return (

versioned_docs/version-6.x/hello-react-navigation.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ sidebar_label: Hello React Navigation
66

77
In a web browser, you can link to different pages using an anchor (`<a>`) tag. When the user clicks on a link, the URL is pushed to the browser history stack. When the user presses the back button, the browser pops the item from the top of the history stack, so the active page is now the previously visited page. React Native doesn't have a built-in idea of a global history stack like a web browser does -- this is where React Navigation enters the story.
88

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.
9+
React Navigation's native 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 native stack navigator provides the gestures and animations that you would expect on Android and iOS when navigating between routes in the stack.
1010

11-
Lets start by demonstrating the most common navigator, `createStackNavigator`.
11+
Let's start by demonstrating the most common navigator, `createNativeStackNavigator`.
1212

13-
## Installing the stack navigator library
13+
## Installing the native stack navigator library
1414

15-
The libraries we've installed so far are the building blocks and shared foundations for navigators, and each navigator in React Navigation lives in its own library. To use the stack navigator, we need to install [`@react-navigation/stack`](https://github.com/react-navigation/react-navigation/tree/main/packages/stack) :
15+
The libraries we've installed so far are the building blocks and shared foundations for navigators, and each navigator in React Navigation lives in its own library. To use the native stack navigator, we need to install [`@react-navigation/native-stack`](https://github.com/react-navigation/react-navigation/tree/main/packages/native-stack) :
1616

1717
```bash npm2yarn
18-
npm install @react-navigation/stack@next @react-native-masked-view/masked-view
18+
npm install @react-navigation/native-stack@next react-native-screens
1919
```
2020

21-
> 💡 `@react-navigation/stack` depends on `@react-native-masked-view/masked-view` and the other libraries that we installed in [Getting started](getting-started.md). If you haven't installed those yet, head over to that page and follow the installation instructions.
21+
> 💡 `@react-navigation/native-stack` depends on `react-native-screens` and the other libraries that we installed in [Getting started](getting-started.md). If you haven't installed those yet, head over to that page and follow the installation instructions.
2222
23-
### Creating a stack navigator
23+
### Creating a native stack navigator
2424

25-
`createStackNavigator` is a function that returns an object containing 2 properties: `Screen` and `Navigator`. Both of them are React components used for configuring the navigator. The `Navigator` should contain `Screen` elements as its children to define the configuration for routes.
25+
`createNativeStackNavigator` is a function that returns an object containing 2 properties: `Screen` and `Navigator`. Both of them are React components used for configuring the navigator. The `Navigator` should contain `Screen` elements as its children to define the configuration for routes.
2626

2727
`NavigationContainer` is a component which manages our navigation tree and contains the [navigation state](navigation-state.md). This component must wrap all navigators structure. Usually, we'd render this component at the root of our app, which is usually the component exported from `App.js`.
2828

@@ -34,7 +34,7 @@ npm install @react-navigation/stack@next @react-native-masked-view/masked-view
3434
import * as React from 'react';
3535
import { View, Text } from 'react-native';
3636
import { NavigationContainer } from '@react-navigation/native';
37-
import { createStackNavigator } from '@react-navigation/stack';
37+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
3838

3939
function HomeScreen() {
4040
return (
@@ -44,7 +44,7 @@ function HomeScreen() {
4444
);
4545
}
4646

47-
const Stack = createStackNavigator();
47+
const Stack = createNativeStackNavigator();
4848

4949
function App() {
5050
return (
@@ -65,13 +65,13 @@ If you run this code, you will see a screen with an empty navigation bar and a g
6565

6666
> 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.
6767
68-
> The only required configuration for a screen is the `name` and `component` props. You can read more about the other options available in the [stack navigator reference](stack-navigator.md).
68+
> The only required configuration for a screen is the `name` and `component` props. You can read more about the other options available in the [native stack navigator reference](native-stack-navigator.md).
6969
7070
### Configuring the navigator
7171

7272
All of the route configuration is specified as props to our navigator. We haven't passed any props to our navigator, so it just uses the default configuration.
7373

74-
Let's add a second screen to our stack navigator and configure the `Home` screen to render first:
74+
Let's add a second screen to our native stack navigator and configure the `Home` screen to render first:
7575

7676
<samp id="hello-react-navigation-full" />
7777

@@ -84,7 +84,7 @@ function DetailsScreen() {
8484
);
8585
}
8686

87-
const Stack = createStackNavigator();
87+
const Stack = createNativeStackNavigator();
8888

8989
function App() {
9090
return (

0 commit comments

Comments
 (0)