我正在使用 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}
/>
);
}