react-native-reanimated icon indicating copy to clipboard operation
react-native-reanimated copied to clipboard

useAnimatedGestureHandler not Firing

Open swushi opened this issue 3 years ago • 12 comments

onGestureEvent fires, but useAnimatedGestureHandler does not

The onGestureEvent prop from PanGestureHandler is firing as expected, but when forwarded to useAnimatedGestureHandler, I get nothing.

onGestureEvent firing:

return (
  <PanGestureHandler onGestureEvent={console.log}>
    <Animated.View style={[styles.container, animatedStyles]}>
      ...
    </Animated.View>
  </PanGestureHandler>
);

Logs

image

useAnimatedGestureHandler not doing anything:

//                                    not being called
const gestureHandler = useAnimatedGestureHandler({
  onFail: (event) => {
    console.log(event);
  },
  onStart: (event) => {
    console.log(event);
  },
  onCancel: (event) => {
    console.log(event);
  },
  onActive: (event) => {
    console.log(event);
  },
  onEnd: (event) => {
    console.log(event);
  },
  onFinish: (event) => {
    console.log(event);
  },

return (
  <PanGestureHandler onGestureEvent={gestureHandler}>
    <Animated.View style={[styles.container, animatedStyles]}>
      ...
    </Animated.View>
  </PanGestureHandler>
);

No Output

This is within a library that I am working on located on my GitHub page at RNBottomSheet

Package versions

  • expo: 40
  • React: 16.13.1
  • React Native: 0.63.4
  • React Native Reanimated: 2.0.0-rc.0
  • React Native Gesture Handler: 1.8.0

swushi avatar Mar 04 '21 00:03 swushi

Issue validator

The issue is invalid!

  • Section required but not found: description(for label 🐞 bug)
  • Section required but not found: steps to reproduce(for label 🐞 bug)
  • Section required but not found: expected behavior(for label 🐞 bug)
  • Section required but not found: actual behavior(for label 🐞 bug)

github-actions[bot] avatar Mar 04 '21 00:03 github-actions[bot]

In your second example, you're still using console.log in onGestureEvent. Try passing there gestureHandler you've got from useAnimatedGestureHandler().

jakub-gonet avatar Mar 04 '21 09:03 jakub-gonet

In your second example, you're still using console.log in onGestureEvent. Try passing there gestureHandler you've got from useAnimatedGestureHandler().

Apologies, that is a typo, in my source code I am in fact passing it to useAnimatedGestureHandler(), updated in OP.

swushi avatar Mar 04 '21 14:03 swushi

Don't know if this is of any help but I have virtually the same issue except that it only happens when a background task (background location) is running. I wanted to file a bug for some time but did not get to it yet. I am using Expo and Reanimated 2 RC0 and Expo Background Task.

silberistgold avatar Mar 04 '21 17:03 silberistgold

Thanks for the response, unfortunately I have not brought in any other dependencies except for Reanimated and RNGH. Could still be related however.

swushi avatar Mar 04 '21 17:03 swushi

Any ideas Im having this same exact issue

jcgertig avatar Sep 12 '21 09:09 jcgertig

Having similar issue on ios only and only after JS thread restart when different js modules are loaded next time. useAnimatedGestureHandler does not call anything but a simple callback function as onGestureEvent works fine.

TexxUkr avatar Nov 01 '21 13:11 TexxUkr

I see the same thing with Animated.event. Doesn't update animated values when the event is passed to onGestureEvent prop. onGestureEvent is definitely firing though.

I have tried this with versions 2.2.0, 2.1.0. It is working on 1.13.1.

MorganTrudeau avatar Nov 22 '21 02:11 MorganTrudeau

I am having the exact same issue using ~2.2.0 with expo. useAnimatedGestureHandler would not work until I built the app for production. I had no issues just passing a callback function to onGestureEvent though.

Smarticles101 avatar Dec 04 '21 02:12 Smarticles101

I am experiencing the same issue right now. Currently, I am tracking the state changes of PanGestureHandler, and once I click and drag the wrapped component, PanGestureHandler onHandlerStateChange logs that the state is changing as you would expect - never arriving at the fail state. However, useAnimatedGestureHandler is not firing at all meaning that the component position remains fixed. Surprisingly, everything works as intended when I force a reload of the app by typing 'r' in metro, but as soon as I close expo-go and start the app again, I experience the same problem.

IIsijola avatar Jan 01 '22 16:01 IIsijola

I am having the same issue. Any updates on your end?

"react": "17.0.2", "react-native": "0.68.2", "react-native-gesture-handler": "^2.4.2", "react-native-reanimated": "^2.8.0"

These are my only deps.

whaddafish avatar Jun 11 '22 09:06 whaddafish

Are there any updates on this?

mechaadi avatar Aug 04 '22 11:08 mechaadi

fwiw I was running into this same issue but found another post mentioning adding GestureHandlerRootView from react-native-gesture-handler as a parent component of <PanGestureHandler> which seems to have fixed the problem for me.

jdcorr avatar Aug 18 '22 18:08 jdcorr