Bokerjy Zahgan Bokerjy Zahgan - 12 days ago 5
Android Question

react-native how to add image and onpress into touchable

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 expected to receive a single React element child


how to fix this ?

Answer

You need to do like this,

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

or

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