选项卡不活动时,我想隐藏TabBar标签。
使用tabBarOptions中的showLabel
只能完全禁用它们。
提前致谢。
最佳答案
嘿,德鲁(Hey Drew)感谢您的想法,我自己无法解决,但我认为您对于问题中的功能没有很多多余的代码。这是我对此的看法,而且效果也很好。
export const BottomTabNavigator = createBottomTabNavigator(
{
News: {
screen: NewsNavigator,
navigationOptions: {
tabBarIcon: ({ focused }: any) =>
focused ? <NewsIconActive /> : <NewsIcon />
}
},
Rewards: {
screen: RewardsNavigator,
navigationOptions: {
tabBarIcon: ({ focused }: any) =>
focused ? <RewardsIconActive /> : <RewardsIcon />
}
},
Home: {
screen: HomeNavigator,
navigationOptions: {
tabBarIcon: ({ focused }: any) =>
focused ? <HomeIconActive /> : <HomeIcon />
}
},
Leaderboard: {
screen: LeaderboardNavigator,
navigationOptions: {
tabBarIcon: ({ focused }: any) =>
focused ? <LeaderboardIconActive /> : <LeaderboardIcon />
}
},
Profile: {
screen: ProfileNavigator,
navigationOptions: {
tabBarIcon: ({ focused }: any) =>
focused ? <ProfileIconActive /> : <ProfileIcon />
}
}
},
{
initialRouteName: 'Profile'
},
navigationOptions: ({ navigation }) => ({
tabBarLabel: ({ focused }) => {
const { routeName } = navigation.state;
switch (routeName) {
case 'News':
return focused ? (
<Text>{routeName}</Text>
) : null;
break;
case 'Rewards':
return focused ? (
<Text>{routeName}</Text>
) : null;
break;
case 'Home':
return focused ? (
<Text>{routeName}</Text>
) : null;
break;
case 'Leaderboard':
return focused ? (
<Text >{routeName}</Text>
) : null;
break;
case 'Profile':
return focused ? (
<Text>{routeName}</Text>
) : null;
break;
default:
return null;
break;
}
}
})
}
);