react-native - 在 React Navigation MaterialTopTabNavigator (v5) 中动态更新 swipeEnabled 属性
问题描述
我目前正在努力动态更新@react-navigation/material-top-tabs
v5 中的 swipeEnabled 道具。我尝试过的是拥有一个全局状态,它指示标签是否应该是可滑动的。该isSwipeable
值正在从 TabNavigator 的屏幕中更新。在这种情况下,当按下 LineChart 时。我的代码:
const { isSwipeable } = useContext(GlobalContext)
return (
<TopTab.Navigator swipeEnabled={isSwipeable} tabBar={(props) => <TabBar {...props} />}>
<TopTab.Screen
name="Screen1"
component={Screen1Component}
options={{
tabBarLabel: 'Screen1',
tabBarIcon: () => null
}}
/>
<TopTab.Screen
name="Screen2"
component={Screen2Component}
options={{
tabBarLabel: 'Screen2',
tabBarIcon: () => null
}}
/>
</TopTab.Navigator>
)
但这不会动态更新swipeEnabled
Tab Navigator 的 prop。
我也尝试过在标签屏幕中使用类似的东西:
React.useLayoutEffect(() => {
navigation.setOptions({})
}, [navigation])
但是在这里setOptions
我只能更改 tabLabel、tabIcon 等,这对我没有多大帮助。
解决方案
推荐阅读
- python-2.7 - 输出类型中 beam.ParDo 和 beam.Map 的区别?
- java - 如何在 Java 中使用 Apache Beam parDo 函数读取 JSON 文件
- c# - 验证字符串的正则表达式由 3-4 个字符后跟分号组成
- java - Spring-batch 作业在 FAILED 和 COMPLETED 之间随机抛出不同的退出状态
- python-3.x - 使用 Python Pandas 合并距离矩阵结果和原始索引
- node.js - 使用 MQTT.js 和 Mosquitto 发布和订阅 MQTT 主题
- c# - 在 tt 文件中检查实体类型
- odoo - Adding Field in Qweb table of odoo 8
- php - How to run DLL file in PHP and Laravel?
- android - android中的谷歌登录获取无效的SHA-1证书指纹错误