React Native タップ検出の表示 質問する

React Native タップ検出の表示 質問する

私はReact Nativeアプリを書いていて、画面上のどこでもタップ/クリックを検出したいので、<View>要素にonClickハンドラを配置しましたが、うまく機能していないようです。これが私のレンダリング関数です:

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

何をすればいいですか?

ベストアンサー1

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>

お役に立てれば幸いです。

おすすめ記事