Skip to content

Commit cfe11b1

Browse files
docs: use native-stack in navigating
1 parent 7d4f9e0 commit cfe11b1

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

static/examples/6.x/go-back.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 { Button, 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({ navigation }) {
77
return (
@@ -29,7 +29,7 @@ function DetailsScreen({ navigation }) {
2929
);
3030
}
3131

32-
const Stack = createStackNavigator();
32+
const Stack = createNativeStackNavigator();
3333

3434
function App() {
3535
return (

static/examples/6.x/multiple-navigate.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 { Button, 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({ navigation }) {
77
return (
@@ -27,7 +27,7 @@ function DetailsScreen({ navigation }) {
2727
);
2828
}
2929

30-
const Stack = createStackNavigator();
30+
const Stack = createNativeStackNavigator();
3131

3232
function App() {
3333
return (

static/examples/6.x/multiple-push.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 { Button, 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({ navigation }) {
77
return (
@@ -27,7 +27,7 @@ function DetailsScreen({ navigation }) {
2727
);
2828
}
2929

30-
const Stack = createStackNavigator();
30+
const Stack = createNativeStackNavigator();
3131

3232
function App() {
3333
return (

static/examples/6.x/new-screen.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 { Button, 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({ navigation }) {
77
return (
@@ -23,7 +23,7 @@ function DetailsScreen() {
2323
);
2424
}
2525

26-
const Stack = createStackNavigator();
26+
const Stack = createNativeStackNavigator();
2727

2828
function App() {
2929
return (

static/examples/6.x/pop-to-top.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 { Button, 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({ navigation }) {
77
return (
@@ -33,7 +33,7 @@ function DetailsScreen({ navigation }) {
3333
);
3434
}
3535

36-
const Stack = createStackNavigator();
36+
const Stack = createNativeStackNavigator();
3737

3838
function App() {
3939
return (

versioned_docs/version-6.x/navigating.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Moving between screens
44
sidebar_label: Moving between screens
55
---
66

7-
In the previous section, ["Hello React Navigation"](hello-react-navigation.md), we defined a stack navigator with two routes (`Home` and `Details`), but we didn't learn how to let a user navigate from `Home` to `Details` (although we did learn how to change the _initial_ route in our code, but forcing our users to clone our repository and change the route in our code in order to see another screen is arguably among the worst user experiences one could imagine).
7+
In the previous section, ["Hello React Navigation"](hello-react-navigation.md), we defined a native stack navigator with two routes (`Home` and `Details`), but we didn't learn how to let a user navigate from `Home` to `Details` (although we did learn how to change the _initial_ route in our code, but forcing our users to clone our repository and change the route in our code in order to see another screen is arguably among the worst user experiences one could imagine).
88

99
If this was a web browser, we'd be able to write something like this:
1010

@@ -34,7 +34,7 @@ We'll do something similar to the latter, but rather than using a `window.locati
3434
import * as React from 'react';
3535
import { Button, 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({ navigation }) {
4040
return (
@@ -53,7 +53,7 @@ function HomeScreen({ navigation }) {
5353

5454
Let's break this down:
5555

56-
- `navigation` - the `navigation` prop is passed in to every **screen component** ([definition](glossary-of-terms.md#screen-component)) in stack navigator (more about this later in ["The navigation prop in depth"](navigation-prop.md)).
56+
- `navigation` - the `navigation` prop is passed in to every **screen component** ([definition](glossary-of-terms.md#screen-component)) in the native stack navigator (more about this later in ["The navigation prop in depth"](navigation-prop.md)).
5757
- `navigate('Details')` - we call the `navigate` function (on the `navigation` prop — naming is hard!) with the name of the route that we'd like to move the user to.
5858

5959
> If we call `navigation.navigate` with a route name that we haven't defined in a navigator, it'll print an error in development builds and nothing will happen in production builds. Said another way, we can only navigate to routes that have been defined on our navigator — we cannot navigate to an arbitrary component.
@@ -101,7 +101,7 @@ Each time you call `push` we add a new route to the navigation stack. When you c
101101

102102
## Going back
103103

104-
The header provided by stack navigator will automatically include a back button when it is possible to go back from the active screen (if there is only one screen in the navigation stack, there is nothing that you can go back to, and so there is no back button).
104+
The header provided by the native stack navigator will automatically include a back button when it is possible to go back from the active screen (if there is only one screen in the navigation stack, there is nothing that you can go back to, and so there is no back button).
105105

106106
Sometimes you'll want to be able to programmatically trigger this behavior, and for that you can use `navigation.goBack();`.
107107

@@ -151,7 +151,7 @@ function DetailsScreen({ navigation }) {
151151

152152
## Summary
153153

154-
- `navigation.navigate('RouteName')` pushes a new route to the stack navigator if it's not already in the stack, otherwise it jumps to that screen.
154+
- `navigation.navigate('RouteName')` pushes a new route to the native stack navigator if it's not already in the stack, otherwise it jumps to that screen.
155155
- We can call `navigation.push('RouteName')` as many times as we like and it will continue pushing routes.
156156
- The header bar will automatically show a back button, but you can programmatically go back by calling `navigation.goBack()`. On Android, the hardware back button just works as expected.
157157
- You can go back to an existing screen in the stack with `navigation.navigate('RouteName')`, and you can go back to the first screen in the stack with `navigation.popToTop()`.

0 commit comments

Comments
 (0)