question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PanHandler expect onGestureHandler to be a function

See original GitHub issue

Description

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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

26reactions
chungweileong94commented, Jun 14, 2021

@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.

0reactions
alphonse92commented, May 3, 2022

@chungweileong94 TY! Works like a charm!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found