我一直在努力让 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)
我怎么能让这个工作?
提前致谢