Bezzi
Bezzi

Reputation: 260

How to Implement a press event in a custom React Native Component

I created a native UI component for android using react native, I can display it on the screen but I'd like to add an onPress event to it. How could I do that?

Upvotes: 1

Views: 798

Answers (1)

MattYao
MattYao

Reputation: 2555

You can wrap your components with TouchableOpacity or TouchableHighlight. And you can easily add event listener in this way:

<TouchableOpacity onPress={MY_FUNC}> 
  <MyComponent />
</TouchableOpacity>

Upvotes: 3

Related Questions