React native 在CreateBoottomTabsnavigator中调用函数
我正在使用react native,我想在选项卡中调用函数React native 在CreateBoottomTabsnavigator中调用函数,react-native,tabs,bottomnavigationview,tabnavigator,React Native,Tabs,Bottomnavigationview,Tabnavigator,我正在使用react native,我想在选项卡中调用函数 import {createBottomTabNavigator} from 'react-navigation-tabs'; const TabNavigator = createBottomTabNavigator( { Home:{ screen:CustomMapView, navigationOptions:{ tabBarLabel
import {createBottomTabNavigator} from 'react-navigation-tabs';
const TabNavigator = createBottomTabNavigator(
{
Home:{
screen:CustomMapView,
navigationOptions:{
tabBarLabel:'Home',
tabBarIcon:({tintColor})=>(
<Image source = {require("../../Images/react-logo.png")} style={{width : 30 , height:30}}/>
)
}
}, Profile11:{
screen:Profile11,
navigationOptions:{
tabBarLabel:'Profile11',
tabBarIcon:({tintColor})=>(
<Image source = {require("../../Images/react-logo.png")} style={{width : 30 , height:30}}/>
)
}
},
Profile: {
screen:ProfileScreen,
navigationOptions:{
tabBarLabel:'Profile',
tabBarIcon:({tintColor})=>(
// <Icon name="ios-person" color={tintColor} size={25}/>
<Image source = {require("../../Images/react-logo.png")} style={{width : 30 , height:30}}/>
)
}
},
},
{
initialRouteName: "Home"
},
);
从“反应导航选项卡”导入{CreateBoottomTabNavigator};
const TabNavigator=createBottomTabNavigator(
{
主页:{
屏幕:CustomMapView,
导航选项:{
tabBarLabel:“主页”,
tabBarIcon:({tintColor})=>(
)
}
},Profile11:{
屏幕:Profile11,
导航选项:{
tabBarLabel:'Profile11',
tabBarIcon:({tintColor})=>(
)
}
},
个人资料:{
屏幕:ProfileScreen,
导航选项:{
tabBarLabel:“配置文件”,
tabBarIcon:({tintColor})=>(
//
)
}
},
},
{
初始路由名称:“主页”
},
);
当我在上面使用时,我想在诸如home if condition true run set CustomMapView As screen if condition false之类的选项卡上设置一些内容,如果condition false,则任何其他屏幕都将设置为CustomMapView.js
如果要设置渲染页面的条件,请检查此示例:
const MainApp = createBottomTabNavigator(
{
Home: HomeTab ,
Settings: SettingsTab ,
},
{
defaultNavigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, horizontal, tintColor }) => {
const { routeName } = navigation.state;
if (routeName === 'Home') {
return (
<Image
source={ require('./assets/home.png') }
style={{ width: 20, height: 20, }} />
);
} else {
return (
<Image
source={ require('./assets/settings.png') }
style={{ width: 20, height: 20 }} />
);
}
},
}),
tabBarOptions: {
activeTintColor: '#FF6F00',
inactiveTintColor: '#263238',
},
});
const MainApp=createBottomTabNavigator(
{
主页:主页选项卡,
设置:设置Stab,
},
{
defaultNavigationOptions:({navigation})=>({
tabBarIcon:({聚焦、水平、着色})=>{
const{routeName}=navigation.state;
如果(routeName==='Home'){
返回(
);
}否则{
返回(
);
}
},
}),
选项卡选项:{
activeTintColor:“#FF6F00”,
颜色:“#263238”,
},
});
如果要在tab press上调用方法,请参考以下示例:
Profile: {
screen:ProfileScreen,
navigationOptions:{
tabBarLabel:'Profile',
tabBarIcon:({tintColor})=>(
// <Icon name="ios-person" color={tintColor} size={25}/>
<Image source = {require("../../Images/react-logo.png")} style={{width : 30 , height:30}}/>
),
tabBarOnPress: () => { this.openGallery() }
}
},
Profile:{
屏幕:ProfileScreen,
导航选项:{
tabBarLabel:“配置文件”,
tabBarIcon:({tintColor})=>(
//
),
tabBarOnPress:()=>{this.openGallery()}
}
},
您是想在tab press上调用函数,还是想根据要呈现的页面设置条件?您好,我想运行一个函数。在该函数中,必须有这样的条件:如果用户登录,则转到该屏幕,否则转到另一屏幕。上述代码不起作用。请告诉我如何调用函数。如上所述。要调用tab press上的函数,可以使用“tabBarOnPress”。请参阅此链接: