Skip to content

Commit 4d83804

Browse files
committed
Add static config to navigation lifecycle
1 parent a53cbaa commit 4d83804

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ title: Navigation lifecycle
44
sidebar_label: Navigation lifecycle
55
---
66

7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
710
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.
811

912
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?
@@ -18,6 +21,36 @@ When going back from B to A, `componentWillUnmount` of B is called, but `compone
1821

1922
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:
2023

24+
<Tabs groupId="config" queryString="config">
25+
<TabItem value="static" label="Static" default>
26+
27+
```js
28+
const SettingsStack = createStackNavigator({
29+
Settings: SettingsScreen,
30+
Profile: ProfileScreen,
31+
});
32+
33+
const HomeStack = createStackNavigator({
34+
Home: HomeScreen,
35+
Details: DetailsScreen,
36+
});
37+
38+
const MyTabs = createBottomTabNavigator({
39+
First: SettingsStack,
40+
Second: HomeStack,
41+
});
42+
43+
44+
const Navigation = createStaticNavigation(MyTabs);
45+
46+
function App() {
47+
return <Navigation />;
48+
}
49+
```
50+
51+
</TabItem>
52+
<TabItem value="dynamic" label="Dynamic">
53+
2154
<samp id="navigation-lifecycle" />
2255

2356
```jsx
@@ -50,6 +83,9 @@ function App() {
5083
}
5184
```
5285

86+
</TabItem>
87+
</Tabs>
88+
5389
We start on the `HomeScreen` and navigate to `DetailsScreen`. Then we use the tab bar to switch to the `SettingsScreen` and navigate to `ProfileScreen`. After this sequence of operations is done, all 4 of the screens are mounted! If you use the tab bar to switch back to the `HomeStack`, you'll notice you'll be presented with the `DetailsScreen` - the navigation state of the `HomeStack` has been preserved!
5490

5591
## React Navigation lifecycle events

versioned_docs/version-7.x/nesting-navigators.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,12 @@ const RootStack = createStackNavigator({
401401
EditPost,
402402
},
403403
});
404+
405+
const Navigation = createStaticNavigation(RootStack);
406+
407+
function App() {
408+
return <Navigation />;
409+
}
404410
```
405411

406412
</TabItem>

0 commit comments

Comments
 (0)