简体   繁体   English

React-navigation undefined错误

[英]React-navigation undefined Error

I have an interesting question: So I import this 我有一个有趣的问题:所以我导入了这个

<TouchableOpacity onPress={() => this.props.navigation.navigate('Feed')} style={styles.buttonContainer}>
   <Text  style={styles.buttonText}>
        LOGIN
   </Text>                 
</TouchableOpacity>   

button from a form I created, I import it to a screen that I want to load the form on like this: 从我创建的表单按钮,我将其导入到我想要加载表单的屏幕上,如下所示:

<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>

but my onpress function to transition screens doesnt want to relay and throws an undefined error Cant import something and render an onpress function anywhere even in my router: 但我转换屏幕的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' },
      }
     }
   },

what do i have to do exactly 我该怎么办呢

Here be the logcat error msg 这是logcat错误消息

You need to pass the properties to your child component to 您需要将属性传递给子组件

Change 更改

<LoginForm/>

to

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

For it to work in navigator, use a reference 要使其在导航器中工作,请使用引用

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

and then 接着

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM