react-native如何将图像和onpress添加到可触摸中 [英] react-native how to add image and onpress into touchable

查看:77
本文介绍了react-native如何将图像和onpress添加到可触摸中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本机反应中具有可触摸性,在可触摸性中我有图像和像这样的新闻

I have touchable in react native, inside touchable I have image and on press like this

 <TouchableHighlight >
  <Image style={styles.imagestyle}
  source={require('./ic_action_name.png')} />
  onPress={() => this.moveToAddNewCustomer()}>
 </TouchableHighlight>

当我尝试运行该应用程序时,出现此错误

When I tried to run the app, I got this error

React.Childeren.only 期望接收单个 React 元素孩子

React.Childeren.only expected to receive a single React element child

如何解决这个问题?

推荐答案

你需要这样做:

<TouchableHighlight onPress={() => this.moveToAddNewCustomer()}>
    <Image style={styles.imagestyle} source={require('./ic_action_name.png')} />
</TouchableHighlight>

<TouchableOpacity onPress={()=>this.moveToAddNewCustomer()}>
    <Image style={styles.imagestyle} source={require('./ic_action_name.png')} />
</TouchableOpacity>

这篇关于react-native如何将图像和onpress添加到可触摸中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆