尝试将旧的反应导航 1.x 更新到当前版本 5.x。navigation.state.params
我需要根据1.x 版本中使用的值显示不同的选项卡图标。该值是使用 navigation.dispatch(data) 在其中一个屏幕中设置的。
这是与导航 1.x 一起使用的简化代码:
import {TabBarBottom, TabNavigator} from 'react-navigation';
import {MyIcon, AnotherIcon} from './icons.js';
export default TabNavigator({
Home: {screen: HomeRouter},
Profile: {screen: ProfileRouter},
}, {
navigationOptions: ({navigation}) => ({
tabBarIcon: ({focused}) => {
const {routeName, params} = navigation.state;
...
if (params.data === 1) {
return <AnotherIcon />
}
...
return <MyIcon />;
},
}),
tabBarComponent: TabBarBottom,
tabBarPosition: 'bottom',
});
需要如何更改才能使用 React 导航 v.5.x?还是我能做的就是使用 React.Context?