小编ire*_*sum的帖子

将 PanResponder 与 Animated.event 结合使用

我一直在努力让 PanResponder 以我需要的方式工作。我有一个包含圆圈的视图,当我在该视图上移动手指时,我希望圆圈跟随我。

结构

<View {...this.panResponder.panHandlers}>
   <Animated.Circle />
</View>
Run Code Online (Sandbox Code Playgroud)

现在,所有教程都显示以下内容

onPanResponderMove: Animated.event([
  null, {dx: this.state.pan.x, dy: this.state.pan.y},
]),
Run Code Online (Sandbox Code Playgroud)

而这个工作绝对没问题,我的问题是,我需要内更多的逻辑onPanResponderMove,每一次我尝试使用Animated.event它什么都不做的函数中。下面是函数的一个例子:

onPanResponderMove: (e, gestureState) => {
  /* some other logic that I need here */

  const { dx, dy } = gestureState;
  Animated.event([null, {dx: this.state.pan.x, dy: this.state.pan.y}]);
},
Run Code Online (Sandbox Code Playgroud)

我怎么能让这个工作?

提前致谢

animation react-native

8
推荐指数
2
解决办法
3342
查看次数

标签 统计

animation ×1

react-native ×1