简体   繁体   English

无法在本机反应中导航到另一个屏幕

[英]Unable to navigate to another screen in react native

I am using props in my code to show items but I am not able to navigate to any other screen after click on it. 我在代码中使用道具来显示项目,但是单击后无法导航到任何其他屏幕。 I am also define as const { navigate } = this.props.navigation; 我也定义为const { navigate } = this.props.navigation; but showing me error as in screen shot. 但向我显示屏幕截图中的错误。

Here is my code. 这是我的代码。 This code is in same Indprotype.js file (two separate .js files are not used) 此代码在同一Indprotype.js文件中(不使用两个单独的.js文件)

  class Withwish extends React.Component {

      ProPressed(productid){
        const { navigate } = this.props.navigation;
        const params = { productid };
        navigate('Product', params);
      }

    render() {
          // const { navigate } = this.props.navigation;
      return (
                  <View style={styles.word}>
                  <TouchableHighlight onPress={() => this.ProPressed(this.props.id)}>
                    <Image source={{uri: 'https://res.cloudinary.com/hu2lcbj2n/' + this.props.image}} />
                  </TouchableHighlight>  
              </View>
      );
    }
  }


  export default class Indprotype extends React.Component {
     // const { navigate } = this.props.navigation;
    render() {
       const items = this.state.qwerty.data;
      return (
          <GridView
              renderItem={item => (
                <Withwish
                  image = {item.p1.image}
                  id = {item.p1.id}
                 />
            )}
          />
      );
    }
  }

错误

Give this a try. 试试看。

Basically I'm passing the navigation prop from the Indprotype component through to the Withwish component. 基本上,我将navigation道具从Indprotype组件传递到Withwish组件。

Note: I'm assuming here that Indprotype itself receives the navigation prop from a router or similar. 注意:我在这里假设Indprotype本身从路由器或类似设备接收navigation道具。

class Withwish extends React.Component {

    ProPressed(productid){
      const { navigate } = this.props.navigation;
      const params = { productid };
      navigate('Product', params);
    }

  render() {
        // const { navigate } = this.props.navigation;
    return (
                <View style={styles.word}>
                <TouchableHighlight onPress={() => this.ProPressed(this.props.id)}>
                  <Image source={{uri: 'https://res.cloudinary.com/hu2lcbj2n/' + this.props.image}} />
                </TouchableHighlight>  
            </View>
    );
  }
}


export default class Indprotype extends React.Component {
    // const { navigate } = this.props.navigation;
  render() {
      const items = this.state.qwerty.data;
    return (
        <GridView
            renderItem={item => (
              <Withwish
                navigation = {this.props.navigation}
                image = {item.p1.image}
                id = {item.p1.id}
                />
          )}
        />
    );
  }
}

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

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