typescript - React Navigation 4.x tabBarOptions 不工作打字稿
问题描述
请不要推荐我使用 React Navigation 5.x,无论如何,我使用 4.x 因为 switchNavigator。在我将项目迁移到打字稿后,我遇到了 React Navigation 4.x 的问题,这是出现错误的代码的一部分。
const MainTabs = createBottomTabNavigator({
Home: {
screen: HomeStack,
navigationOptions: {
tabBarIcon: ({focused}) => {
const image = focused ? Images.inicio_onFocus : Images.inicio_onBlur;
return <Image source={image} />;
},
tabBarOptions: {
activeTintColor: colors.active,
inactiveTintColor: colors.background,
style: {
marginTop: 10,
height: 65,
backgroundColor: colors.title,
shadowColor: colors.inactive,
borderTopColor: 'transparent',
borderTopWidth: 0,
elevation: 5,
shadowOpacity: 5,
shadowRadius: 10,
},
},
tabBarLabel: 'INICIO',
},
},
Vacations: {
screen: VacationsStack,
navigationOptions: {
tabBarIcon: ({focused}) => {
const image = focused ? Images.vacaciones_onFocus : Images.vacaciones_onBlur;
return <Image source={image} />;
},
/*
tabBarOptions: {
activeTintColor: colors.active,
inactiveTintColor: colors.background,
style: {
marginTop: 10,
height: 65,
backgroundColor: colors.title,
shadowColor: colors.inactive,
borderTopColor: 'transparent',
borderTopWidth: 0,
elevation: 5,
shadowOpacity: 5,
shadowRadius: 10,
},
},
*/
tabBarLabel: 'VACACIONES',
},
},
HoursReport: {
screen: HoursReportStack,
navigationOptions: {
tabBarIcon: ({focused}) => {
const image = focused ? Images.imputar_onFocus: Images.imputar_onBlur;
return <Image source={image} />;
},
/*
tabBarOptions: {
activeTintColor: colors.active,
inactiveTintColor: colors.background,
style: {
marginTop: 10,
height: 65,
backgroundColor: colors.title,
shadowColor: colors.inactive,
borderTopColor: 'transparent',
borderTopWidth: 0,
elevation: 5,
shadowOpacity: 5,
shadowRadius: 10,
},
},
*/
tabBarLabel: 'IMPUTAR',
},
},
ExpenseReport: {
screen: ExpenseReportStack,
navigationOptions: {
tabBarIcon: ({focused}) => {
const image = focused ? Images.rendir_onFocus : Images.rendir_onBlur;
return <Image source={image} />;
},
/*
tabBarOptions: {
activeTintColor: colors.active,
inactiveTintColor: colors.background,
style: {
marginTop: 10,
height: 65,
backgroundColor: colors.title,
shadowColor: colors.inactive,
borderTopColor: 'transparent',
borderTopWidth: 0,
elevation: 5,
shadowOpacity: 5,
shadowRadius: 10,
},
},
*/
tabBarLabel: 'RENDIR',
},
},
});
包含 tabBarOptions 的代码的每个部分都出现此错误。
The expected type comes from property 'navigationOptions' which is declared here on type 'NavigationRouteConfig<NavigationBottomTabOptions, NavigationTabProp<NavigationRoute<NavigationParams>, any>, unknown>'
解决方案
似乎tabBarOptions
是在错误的地方,也许这种方式对你有用:
tabBarOptions
不是 的属性navigationOptions
。createBottomTabNavigator
例如,它应该放在第二个参数中initialRouteName
。
const MainTabs = createBottomTabNavigator({
Home: {
screen: HomeStack,
navigationOptions: {
tabBarIcon: ({focused}) => {
const image = focused ? Images.inicio_onFocus : Images.inicio_onBlur;
return <Image source={image} />;
},
tabBarLabel: 'INICIO',
},
},
Vacations: {
screen: VacationsStack,
navigationOptions: {
tabBarIcon: ({focused}) => {
const image = focused ? Images.vacaciones_onFocus : Images.vacaciones_onBlur;
return <Image source={image} />;
},
tabBarLabel: 'VACACIONES',
},
},
HoursReport: {
screen: HoursReportStack,
navigationOptions: {
tabBarIcon: ({focused}) => {
const image = focused ? Images.imputar_onFocus: Images.imputar_onBlur;
return <Image source={image} />;
},
tabBarLabel: 'IMPUTAR',
},
},
ExpenseReport: {
screen: ExpenseReportStack,
navigationOptions: {
tabBarIcon: ({focused}) => {
const image = focused ? Images.rendir_onFocus : Images.rendir_onBlur;
return <Image source={image} />;
},
tabBarLabel: 'RENDIR',
},
},
}, {
tabBarOptions: {
activeTintColor: colors.active,
inactiveTintColor: colors.background,
style: {
marginTop: 10,
height: 65,
backgroundColor: colors.title,
shadowColor: colors.inactive,
borderTopColor: 'transparent',
borderTopWidth: 0,
elevation: 5,
shadowOpacity: 5,
shadowRadius: 10,
}
}
}});
推荐阅读
- python - 以可编辑模式安装 Pip 始终卸载现有发行版
- go - 如何在 Golang 中将 Math.Pow 与整数一起使用
- python - 如何在python中使用绝对值进行整数优化?
- node.js - PostgreSQL - Continuous integration
- visual-studio-code - Visual Studio Code 未在 WSL 2 上运行/工作
- python - InvalidArgumentError:无法挤压昏暗 [2],预期维度为 1,得到 10
- sql - 创建一个数据集,该数据集在任何记录存在时都生成 0/1 标志
- vb.net - Web Server Controls Code Behind 看不到我的数据集配置
- html - 当“恢复窗口”到原始大小时跳转到 html 锚点,没有 JS?
- sql - 在sql查询中排除日期范围