【问题标题】:Does onGestureEvent of TapGestureHandler never fire?TapGestureHandler 的 onGestureEvent 永远不会触发吗?
【发布时间】:2021-06-05 09:31:16
【问题描述】:

这里是下面问题的小吃 - https://snack.expo.io/@noitidart/tapgesturehandler-ongestureevent

onGestureEvent for TapGestureHandler 永远不会触发吗?文档没有说明这一点。这似乎发生在我身上:

import Reanimated from 'react-native-reanimated';

const handleStateChange = () => console.log('state changed');
const handleGestureEvent = () => console.log('got gesture event');

<TapGestureHandler
  onHandlerStateChange={handleStateChange}
  onGestureEvent={handleGestureEvent}>
  <Reanimated.View
    style={{ width: 100, height: 100, backgroundColor: 'green' }}
  />
</TapGestureHandler>

您会在点击时看到它永远不会触发(“手势事件”)

【问题讨论】:

    标签: react-native-gesture-handler


    【解决方案1】:

    我也遇到过这个问题,手势处理程序中关于离散手势和连续手势的文档提到了它:

    Keep in mind that onGestureEvent is only generated in continuous gesture handlers and shouldn't be used in the TapGestureHandler and other discrete handlers.
    

    来源:https://docs.swmansion.com/react-native-gesture-handler/docs/about-handlers

    这很令人困惑,因为在 Reanimated 中使用 TapGestureHandler 的示例似乎使用了 onGestureEvent,但我发现自己处理状态更改是可行的方法。 好消息是,管理起来非常简单,因为它是一个独立的手势。

    【讨论】:

    • 这太棒了,谢谢你的分享!确实,使用 onGestureEvent 的 TapGestureHandler 示例让人非常困惑。
    猜你喜欢
    • 2014-05-15
    • 2021-05-22
    • 2015-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多