【发布时间】:2020-06-29 18:00:26
【问题描述】:
从代码中可以看出,tabPress 没有被调用,是我做错了还是我遗漏了什么,不幸的是我没有找到任何反应导航版本 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>
【问题讨论】:
-
tabPress 是一个事件。您必须在组件内部使用它。 reactnavigation.org/docs/bottom-tab-navigator#events
标签: react-native react-navigation-v5 react-navigation-bottom-tab