react-native-reanimated
react-native-reanimated copied to clipboard
useAnimatedGestureHandler not Firing
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
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
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)
In your second example, you're still using console.log
in onGestureEvent
. Try passing there gestureHandler
you've got from useAnimatedGestureHandler()
.
In your second example, you're still using
console.log
inonGestureEvent
. Try passing theregestureHandler
you've got fromuseAnimatedGestureHandler()
.
Apologies, that is a typo, in my source code I am in fact passing it to useAnimatedGestureHandler(), updated in OP.
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.
Thanks for the response, unfortunately I have not brought in any other dependencies except for Reanimated and RNGH. Could still be related however.
Any ideas Im having this same exact issue
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.
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.
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.
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.
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.
Are there any updates on this?
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.