61

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
  • 985
  • 2
  • 8
  • 7

3 Answers3

146

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'}>

iphonic
  • 12,615
  • 7
  • 60
  • 107
Kerumen
  • 4,193
  • 2
  • 19
  • 33
28

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>
Kerumen
  • 4,193
  • 2
  • 19
  • 33
Hasn Ar
  • 281
  • 3
  • 3
  • 1
    It 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? – Joey Harwood Dec 19 '17 at 15:45
  • honestly, 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 – Hasn Ar Dec 19 '17 at 16:17
0

Create a TouchableOpacity in a space where you want to make it unresponsive to any action. like this :

<TouchableOpacity style={{ width : 40 , height : 40}} activeOpacity={1}>
</TouchableOpacity>

this area doesnt have any action from parents component

amir behrouzi
  • 155
  • 1
  • 10