TouchableOpacity:为什么不触发onPress,但是触发onLongPress?

时间:2019-11-28 06:21:25

标签: react-native react-native-android touchableopacity

<TouchableOpacity
    onPressIn={() => { console.log(Math.round((new Date().getTime() / 1000)), 'onPressIn') }}
    onPressOut={() => { console.log(Math.round((new Date().getTime() / 1000)), 'onPressOut') }}
    onPress={() => { console.log(Math.round((new Date().getTime() / 1000)), 'onPress') }}
    onLongPress={() => { console.log(Math.round((new Date().getTime() / 1000)), 'onLongPress') }}>

    <Image
        source={{ uri: item.images.medium }}
        style={styles.item_image}
    />

</TouchableOpacity>

console.log

1574921523 "onPressIn"
1574921523 "onLongPress"
1574921523 "onPressOut"

为什么不触发onPress,而是触发onLongPress?

https://facebook.github.io/react-native/docs/touchablewithoutfeedback#onlongpress

image: console.log

1 个答案:

答案 0 :(得分:0)

  

在开发过程中,我也面临着与onLongpress和   onPress都无法正常工作,但是当我完成构建后   它按预期运行。

So try to make the build of the app, and it will work fine

希望这会有所帮助。...谢谢:)