【问题标题】:TouchableOpacity:Why did not trigger onPress,But triggered onLongPress?TouchableOpacity:为什么没有触发onPress,却触发了onLongPress?
【发布时间】:2019-11-28 06:21:25
【问题描述】:
<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

【问题讨论】:

  • 您可以尝试评论 onLongPress 或 onPressIn 或 onPressOut。可能会将控制权传递给其他回调。
  • 但我不知道为什么会这样?这不合理吗?
  • 为什么需要所有回调?仅供参考:github.com/facebook/react-native/issues/15088
  • delayLongPress={1500}
  • 嘿@ebyteebyte你在哪里检查onpress和onlongpress ...在模拟器中???

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


【解决方案1】:

我在开发过程中也面临同样的问题,如 onLongpress 和 onPress 两者都不能顺利运行,但是当我进行构建时 它按预期工作。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-23
    • 2021-06-21
    • 2019-02-19
    • 2023-03-11
    相关资源
    最近更新 更多