【问题标题】:React Native - Push one Screen To Another have issueReact Native - 将一个屏幕推送到另一个有问题
【发布时间】:2017-07-29 05:50:07
【问题描述】:

我使用了“StackNavigator”,当导航代码写入按钮事件时,我无法推送。但是如果我们直接对 onPress 事件进行编码,它就可以正常工作,

导入文件。

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>
    );
  }

推送另一个 via 功能不起作用:

   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>

    );}

点击按钮错误:

谢谢。请帮帮我。

【问题讨论】:

    标签: react-native react-router react-navigation react-native-0.46


    【解决方案1】:

    看起来你在这一行中使用了 push extra

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

    试试这个对你有用

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

    也许这对你有帮助

    【讨论】:

    • 什么问题我没找到你?
    【解决方案2】:

    我认为您错过了构造函数中的函数 bind --- 这就是为什么您得到 undefined is not an object (evalating 'this.props.navigation')。因为thispushcode 函数范围内是未定义的。

    将以下内容添加到您的构造函数中:

    constructor(props) {
        super(props);
    
        this.pushcode = this.pushcode.bind(this);
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-30
      • 1970-01-01
      • 2020-11-14
      • 1970-01-01
      • 1970-01-01
      • 2019-01-18
      • 2022-01-22
      • 1970-01-01
      相关资源
      最近更新 更多