React-navigation undefined错误

时间:2017-04-06 14:44:30

标签: javascript react-native react-navigation expo

我有一个有趣的问题:所以我导入了这个

<TouchableOpacity onPress={() => this.props.navigation.navigate('Feed')} style={styles.buttonContainer}>
   <Text  style={styles.buttonText}>
        LOGIN
   </Text>                 
</TouchableOpacity>   
我创建的表单中的

按钮, 我将它导入到我想加载表单的屏幕上,如下所示:

<KeyboardAvoidingView behavior='padding' style={styles.container}>

              <View style={styles.logo}>
                <Text style={{fontSize: 64, color: '#34B3E4'}}>Partner<Text style={{fontSize: 64, color: '#0077B5'}}>Up</Text></Text>
                <Text style={{fontSize: 13, opacity: 0.8, color: '#0077B5'}}>We connect you. You work easier.</Text>
              </View>
              <LoginForm/>           <-------------------Here is the import
              <View style={styles.accountLogin}>
                    <TouchableOpacity onPress={() => this.props.navigation.navigate('Forgot')}>
                        <Text style={{opacity: 0.9,color:'#34B3E4'}} >Forgot your password? </Text>
                    </TouchableOpacity>
              </View>  
</KeyboardAvoidingView>

但我转换屏幕的onpress功能不想中继并抛出未定义的错误 无法导入某些内容并在我的路由器中的任何地方呈现onpress功能:

Feed: {
     screen: Feed,
     navigationOptions: {
       title: 'Mentor',
       header:{
         right: //Going to be the users profile picture
       <Icon  
       onPress={() => this.props.navigation.navigate('Profile')}
       name="user" 
       color='#0077B5'
       size={30}
        />,
        left: //Messages
       <Icon  
       name="message" 
       color='#0077B5'
       size={30}
        />,
       titleStyle: { color: '#0077B5' },
      }
     }
   },

我该怎么做

Here be the logcat error msg

1 个答案:

答案 0 :(得分:0)

您需要将属性传递给子组件

更改

<LoginForm/>

<LoginForm navigation={this.props.navigation}/>

要使其在导航器中工作,请使用参考

<Navigator
 ref='navigator'
 ...
/>

然后

<Icon
  navigator={this.refs.navigator}
/>