Skip to content

Commit 3a79b33

Browse files
committed
Fix persistence example for static config
1 parent 60212e4 commit 3a79b33

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

versioned_docs/version-7.x/state-persistence.md

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,27 @@ const SettingsStackScreen = createNativeStackNavigator({
7777
},
7878
});
7979

80+
const Tab = createBottomTabNavigator({
81+
screens: {
82+
Home: {
83+
screen: HomeStackScreen,
84+
options: {
85+
headerShown: false,
86+
tabBarLabel: 'Home!',
87+
},
88+
},
89+
Settings: {
90+
screen: SettingsStackScreen,
91+
options: {
92+
headerShown: false,
93+
tabBarLabel: 'Settings!',
94+
},
95+
},
96+
},
97+
});
98+
99+
const Navigation = createStaticNavigation(Tab);
100+
80101
// codeblock-focus-start
81102

82103
const PERSISTENCE_KEY = 'NAVIGATION_STATE_V1';
@@ -111,25 +132,6 @@ export default function App() {
111132
if (!isReady) {
112133
return null;
113134
}
114-
const Tab = createBottomTabNavigator({
115-
screens: {
116-
Home: {
117-
screen: HomeStackScreen,
118-
options: {
119-
headerShown: false,
120-
tabBarLabel: 'Home!',
121-
},
122-
},
123-
Settings: {
124-
screen: SettingsStackScreen,
125-
options: {
126-
headerShown: false,
127-
tabBarLabel: 'Settings!',
128-
},
129-
},
130-
},
131-
});
132-
const Navigation = createStaticNavigation(Tab);
133135

134136
return (
135137
<Navigation
@@ -207,6 +209,23 @@ function SettingsStackScreen() {
207209
);
208210
}
209211

212+
function RootTabs() {
213+
return (
214+
<Tab.Navigator screenOptions={{ headerShown: false }}>
215+
<Tab.Screen
216+
name="Home"
217+
component={HomeStackScreen}
218+
options={{ tabBarLabel: 'Home!' }}
219+
/>
220+
<Tab.Screen
221+
name="Settings"
222+
component={SettingsStackScreen}
223+
options={{ tabBarLabel: 'Settings!' }}
224+
/>
225+
</Tab.Navigator>
226+
);
227+
}
228+
210229
// codeblock-focus-start
211230

212231
const PERSISTENCE_KEY = 'NAVIGATION_STATE_V1';
@@ -252,18 +271,7 @@ export default function App() {
252271
AsyncStorage.setItem(PERSISTENCE_KEY, JSON.stringify(state))
253272
}
254273
>
255-
<Tab.Navigator screenOptions={{ headerShown: false }}>
256-
<Tab.Screen
257-
name="Home"
258-
component={HomeStackScreen}
259-
options={{ tabBarLabel: 'Home!' }}
260-
/>
261-
<Tab.Screen
262-
name="Settings"
263-
component={SettingsStackScreen}
264-
options={{ tabBarLabel: 'Settings!' }}
265-
/>
266-
</Tab.Navigator>
274+
<RootTabs />
267275
</NavigationContainer>
268276
);
269277
}

0 commit comments

Comments
 (0)