我应该在 StackNavigator 中的什么地方放置 "tabBarOptions"?
Where do I place "tabBarOptions" inside StackNavigator?
我正在使用 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}
/>
);
}
你应该把它放在这里,
const tabNavigator = createBottomTabNavigator({
HomeStack,
LinksStack,
SettingsStack,
},{
tabBarOptions: {
showLabel: false,
style: {
backgroundColor: Colors.greyGreen
}
}
});
希望对您有所帮助。有问必答
我相信 React Navigation 版本 5.x。
const Tab = createBottomTabNavigator();
function MyTab() {
return (
<Tab.Navigator
tabBarOptions={{
showLabel: false
}}
>
<Tab.Screen ... />
<Tab.Screen ... />
</Tab.Navigator>
);
}
底部选项卡导航器:'tabBarOptions' 已弃用。将选项迁移到 'screenOptions'。
<Tab.Navigator
screenOptions={{
tabBarShowLabel: false,
tabBarStyle: {
backgroundColor: Colors.greyGreen
}
}}
/>
我正在使用 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}
/>
);
}
你应该把它放在这里,
const tabNavigator = createBottomTabNavigator({
HomeStack,
LinksStack,
SettingsStack,
},{
tabBarOptions: {
showLabel: false,
style: {
backgroundColor: Colors.greyGreen
}
}
});
希望对您有所帮助。有问必答
我相信 React Navigation 版本 5.x。
const Tab = createBottomTabNavigator();
function MyTab() {
return (
<Tab.Navigator
tabBarOptions={{
showLabel: false
}}
>
<Tab.Screen ... />
<Tab.Screen ... />
</Tab.Navigator>
);
}
底部选项卡导航器:'tabBarOptions' 已弃用。将选项迁移到 'screenOptions'。
<Tab.Navigator
screenOptions={{
tabBarShowLabel: false,
tabBarStyle: {
backgroundColor: Colors.greyGreen
}
}}
/>