I would like to hide the TabBar Label when the tab is not active.
With showLabel
from tabBarOptions I can only disable them completely.
Thanks in advance.
Hey Drew thanks for the idea, couldn't figure it out on my own, but I think you have a lot of extra code unnecessary for the functionality asked in the question. Here is my take on this, and this works just as well.
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;
}
}
})
}
);
This fairly simple solution worked for me in version 5 of React Navigation:
<Tab.Navigator
screenOptions={({ route, navigation }) => {
return { tabBarLabel: navigation.isFocused() ? route.name : '' };
}}
>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With