Can I disable a View component in react native?

JavascriptFacebookReactjsReact NativeReactjs Native

Javascript Problem Overview


My app screen has a View component with few Text Inputs. I cannot disable text inputs. Is there a way that I can disable complete View?

P.S.: By Disabling a View component I mean that the component renders but becomes unresponsive of any action.

Javascript Solutions


Solution 1 - Javascript

You can use pointerEvents:

<View pointerEvents="none">
  ...
</View>

This will make the view unresponsive to touch events.

You can use something like

>

Solution 2 - Javascript

Adding to Kerumen's answer, in some rare cases:

<View pointerEvents={myCondition ? 'none' : 'auto'}>
  ...
</View>

You might need to wrap it in an anonymous function:

<View pointerEvents={() => myCondition ? 'none' : 'auto'}>
  ...
</View>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3300203View Question on Stackoverflow
Solution 1 - JavascriptKerumenView Answer on Stackoverflow
Solution 2 - JavascriptHasn ArView Answer on Stackoverflow