在React-Navigation V5/V6的屏幕外获取Navigation.State
我正在尝试将一个反应的V4应用程序升级到V5/V6。在v4中,createAppContainer
被像这样:
const AppContainer = createAppContainer(AppNavigator);
appnavigator
将接收navigation
prop,可以使用:
type AppNavigatorProps = {
navigation: Navigation;
};
class AppNavigator extends Component<AppNavigatorProps> {
isSplashScreen = (): boolean => {
const { navigation } = this.props;
return navigation.state.index === RouteIndexes.SplashScreen;
};
render(): ReactNode {
// styling set-up here
return (
<>
<SafeAreaView style={topStyle} />
<SafeAreaView style={bottomStyle}>
<StatusBar backgroundColor={barColor} />
<ErrorBoundary
navigation={navigation}>
<RootContainerStackNavigator navigation={navigation} />
</ErrorBoundary>
</SafeAreaView>
</>
);
}
}
我无法找到一种方法再在此位置中获取该navigation.state
。我有appnavigator
navigationContainer
而不是createAppContainer
so:
<NavigationContainer>
<AppNavigator />
</NavigationContainer>
I'm trying to upgrade a react-native v4 app to v5/v6. In v4, createAppContainer
was used like so:
const AppContainer = createAppContainer(AppNavigator);
and AppNavigator
would receive a Navigation
prop that could be used like:
type AppNavigatorProps = {
navigation: Navigation;
};
class AppNavigator extends Component<AppNavigatorProps> {
isSplashScreen = (): boolean => {
const { navigation } = this.props;
return navigation.state.index === RouteIndexes.SplashScreen;
};
render(): ReactNode {
// styling set-up here
return (
<>
<SafeAreaView style={topStyle} />
<SafeAreaView style={bottomStyle}>
<StatusBar backgroundColor={barColor} />
<ErrorBoundary
navigation={navigation}>
<RootContainerStackNavigator navigation={navigation} />
</ErrorBoundary>
</SafeAreaView>
</>
);
}
}
I cannot figure out a way to get that navigation.state
in this location anymore. I have the AppNavigator
wrapped in NavigationContainer
instead of the createAppContainer
like so:
<NavigationContainer>
<AppNavigator />
</NavigationContainer>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论