我可以使用像TouchableWithoutFeedback这样的Touchables而不是使用this.props.navigation.navigate的按钮进行反应原生导航

[英]can I use Touchables like TouchableWithoutFeedback instead of using button for this.props.navigation.navigate in react native navigation


<TouchableWithoutFeedback onPress={()=>this.props.navigation.navigate('Home')} > 
    { 
        this.props.type!=='1' ? <Icon2 name="chevron-with-circle-left" size={28}/> 
                              : <Icon name='chevron-left' style={{ color: "#16527e" }} size={35}/>
    }
</TouchableWithoutFeedback>

This code is showing an error that this.props.navigation.navigate is not an object . Is that necessary to use button for navigation for using this.props.navigation.navigate? can anyone help ?

此代码显示this.props.navigation.navigate不是对象的错误。是否有必要使用按钮进行导航以使用this.props.navigation.navigate?有人可以帮忙吗?

1 个解决方案

#1


0  

No, it's not necessary. You can use whatever function for your onPress. I think that the problem is your navigation object.. is it undefined?

不,这是没有必要的。您可以使用onPress的任何功能。我认为问题是你的导航对象..是不确定的?

Try with this code and read what it's logged:

尝试使用此代码并阅读它的记录:

<TouchableWithoutFeedback
    onPress={()=> console.log("Navigation is :", this.props.navigation}> 
              { this.props.type!=='1'?
                <Icon2 name="chevron-with-circle-left" size={28}/> 
                : <Icon name='chevron-left' style={{ color: "#16527e" }} 
                  size={35}/>
              }
</TouchableWithoutFeedback>

Ensure that navigation contains the "navigate" function and, if it's necessary, log even "this.props.navigation.navigate".

确保导航包含“导航”功能,如果有必要,甚至记录“this.props.navigation.navigate”。

At the end ensure that react-navigation is configured properly.

最后确保正确配置react-navigation。

Something more: if you are trying to use navigation inside a presentational component make sure that navigation is an object inside the container component and pass navigation down as a prop. If react-navigation opens the page XYZ ensure that navigation.navigate works in XYZ and pass it to other components as a prop. If XYZ opens from react-navigation routing it should have this.props.navigation. XYZ renders ABC. XYZ should pass this.props.navigation to ABC as a prop:

更多内容:如果您尝试在演示组件中使用导航,请确保导航是容器组件内的对象,并将导航向下传递为道具。如果react-navigation打开页面XYZ,请确保navigation.navigate在XYZ中工作,并将其作为prop传递给其他组件。如果XYZ从反应导航路由打开,它应该有this.props.navigation。 XYZ呈现ABC。 XYZ应该将this.props.navigation传递给ABC作为道具:

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

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2018/06/25/f251cfc808e8257d1dbd62ef6470169f.html



 
  © 2014-2022 ITdaan.com 联系我们: