反应原生导航 v5 选项卡按不工作 [英] React native navigation v5 tab press not working
本文介绍了反应原生导航 v5 选项卡按不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如代码所示,tabPress 没有被调用,是我做错了还是我遗漏了什么,不幸的是我没有找到任何 React 导航版本 5 的代码示例.
As seen on the code, tabPress is not called, am i doing it wrong or am i missing something, unfortunately i have not found any code samples for react navigation version 5.
<Tab.Navigator labeled={false} barStyle={{backgroundColor: '#ffffff', height: 55}} options={{
tabPress: ({navigation}) => {
console.log('nav tab press triggered')
}
}}>
<Tab.Screen name={`DeviceNavigatorTab`} component={DeviceNavigator} options={{
tabBarIcon: ({tintColor}) => <Image source={require('../../images/feather_home-menu.png')}
style={{width: 26, height: 26, tintColor}}/>,
tabPress: ({navigation}) => {
console.log('tab press triggered')
}
}} tabPress={() => { console.log('prop tab pressed') }}/>
<Tab.Screen name={`AlarmNavigatorTab`} component={AlarmNavigator} options={{
tabBarIcon: ({tintColor}) => <Image source={require('../../images/feather_alert-circle.png')}
style={{width: 26, height: 26, tintColor}}/>,
}}/>
<Tab.Screen name={`ProfileNavigatorTab`} component={ProfileNavigator} options={{
tabBarIcon: ({tintColor}) => <Image source={require('../../images/feather_user.png')}
style={{width: 26, height: 26, tintColor}}/>,
}} />
</Tab.Navigator>
推荐答案
我在文档中发现了一些我以前从未见过的新东西,这是向屏幕添加侦听器的方法,每次用户单击选项卡时,它都会在此选项卡内的第一个堆栈屏幕
I found something new in documentation, that i have not seen before, this is the way to add listener to screen, every time user clicks on tab, it goes to first stack screen inside this tab
https://reactnavigation.org/docs/navigation-事件/#listeners-prop-on-screen
<Tab.Screen
name="DeviceNavigatorTab"
component={DeviceNavigator}
listeners={({ navigation, route }) => ({
tabPress: e => {
if (route.state && route.state.routeNames.length > 0) {
navigation.navigate('Device')
}
},
})}
/>
这篇关于反应原生导航 v5 选项卡按不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文