react-native - React Native Navigation:仅显示焦点项目的选项卡标签
问题描述
我只是试图根据标签导航器的项目是否聚焦有条件地显示/隐藏标签。我可以像这样更改图标的色调:
tabBarIcon: ({ focused }) => {
const icon = <Image
style={{
width: 25,
height: 25,
tintColor: focused ? colors.primary : colors.inactive
}}
source={require('./assets/account.png');}
/> ;
return icon
但是尝试根据相同的道具有条件地更改 showLabel 布尔值是行不通的?
tabBarOptions={{
activeTintColor: colors.primary,
inactiveTintColor: colors.inactive,
showLabel: ({ focused }) => {
return focused ? true : false
},
标签栏上显示所有项目的标签。
任何/所有帮助表示赞赏!
解决方案
弄清楚了。
<Tab.Navigator
screenOptions={({ route }) => ({
tabBarLabel: ({ focused }) => {
return <Text style={{fontSize: 14, fontWeight: '600', color: colors.primary}}>{focused ? route.name : ""}</Text>
},
tabBarIcon: ({ focused }) => {
let iconSource;
if (route.name === 'Map') {
iconSource = require('./assets/public.png');
} else if (route.name === 'List') {
iconSource = require('./assets/numbered.png');
} else if (route.name === 'Log') {
iconSource = require('./assets/menu.png');
} else if (route.name === 'Talk') {
iconSource = require('./assets/chat.png');
} else if (route.name === 'Account') {
iconSource = require('./assets/account.png');
}
const icon = <Image
style={{
width: 25,
height: 25,
tintColor: focused ? colors.primary : colors.inactive,
marginTop: focused ? 5 : 15
}}
source={iconSource}
/> ;
return icon
},
})}
>
推荐阅读
- c# - 无法添加字典
列出 > - android - Android webview 与 Instagram 存在一些问题
- node.js - 尝试将动态数据从道具传递到从服务器加载的文本内部(使用 MERN 堆栈)
- javascript - 如何使用 setTimeout 在递归函数中延迟 for 循环?
- swift - 我可以从 dSYM 或 XCode DerivedData 中恢复已删除的 Swift 代码吗?
- spring - 使用 posgresql 在内存中实现 h2 兼容性的 Spring Boot 属性
- angular - 一次订阅即可订阅多个 observables
- database - 如何从用户 [UI] 获取 JDBC URL、USERNAME、PASSWORD 等数据库配置属性
- javascript - 这是处理空数组的最佳方法
- json-spec - 用于从 SPA Angular/REact 应用程序到后端的服务的规范是什么?