javascript - PanGestureHandler 预期 `onGestureHandlerEvent` 监听器是一个函数

标签 javascript react-native react-native-reanimated react-native-gesture-handler react-native-reanimated-v2

使用 react-native-gesture-handler 中的 PanGestureHandlerreact-native-reanimated 以及 useAnimatedGestureHandler 抛出这个错误。

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

这些是正在渲染的组件,

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

点心,https://snack.expo.dev/4Mp-PfXPU

最佳答案

This comment在 GitHub 上指出了正确的方向。

虽然没有在文档中指定,但可以从示例中推断... PanGestureHandler <PanGestureHandler ...> 内需要一个动画组件子组件. (如<Animated.View ...>)

所以 <Animated.View ...>...</Animated.View> ,或其他一些动画组件,需要在 <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>

这是一份工作点心,

https://snack.expo.dev/ZRr6t24Hv

关于javascript - PanGestureHandler 预期 `onGestureHandlerEvent` 监听器是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72317760/

相关文章:

javascript - 为什么 jsperf 根据 HTML 和设置中的准备代码给出不同的结果?

javascript - 使用 Flot JQuery 库更改现有图上的轴最小值/最大值

javascript - 尝试使用javascript取消iPad2上的事件绑定(bind)

javascript - 如何使用expo打开日历事件创建屏幕?

javascript - 正则表达式中的批量转义

javascript - React native 无法将读取权限(电子邮件)传递给发布授权请求

react-native - react 导航 goBack() 并更新父状态

react-native - 使用 React Native Gesture Handler 和 Reanimated 检测滑动方向

javascript - 如何在 react-native-reanimated 中聆听值(value)变化?

javascript - React Native jest 26 到 jest 27 升级很痛苦,超时和动画