react-native how to add image and onpress into touchable
if
TouchableHighlight onPress={() => this.moveToAddNewCustomer()}>
<Image style={styles.imagestyle} source={require('./ic_action_name.png')} />
</TouchableHighlight>
didn't work, you should put ur image in a <view>
You need to do it 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>
By default there is no click or events that attached with any of the Views in react native like react.js. There are mainly two Views specifically designed for handling touch events. They are TouchableOpacity
and TouchableHighlight
. You can resolve your issue by wrapping your Image
component with TouchableOpacity
or TouchableHighlight
.
<TouchableHighlight onPress={() => this.moveToAddNewCustomer()}>
<Image style={styles.imagestyle} source={require('./ic_action_name.png')} />
</TouchableHighlight>
https://reactnative.dev/docs/touchablehighlight
https://reactnative.dev/docs/touchableopacity