Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way in which I can ignore touch events on Text in React Native?

Tags:

react-native

I want to implement floating labels, for this I have a Text Component Above a TextInput. I want to ignore all the touch events on the Text so that the TextInput Under it gets all the events. Is there a way I can do this ? In CSS we used to have pointer-events none, I am not sure how to do this in react native.

like image 807
Mayank Patel Avatar asked May 04 '15 22:05

Mayank Patel


People also ask

How do I disable touch in React Native?

To disable a View component in React Native, we can set the pointerEvents prop to 'none' . to set the inner view's pointerEvents prop to 'none' so that users can't interact with the content inside.

How do you handle touch in React Native?

Touchable HighlightThe Button component is wrapped inside the Text component and the Text is inside the TouchableHighlight component . You can add styles to the components as per your requirements. The onPress function is added on the TouchableHighlight and on tap the alert message will be shown.

How do you stop event bubbling in React Native?

Just add the prop onStartShouldSetResponder={event => true} to the <View> you want to prevent bubbling up.

How do you avoid multiple clicks on a button in React Native?

To prevent multiple button clicks in React: Set an onClick prop on the button, passing it a function. When the button gets clicked, set its disabled attribute to true .


2 Answers

In react-native, pointerEvents is a prop, not a style.

    <View pointerEvents="none" /> 
like image 188
Gil Birman Avatar answered Sep 20 '22 14:09

Gil Birman


Add pointerEvents: 'none' to the Text component. This allows touch events to go to the ancestors of the component, but not the component itself or its children.

React Native also supports 'box-none', which allows touch events to go to the ancestors and children of the component, and excludes only the component itself.

like image 23
ide Avatar answered Sep 22 '22 14:09

ide