3

我正在使用 create-react-native-app 并且正在使用带有 createBottomTabNavigator 函数的 StackNavigator。这些图标是通过一个单独的组件设置样式的,但是我在设置导航器的其余部分时遇到了问题。

我已经创建了我想使用的这些选项:

  tabBarOptions: {
    showLabel: false,
    style: {
      backgroundColor: Colors.greyGreen
    }
  }

希望这对某人来说非常明显,并会感谢您的帮助!我尝试将选项放置在下面代码中的各个位置(两个位置都不起作用):

const config = Platform.select({
  web: { headerMode: 'screen' },
  default: {},
  // TRIED PLACING THE OPTIONS HERE
});

const HomeStack = createStackNavigator(
  {
    Home: HomeScreen,
  },
  config
);
HomeStack.navigationOptions = {
  tabBarLabel: 'Home',
  tabBarIcon: ({ focused }) => (
    <TabBarIcon
      focused={focused}
      name={
        Platform.OS === 'ios'
          ? `ios-information-circle${focused ? '' : '-outline'}`
          : 'md-information-circle'
      }
    />
  ),
};
HomeStack.path = '';

const LinksStack = createStackNavigator(
  {
    Links: LinksScreen,
  },
  config
);
LinksStack.navigationOptions = {
  tabBarLabel: 'Links',
  tabBarIcon: ({ focused }) => (
    <TabBarIcon focused={focused} name={Platform.OS === 'ios' ? 'ios-link' : 'md-link'} />
  ),
};
LinksStack.path = '';

const SettingsStack = createStackNavigator(
  {
    Settings: SettingsScreen,
  },
  config
);
SettingsStack.navigationOptions = {
  tabBarLabel: 'Settings',
  tabBarIcon: ({ focused }) => (
    <TabBarIcon focused={focused} name={Platform.OS === 'ios' ? 'ios-options' : 'md-options'} />
  ),
};
SettingsStack.path = '';

const tabNavigator = createBottomTabNavigator({
  HomeStack,
  LinksStack,
  SettingsStack,
  // TRIED PLACING THE OPTIONS HERE
});
tabNavigator.path = '';

export default tabNavigator;

如果您想查看图标组件:

export default function TabBarIcon(props) {
  return (
    <Ionicons
      name={props.name}
      size={26}
      style={{ marginBottom: -3 }}
      color={props.focused ? Colors.tabIconSelected : Colors.tabIconDefault}
    />
  );
}
4

3 回答 3

9

我相信 React Navigation 版本 5.x 已经发生了变化。

const Tab = createBottomTabNavigator();

function MyTab() {
    return (
        <Tab.Navigator
            tabBarOptions={{
                showLabel: false
            }}
        >
            <Tab.Screen ... />
            <Tab.Screen ... />
        </Tab.Navigator>
    );
}
于 2020-11-04T13:21:05.953 回答
4

你应该把它放在这里,

const tabNavigator = createBottomTabNavigator({
  HomeStack,
  LinksStack,
  SettingsStack,
},{

tabBarOptions: {
    showLabel: false,
    style: {
      backgroundColor: Colors.greyGreen
    }
  }
});

希望能帮助到你。随时怀疑

于 2019-12-10T06:55:18.940 回答
1

底部选项卡导航器:不推荐使用“tabBarOptions”。将选项迁移到“screenOptions”。

<Tab.Navigator    
  screenOptions={{
    tabBarShowLabel: false,
    tabBarStyle: {
      backgroundColor: Colors.greyGreen
    }
  }}
/>
于 2022-01-24T14:15:43.817 回答