Reputation: 1158
I need to listen to touch event of a React Native view and do some action in the callback. I couldn't get any way of doing it in a simple way. Only workaround I could find is to use Pan Responder and use onResponderGrant
callback. Wanted to know if there is a simpler way of listening to touch event, something similar to onPress
.
Upvotes: 3
Views: 3035
Reputation: 3944
You can use TouchableOpacity
as a View
that provides touchable feedback. Eg
<TouchableOpacity
onPress = {() => function()}
onLongPress = {() => longerFunction()}
style = {{these can be the same as a normal View}}>
</TouchableOpacity>
You can also use TouchableHighlight
and TouchableWithoutFeedback
, which provide a darkening onPress effect and no effect respectively.
Upvotes: 5