文档中有此example:
const AppNavigator = createStackNavigator({...});
const persistenceKey = "persistenceKey"
const persistNavigationState = async (navState) => {
try {
await AsyncStorage.setItem(persistenceKey, JSON.stringify(navState))
} catch(err) {
// handle the error according to your needs
}
}
const loadNavigationState = async () => {
const jsonString = await AsyncStorage.getItem(persistenceKey)
return JSON.parse(jsonString)
}
const App = () => <AppNavigator persistNavigationState={persistNavigationState} loadNavigationState={loadNavigationState} />;
现在,这很清楚。尚不清楚的是如何将其与createAppContainer
which requires that you pass an object结合使用:
const AppNavigator = createStackNavigator(...);
const AppContainer = createAppContainer(AppNavigator);
因此,如果我必须将persistNavigationState
和loadNavigationState
传递给<AppNavigator />
,但是我不能将<AppNavigator />
传递给createAppContainer
,则我看不到实现这一点是可能的。我在俯视什么?