我正在编写一个 React Native 应用程序,我想检测屏幕上任意位置的点击/点击,所以我在我的 <View>
上放置了一个 onClick 处理程序元素,但它似乎不起作用。这是我的渲染功能:
<View style={styles.container} onClick={this.onClick}>
<Text style={styles.welcome}>
Tap to change the background
</Text>
</View>
我需要做什么?
最佳答案
为了让任何元素在 React-Native UI 中处理触摸/点击事件,你需要将元素放在 TouchableOpacity、TouchableWithoutFeedback、TouchableNativeFeedback 或 TouchableHighlight 元素中:
<TouchableHighlight onPress = { this.onClick }>
<View style={styles.container}>
<Text style={styles.welcome}>
Tap to change the background
</Text>
</View>
</TouchableHighlight>
希望有帮助。
关于react-native - React Native 检测点击 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41948900/