Can I disable a View component in react native?
33,050
Solution 1
You can use pointerEvents
:
<View pointerEvents="none">
...
</View>
This will make the view unresponsive to touch events.
You can use something like
<View pointerEvents={myCondition ? 'none' : 'auto'}>
Solution 2
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>
Author by
user3300203
Updated on August 28, 2021Comments
-
user3300203 almost 3 years
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.
-
user3300203 over 7 yearsThanks for this solution.
-
Dhrupal over 6 yearsCan we give it conditinally?
-
Kerumen over 6 yearsYes you can use something like
<View pointerEvents={myCondition ? 'none' : 'auto'}>
-
Joey Harwood over 6 yearsIt looks like your code block didn't format the way you intended. Also, in what rare cases would you need to wrap* it in an anonymous function?
-
Admin over 6 yearshonestly, I don't but for some reason, it didn't work until I warp it in a function, I am investigating to find out the reason
-
Nicolas Silva over 3 yearssuper useful prop, how i never heard of it?