React Native Add onLongPress on Button using TouchableOpacity

onLongPress={} event is like setOnLongClickListener() available in android application development. onLongPress={} activated the button after a few seconds of press, User need to press and hold the button for few seconds(1.3 seconds) approximate. But Button component in react native directly dose not support the onLongPress={} event, So instead of Button component we have to use TouchableOpacity component. So in this tutorial we would going to Add onLongPress on Button using TouchableOpacity in both Android iOS react native application example tutorial. Using this same method we can also implement onLongPress={} on Images.

Contents in this project Add onLongPress on Button using TouchableOpacity in Android iOS react native app example tutorial:

1. Import StyleSheet, View, Alert, TouchableOpacity and Text component in your project.

2. Create a function named as SampleFunction(). We would call this function on onLongPress={} event.

3. Create a Root Parent View in render’s return block.

4. Create a TouchableOpacity component with Text component in root view and call the onLongPress={} event.

5. Create Style.

6. Complete source code for App.js File :

Screenshot in Android device :

Add onLongPress on Button

Screenshots in iOS device :

2 Comments

  1. Can you explain how to do a category list selector with a long press button click?

Leave a Reply

Your email address will not be published.