Set onPress on View using onStartShouldSetResponder React Native Example

Buttons are used in all the programming language to get click events from users. But in react native we can also use its onStartShouldSetResponder Prop to enable click onPress event on View component. Because sometimes we have to make the View component responsive or Fire an event when user clicks on View. So here comes the onStartShouldSetResponder prop. It works same as button onPress event and can handle function calling. So in this tutorial we would learn about How to Set onPress on View using onStartShouldSetResponder React Native Android iOS Example.

Contents in this project Set onPress on View using onStartShouldSetResponder React Native Android iOS Example :-

1. Open your project’s main App.js file and import View, StyleSheet, Text and Alert component.

2. Creating our main Export default Functional component named as App.

3. Creating a function named as showAlert(). In this function we would print a Alert dialog box on the screen.

4. Creating return block. Now here first we would make a Root View component -> 1 Child View component and set onStartShouldSetResponder on it to call the above function. So when user clicks on the View component it will call the function and print a Alert message on screen.

5. Creating Style.

6. Complete Source Code for our React Native Project’s Main App.js File:

Screenshots:-

Set onPress on View using onStartShouldSetResponder React Native Example

Leave a Reply

Your email address will not be published.