最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - PanGestureHandler Expected `onGestureHandlerEvent` listener to be a function - Stack Overflow

programmeradmin0浏览0评论

Using PanGestureHandler from react-native-gesture-handler with react-native-reanimated with useAnimatedGestureHandler throws this error.

Expected onGestureHandlerEvent listener to be a function, instead got a value of object type

These are the ponents being rendered,

<View style={[styles.center]}>
  <Text style={{color: "#555", fontSize:16, marginTop: 120, marginBottom: 70, width: 250, margin: 'auto'}}>Works on the web but throws an error on iOS.</Text>

  <Animated.View style={[styles.box, styles.center, animatedStyle]}>
    <PanGestureHandler onGestureEvent={gestureHandler}>
      <Text style={{color: "#444", fontWeight:'bold', padding: 16,}}>Drag me around</Text>
    </PanGestureHandler>
  </Animated.View>
</View>;

Snack here, /4Mp-PfXPU

Using PanGestureHandler from react-native-gesture-handler with react-native-reanimated with useAnimatedGestureHandler throws this error.

Expected onGestureHandlerEvent listener to be a function, instead got a value of object type

These are the ponents being rendered,

<View style={[styles.center]}>
  <Text style={{color: "#555", fontSize:16, marginTop: 120, marginBottom: 70, width: 250, margin: 'auto'}}>Works on the web but throws an error on iOS.</Text>

  <Animated.View style={[styles.box, styles.center, animatedStyle]}>
    <PanGestureHandler onGestureEvent={gestureHandler}>
      <Text style={{color: "#444", fontWeight:'bold', padding: 16,}}>Drag me around</Text>
    </PanGestureHandler>
  </Animated.View>
</View>;

Snack here, https://snack.expo.dev/4Mp-PfXPU

Share Improve this question asked May 20, 2022 at 10:55 shrameeshramee 5,0992 gold badges25 silver badges48 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

This ment on GitHub points in the correct direction.

Though not specified in the docs, but can be inferred from the examples... PanGestureHandler requires an animated ponent child inside <PanGestureHandler ...>. (Such as <Animated.View ...>)

So <Animated.View ...>...</Animated.View>, or some other animated ponent, needs to be inside <PanGestureHandler onGestureEvent={gestureHandler}>.

<PanGestureHandler onGestureEvent={gestureHandler}>
  <Animated.View style={[styles.box, styles.center, animatedStyle]}>
      <Text style={{color: "#444", fontWeight:'bold', padding: 16,}}>Drag me around</Text>
  </Animated.View>
</PanGestureHandler>

Here's a working snack,

https://snack.expo.dev/ZRr6t24Hv

发布评论

评论列表(0)

  1. 暂无评论