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
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/navigation-lifecycle.md
+36Lines changed: 36 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,9 @@ title: Navigation lifecycle
4
4
sidebar_label: Navigation lifecycle
5
5
---
6
6
7
+
import Tabs from '@theme/Tabs';
8
+
import TabItem from '@theme/TabItem';
9
+
7
10
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.
8
11
9
12
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
18
21
19
22
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:
20
23
24
+
<TabsgroupId="config"queryString="config">
25
+
<TabItemvalue="static"label="Static"default>
26
+
27
+
```js
28
+
constSettingsStack=createStackNavigator({
29
+
Settings: SettingsScreen,
30
+
Profile: ProfileScreen,
31
+
});
32
+
33
+
constHomeStack=createStackNavigator({
34
+
Home: HomeScreen,
35
+
Details: DetailsScreen,
36
+
});
37
+
38
+
constMyTabs=createBottomTabNavigator({
39
+
First: SettingsStack,
40
+
Second: HomeStack,
41
+
});
42
+
43
+
44
+
constNavigation=createStaticNavigation(MyTabs);
45
+
46
+
functionApp() {
47
+
return<Navigation />;
48
+
}
49
+
```
50
+
51
+
</TabItem>
52
+
<TabItemvalue="dynamic"label="Dynamic">
53
+
21
54
<sampid="navigation-lifecycle" />
22
55
23
56
```jsx
@@ -50,6 +83,9 @@ function App() {
50
83
}
51
84
```
52
85
86
+
</TabItem>
87
+
</Tabs>
88
+
53
89
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!
0 commit comments