PanHandler expect onGestureHandler to be a function
See original GitHub issueDescription
I’m using <PanGestureHandler />
from react-native-gesture-handler@1.9.0
, and useAnimatedGestureHandler
from react-native-reanimated@2.0.0-rc.0
… the hook returns an object, and according to the docs I should just take what the hook returns and add it to the <PanGestureHander onGestureEvent={gestureHandler} />
… but I’m getting the following error
ERROR Error: Expected `onGestureHandlerEvent` listener to be a function, instead got a value of `object` type.
Code
export const AuctionDetails: React.FC<Props> = ({ route }) => {
const { auction } = route.params;
// ...
const onGestureEvent = useAnimatedGestureHandler({
onStart: () => {
isGestureActive.value = true;
},
onActive: ({ translationX, translationY }) => {
translateX.value = translationX;
translateY.value = translationY;
},
onEnd: ({ velocityX, velocityY }) => {
if (snapPoint(translateY.value, velocityY, [0, height]) === height) {
navigation.goBack();
} else {
translateX.value = withSpring(0, { velocity: velocityX });
translateY.value = withSpring(0, { velocity: velocityY });
}
isGestureActive.value = false;
},
});
// ...
return (
<PanGestureHandler onGestureEvent={onGestureEvent}>
<Animated.View style={containerStyle}>
<SharedElement id={auction.id} style={{ flex: 1 }}>
<Animated.View
style={[
{
...StyleSheet.absoluteFillObject,
width: undefined,
height: undefined,
},
imageStyle,
]}
>
<Image
source={auction.source}
style={StyleSheet.absoluteFillObject}
/>
</Animated.View>
</SharedElement>
</Animated.View>
</PanGestureHandler>
);
};
Package versions
- React: 16.13.1
- React Native: expo sdk 40
- React Native Reanimated: 2.0.0-rc.0
- React Native Gesture Handler: 1.9.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Expected onGestureHandlerEvent listener to be a function, ...
Using PanGestureHandler from react-native-gesture-handler with react-native-reanimated with useAnimatedGestureHandler throws this error.
Read more >Using the Gesture Handler in React Native | by SaidHayani
PanGestureHandler has many props but for now, we only need to use OnGestureEvent props to pass the gesture event, a callback function.
Read more >PanGestureHandler | React Native Gesture Handler
A continuous gesture handler that can recognize a panning (dragging) gesture and track its movement. The handler activates when a finger is placed...
Read more >React Native Animations with pan handler for touches and ...
... Animations with pan handler for touches and gestures.React native tutorial on how to create cool animations with pan gesture handler.
Read more >react-native-gesture-handler - npm
TapGestureHandler; LongPressGestureHandler; PanGestureHandler ... onActiveStateChange - function that gets triggered when button changes ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Essam-Harrous @StampixSMO If none of the clean & rebuild works, make sure you have
Animated.View
as the direct child to the<PanGestureHandler />
. That was the mistake I had few days ago.@chungweileong94 TY! Works like a charm!