选项卡不活动时,我想隐藏TabBar标签。
使用tabBarOptions中的showLabel只能完全禁用它们。
提前致谢。

reactjs - 如何仅在 Activity 的Tab上显示TabBar标签?-LMLPHP

最佳答案

嘿,德鲁(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;
        }
      }
    })
  }
);

07-26 06:45