javascript - 如何有条件地更改同一导航器中不同反应本机屏幕的 screenOptions?
问题描述
我有一个带 2 个屏幕的导航器。在其中一个屏幕中,我想显示headerRight
组件,而在另一个屏幕中,我不想显示headerRight
组件。
我的导航如下所示:
<NavigationContainer>
<Stack.Navigator screenOptions={{
headerShown: true,
headerRight: () => <Switch /> // conitionally change this
}}>
<Stack.Screen name="Vocabulary" component={bottomNavigator} />
<Stack.Screen name="Definition" component={Definition} />
</Stack.Navigator>
</NavigationContainer>
- 我是否
headerRight
根据可见的屏幕有条件地渲染? - 我有多个导航器吗?
- 我是否在呈现的组件(即
Definition
)中配置它?
解决方案
试试这个方法
componentDidMount() {
this.props.navigation.setOptions({
headerRight: <Switch />
});
}
推荐阅读
- tableau-api - 表格中的计算字段取决于列中的值
- emacs - 从组织模式表创建蜘蛛图
- javascript - 基于数量的 Woocommerce 变化价格产品总数
- json - 如何处理通过 JSON 传递的映射有意的 NULL 值?
- methods - 如何判断一个类方法是否存在
- node.js - sendSignedTransaction:Quorum 上的无效发件人错误
- mapstruct - 将 com.vividsolutions.jts.geom.Point 转换为 Dto
- c# - 将 AutoFixture 与 Moq 一起使用?
- java - Android 过渡动画 onBackPressed() 图像消失(释放缓冲区失败)
- vue.js - Vue.js;无限循环,在while循环中观察