gpt4 book ai didi

react-native - 我在哪里放置 "tabBarOptions"在 StackNavigator 中?

转载 作者:行者123 更新时间:2023-12-04 14:35:36 27 4
gpt4 key购买 nike

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

最佳答案

我相信 React Navigation 版本 5.x 已经改变了。

const Tab = createBottomTabNavigator();

function MyTab() {
return (
<Tab.Navigator
tabBarOptions={{
showLabel: false
}}
>
<Tab.Screen ... />
<Tab.Screen ... />
</Tab.Navigator>
);
}

关于react-native - 我在哪里放置 "tabBarOptions"在 StackNavigator 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59261694/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com