reactjs - React Navigation 5 使用类组件设置导航选项
问题描述
我最近将项目中的 react 导航版本升级到了版本 5,但仍然使用类组件,并且希望保留类组件。不幸的是,我不能再使用 navigationOptions 为我的班级设置导航属性。我想获得有关如何在类组件中为反应导航 5 设置 navigationOptions 的帮助。
const AppStack = createStackNavigator();
const app = () => {
return (
<NavigationContainer>
<AppStack.Navigator initialRouteName="SplashScreen">
<AppStack.Screen name="SplashScreen" component={SplashScreen} options={{ headerShown: false, headerBackTitle: null }}/>
<AppStack.Screen name="Login" component={Login} options={{ headerShown: true, headerBackTitle: null }}/>
</AppStack.Navigator>
</NavigationContainer>
);
};
export default app;
class Login extends React.Component {
static navigationOptions = ({ navigation }) => {
const params = navigation.state.params || {};
return {
headerTitle: params.headerTitle,
headerRight: params.headerRight,
headerLeft: params.headerLeft,
headerStyle: params.headerStyle,
headerTitleStyle: styles.headerTitle,
};
};
}
解决方案
推荐阅读
- c# - 如何将值传递给 MVC 模型
- amazon-web-services - 使用 boto3 或 CLI 推迟 Amazon Redshift 维护时段
- hibernate - Hibernate 如何在使用 Auto DDL 时确定表列的默认长度和数据类型
- reporting-services - 如何从 SSRS 数据集行中获取条件为真的值
- javascript - 我可以在没有 Window.print 的情况下用 javascript 将 HTML 保存为 PDF 吗?
- python - 这个正则化代码如何影响损失?
- c# - 在实体框架中添加 AsNoTracking 会影响计数吗?
- java - 如何在Java中使用没有初始化的数组
- django - KeyError: 'collectstatic' 将 Django 应用程序部署到 pythonanywhere 时
- boto3 - Boto3 显示了这么多 ec2 快照,没有一个快照不属于我