Responsive Native Detector to View

I am writing a React Native application and I want to detect clicks / clicks anywhere on the screen, so I put the onClick handler in my <View> element, but it does not seem to work. Here is my rendering function:

 <View style={styles.container} onClick={this.onClick}> <Text style={styles.welcome}> Tap to change the background </Text> </View> 

What do I need to do?

+6
source share
1 answer

In order for any element to handle touch / click events in the React-Native user interface, you need to place the element in the element TouchableOpacity, TouchableWithoutFeedback, TouchableNativeFeedback or TouchableHighlight:

 <TouchableHighlight onPress = { this.onClick }> <View style={styles.container}> <Text style={styles.welcome}> Tap to change the background </Text> </View> </TouchableHighlight> 

Hope this helps.

+11
source

Source: https://habr.com/ru/post/1014574/


All Articles