Search code examples
react-native-gesture-handler

Does onGestureEvent of TapGestureHandler never fire?


Here is a Snack of the issue below - https://snack.expo.io/@noitidart/tapgesturehandler-ongestureevent

Does onGestureEvent for TapGestureHandler never trigger? The docs do not make this clear. This seems to be happening to me:

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>

You will see on tap it never triggers ('gesture event')


Solution

  • I ran into this as well, the docs in gesture handler on discrete vs continuous gestures mentions it:

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

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

    This is very confusing since examples using TapGestureHandler in Reanimated appear to use onGestureEvent, but I have found that handling the state change myself is the way to go. Good news is, it is incredibly simple to manage since it is a discrete gesture.