0

我使用了'StackNavigator',导航代码在按钮事件中写入时我遇到问题。但其工作正常,如果我们直接编码onPress事件,React Native - 将一个屏幕推送到另一个有问题

导入文件。

import { StackNavigator } from "react-navigation"; 
import SignUpScreen from "./SignUp"; 

推另一工作:

render() { 
    console.disableYellowBox = true; 
    const { navigate } = this.props.navigation; 
    return (
     <View style={styles.viewStyle}> 
     <TouchableHighlight style = {styles.buttonStart} 
      onPress={() => navigate("SignUpCompany")}> 
       <Image 
       source={require('./Images/hire.png')} 
       /> 
     </TouchableHighlight> 
     </View> 
    ); 
    } 

推另一个通过功能无法正常工作:

pushcode() { 
    console.log('call'); 
    this.props.navigation.navigate('SignUp'); 
    } 

    render() { 
    return (

    <TouchableHighlight style = {styles.buttonStart} 
     onPress={this.pushcode}> 
      <Image 
      source={require('./Images/hire.png')} 
      /> 
    </TouchableHighlight> 

    );} 

错误接通,单击按钮:

enter image description here

谢谢。请帮帮我。

回答

2

看起来像你正在使用推额外此行

this.props.navigation.navigate.push('SignUp'); 

试试这个会为你工作

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

可能这可以帮助你

+0

OKY。我会尝试 –

+0

谢谢,但也有问题。我将编辑代码。 –

+0

我没有得到你什么问题? –

1

我想你错过了函数bind在构造函数---这就是为什么你有未定义不是一个对象(评估'this.props.navigation')。因为thispushcode功能范围内未定义。

下方添加到您的构造函数:

constructor(props) { 
    super(props); 

    this.pushcode = this.pushcode.bind(this); 
    ... 
} 
相关问题