Skip to content

Commit 3a1ca57

Browse files
docs: use native-stack in navigation-lifecycle
1 parent 088736b commit 3a1ca57

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

static/examples/6.x/focus-and-blur.js

Lines changed: 3 additions & 3 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
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
66

77
function SettingsScreen({ navigation }) {
@@ -62,8 +62,8 @@ function DetailsScreen({ navigation }) {
6262
);
6363
}
6464
const Tab = createBottomTabNavigator();
65-
const SettingsStack = createStackNavigator();
66-
const HomeStack = createStackNavigator();
65+
const SettingsStack = createNativeStackNavigator();
66+
const HomeStack = createNativeStackNavigator();
6767

6868
export default function App() {
6969
return (

static/examples/6.x/navigation-lifecycle.js

Lines changed: 3 additions & 3 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
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
66

77
function SettingsScreen({ navigation }) {
@@ -52,8 +52,8 @@ function DetailsScreen({ navigation }) {
5252
);
5353
}
5454
const Tab = createBottomTabNavigator();
55-
const SettingsStack = createStackNavigator();
56-
const HomeStack = createStackNavigator();
55+
const SettingsStack = createNativeStackNavigator();
56+
const HomeStack = createNativeStackNavigator();
5757

5858
export default function App() {
5959
return (

static/examples/6.x/use-focus-effect.js

Lines changed: 3 additions & 3 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, useFocusEffect } from '@react-navigation/native';
4-
import { createStackNavigator } from '@react-navigation/stack';
4+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
55
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
66

77
function SettingsScreen({ navigation }) {
@@ -64,8 +64,8 @@ function DetailsScreen({ navigation }) {
6464
);
6565
}
6666
const Tab = createBottomTabNavigator();
67-
const SettingsStack = createStackNavigator();
68-
const HomeStack = createStackNavigator();
67+
const SettingsStack = createNativeStackNavigator();
68+
const HomeStack = createNativeStackNavigator();
6969

7070
export default function App() {
7171
return (

versioned_docs/version-6.x/navigation-lifecycle.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ title: Navigation lifecycle
44
sidebar_label: Navigation lifecycle
55
---
66

7-
In a previous section, we worked with a stack navigator that has two screens (`Home` and `Details`) and learned how to use `navigation.navigate('RouteName')` to navigate between the routes.
7+
In a previous section, we worked with a native stack navigator that has two screens (`Home` and `Details`) and learned how to use `navigation.navigate('RouteName')` to navigate between the routes.
88

99
An important question in this context is: what happens with `Home` when we navigate away from it, or when we come back to it? How does a route find out that a user is leaving it or coming back to it?
1010

1111
If you are coming to react-navigation from a web background, you may assume that when user navigates from route `A` to route `B`, `A` will unmount (its `componentWillUnmount` is called) and `A` will mount again when user comes back to it. While these React lifecycle methods are still valid and are used in react-navigation, their usage differs from the web. This is driven by more complex needs of mobile navigation.
1212

1313
## Example scenario
1414

15-
Consider a stack navigator with screens A and B. After navigating to A, its `componentDidMount` is called. When pushing B, its `componentDidMount` is also called, but A remains mounted on the stack and its `componentWillUnmount` is therefore not called.
15+
Consider a native stack navigator with screens A and B. After navigating to A, its `componentDidMount` is called. When pushing B, its `componentDidMount` is also called, but A remains mounted on the stack and its `componentWillUnmount` is therefore not called.
1616

1717
When going back from B to A, `componentWillUnmount` of B is called, but `componentDidMount` of A is not because A remained mounted the whole time.
1818

19-
Similar results can be observed (in combination) with other navigators as well. Consider a tab navigator with two tabs, where each tab is a stack navigator:
19+
Similar results can be observed (in combination) with other navigators as well. Consider a tab navigator with two tabs, where each tab is a native stack navigator:
2020

2121
<samp id="navigation-lifecycle" />
2222

0 commit comments

Comments
 (0)