React native 如何在CreateBoottomTabNavigator()中设置初始选项卡
在使用react navigation 3.11.0的应用程序中,有3个选项卡:React native 如何在CreateBoottomTabNavigator()中设置初始选项卡,react-native,react-navigation,React Native,React Navigation,在使用react navigation 3.11.0的应用程序中,有3个选项卡: return createBottomTabNavigator( { Event: { screen: EventStack, navigationOptions: { title: "Event", }, },
return createBottomTabNavigator(
{
Event: {
screen: EventStack,
navigationOptions: {
title: "Event",
},
},
Group: {
screen: GroupStack,
navigationOptions: {
title: "Group",
},
},
Contact: {
screen: ContactStack,
navigationOptions: {
title: "Contact",
},
},
}, bottomTabNavOptions,
{initialRouteName: Group} //<<<== did not work
);
及
两个都不起作用。设置初始选项卡的正确方法是什么
bottomTabNavOptions
是:
const bottomTabNavOptions = {
defaultNavigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
console.log("route name", routeName);
let iconName;
if (routeName === 'Event') {
iconName = `list-unordered`;
} else if (routeName === 'Contact') {
iconName = `person`;
} else if (routeName === 'Group') {
iconName = `organization`
}
return <Icon name={iconName} size={30} color={tintColor} type='octicon' />;
},
}),
tabBarOptions: {
activeTintColor: 'tomato',
inactiveTintColor: 'gray',
},
};
const bottomTabNavOptions={
defaultNavigationOptions:({navigation})=>({
tabBarIcon:({focused,tintColor})=>{
const{routeName}=navigation.state;
日志(“路由名称”,routeName);
让我来;
如果(routeName=='Event'){
iconName=`无序列表';
}否则,如果(routeName==='Contact'){
iconName=`person`;
}else if(routeName=='Group'){
iconName=`组织`
}
回来
},
}),
选项卡选项:{
activeTintColor:‘番茄’,
颜色:“灰色”,
},
};
您需要使用一个字符串,您正在传递整个“组”组件:
initialRouteName:"Group"
您需要使用一个字符串,您正在传递整个“组”组件:
initialRouteName:"Group"
createBottomTabNavigator
选项卡有两个参数。但您似乎正在发送三个参数
CreateBoottomTabNavigator(RouteConfigs、BottomTabNavigatorConfig)
底部选项卡导航配置:
- initialRouteName:字符串
createBottomTabNavigator(
{
活动:{
屏幕:EventStack,
导航选项:{
标题:“事件”,
},
},
组:{
屏幕:GroupStack,
导航选项:{
标题:“集团”,
},
},
联系人:{
屏幕:ContactStack,
导航选项:{
标题:“联系人”,
},
},
},
{
initialRouteName:'Group',CreateBoottomTabNavigator
选项卡有两个参数。但您似乎正在发送三个参数
CreateBoottomTabNavigator(RouteConfigs、BottomTabNavigatorConfig)
底部选项卡导航配置:
- initialRouteName:字符串
createBottomTabNavigator(
{
活动:{
屏幕:EventStack,
导航选项:{
标题:“事件”,
},
},
组:{
屏幕:GroupStack,
导航选项:{
标题:“集团”,
},
},
联系人:{
屏幕:ContactStack,
导航选项:{
标题:“联系人”,
},
},
},
{
initialRouteName:'Group',看到您最初尝试传递字符串的评论。同样的事情发生在我身上。我只需重新启动正在使用的模拟器,然后它就开始为我工作。看到您最初尝试传递字符串的评论。同样的事情发生在我身上。我只需重新启动正在使用的模拟器,然后恩,它开始对我起作用。在发布前尝试了字符串。但它仍然首先登录到事件
选项卡。应用程序是否有办法返回当前选项卡?只需打印出路线名称并确认它是事件
正在呈现。在发布前尝试了字符串。但它仍然首先登录到事件
选项卡。ap有办法吗p返回当前选项卡?只需打印出路由名称,并确认正在呈现Event
。
initialRouteName:"Group"