Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 从MaterialBottomTabNavigator向组件传递道具_React Native - Fatal编程技术网

React native 从MaterialBottomTabNavigator向组件传递道具

React native 从MaterialBottomTabNavigator向组件传递道具,react-native,React Native,我是个新来的本地人。我使用了MaterialBottomTabNavigator进行导航。当标签点击强文本时,它工作正常,但我在主组件屏幕上有一个按钮(链接)。单击该按钮时,应转到项目组件。该按钮位于名为“全部查看”的主组件(可触摸不透明度)中 这是我的导航器(App.js) 从“React”导入React; 从“react native”导入{View}; 从“react navigation”导入{createAppContainer,createStackNavigator}; 从“反应导

我是个新来的本地人。我使用了
MaterialBottomTabNavigator
进行导航。当标签点击强文本时,它工作正常,但我在主组件屏幕上有一个按钮(链接)。单击该按钮时,应转到项目组件。该按钮位于名为“全部查看”的主组件(可触摸不透明度)中

这是我的导航器(App.js)

从“React”导入React;
从“react native”导入{View};
从“react navigation”导入{createAppContainer,createStackNavigator};
从“反应导航材料底部选项卡”导入{createMaterialBottomTabNavigator};
从“反应本机矢量图标/离子图标”导入图标;
从“/pages”导入{主页、项目、图库、联系人、评论、关于};
const TabNavigator=createMaterialBottomTabNavigator(
{  
主页:{
屏幕:主页,
导航选项:{
tabBarLabel:“主页”,
tabBarIcon:({tintColor})=>(
),  
} 
},  
项目:{屏幕:项目,
导航选项:{
tabBarLabel:“项目”,
tabBarIcon:({tintColor})=>(
),  
activeColor:“#c42e00”,
不活动颜色:'#000',
barStyle:{backgroundColor:'#fff'},
}  
},  
图库:{屏幕:图库,
导航选项:{
tabBarLabel:'Gallery',
tabBarIcon:({tintColor})=>(
),  
activeColor:“#c42e00”,
不活动颜色:'#000',
barStyle:{backgroundColor:'#fff'},
}  
},  
联系人:{
屏幕:联系人,
导航选项:{
tabBarLabel:“联系人”,
tabBarIcon:({tintColor})=>(
),  
activeColor:“#c42e00”,
不活动颜色:'#000',
barStyle:{backgroundColor:'#fff'},
}  
}, 
评论:{
屏幕:评论,
导航选项:{
tabBarLabel:“评论”,
tabBarIcon:({tintColor})=>(
),  
activeColor:“#c42e00”,
不活动颜色:'#000',
barStyle:{backgroundColor:'#fff'},
}  
}, 
关于:{
屏幕:关于,
导航选项:{
tabBarLabel:“关于”,
tabBarIcon:({tintColor})=>(
),  
activeColor:“#c42e00”,
不活动颜色:'#000',
barStyle:{backgroundColor:'#fff'},
}  
},  
},  
{  
初始路由名称:“主页”,
activeColor:“#c42e00”,
不活动颜色:'#000',
barStyle:{backgroundColor:'#fff'},
},  
);  
const Nav=createAppContainer(TabNavigator);
导出默认导航
这是我的主页组件(Home.js)

import React,{Component}来自'React';
从“react native”导入{View、Dimensions、ScrollView、ActivityIndicator、图像、文本、TouchableOpacity};
从“axios”导入axios;
从“../common”导入{标题、状态栏、旋转木马};
从“../pages”导入{Nav,Projects};
var{height,width}=Dimensions.get(“窗口”);
类Home扩展组件{
建造师(道具){
超级(道具);
此.state={
布局:{
高度:高度,,
宽度:宽度
},
滑块:[],
项目:[],
加载器:错误
}
}
_按按钮(){
this.props.navigation.navigate('Projects');
}
render(){
返回(
我们的项目
见识
)
}
}
常量样式={
主容器:{
弹性:1,
},
项目\文本\容器:{
flexDirection:“行”,
边缘左侧:28
},
正文1:{
尺寸:20,
fontWeight:“粗体”,
},
文本2:{
边缘左:150,
颜色:#c42e00“,
fontWeight:“粗体”,
玛金托普:5
},
图像样式:{
身高:180,
宽度:150,
}
}  
导出{Home}

代码基本正常,但您的
\u on按钮
无法访问当前组件的
。您必须绑定它或使用箭头函数

对于
绑定
,您可以在构造函数中执行这两项操作:

   constructor(props) {

      super(props);
      this.state = {
       layout: {
           height: height,
           width: width
       },
       sliders : [],
       projects : [],
       loader : false
    }
      this._onPressButton.bind(this)
}
或直接向onPress:

<TouchableOpacity onPress={this._onPressButton.bind(this)}>

请向我们展示一些代码,您尝试了什么,您是如何构建导航器的。让它这样下去,我们甚至不可能想出一个可能的解决办法
   constructor(props) {

      super(props);
      this.state = {
       layout: {
           height: height,
           width: width
       },
       sliders : [],
       projects : [],
       loader : false
    }
      this._onPressButton.bind(this)
}
<TouchableOpacity onPress={this._onPressButton.bind(this)}>
<TouchableOpacity onPress={this._onPressButton.bind(this, "params")}>
_onPressButton = () => {

   this.props.navigation.navigate('Projects');     

}