React native 使用React本机手势处理程序检测滑动方向并重新激活
我们已经使用React Native PanResponder开发了一个swiper(在有人评论之前)-我们不能在这里使用任何其他swiper库。在我们开发的swiper中,当用户结束swipe(意味着释放Pan)时,我们面临一个问题:启动spring动画时存在延迟 为了解决这个问题,我们正在尝试从解决用户所面临的滞后问题 但在与(PanGestureHandler)和 复活库,我们无法检测到在 手势处理程序 我正在添加我们用来在PanResponder中检测滑动方向的代码部分React native 使用React本机手势处理程序检测滑动方向并重新激活,react-native,react-native-reanimated,react-native-gesture-handler,React Native,React Native Reanimated,React Native Gesture Handler,我们已经使用React Native PanResponder开发了一个swiper(在有人评论之前)-我们不能在这里使用任何其他swiper库。在我们开发的swiper中,当用户结束swipe(意味着释放Pan)时,我们面临一个问题:启动spring动画时存在延迟 为了解决这个问题,我们正在尝试从解决用户所面临的滞后问题 但在与(PanGestureHandler)和 复活库,我们无法检测到在 手势处理程序 我正在添加我们用来在PanResponder中检测滑动方向的代码部分 onPanMov
onPanMoving = (evt, {dx}) => {
this.draggedEnd = dx < -this.swipeThreshold; //You are moving towards right screen
this.draggedStart = dx > this.swipeThreshold; //You are moving towards left screen
}
onPanMoving=(evt,{dx})=>{
this.draggedEnd=dx<-this.swipeThreshold;//您正在向右屏幕移动
this.draggedStart=dx>this.swipeThreshold;//您正在向左屏幕移动
}
如您所见,在PanResponder中,在平移移动时检测方向非常容易
手势处理程序的问题来了
当手势状态处于活动状态时,我无法检测到滑动
我已经在手势处理程序中搜索了问题,我发现了
该问题提出了两种解决办法
注意:我们不能使用和,因为我们需要在仍在手柄上的状态变化中找到方向,而Swipeables不使用Reanimated。在我的例子中,我曾经检测过方向。这对我很有用。通过属性
velocityX
例如:
const handleGesture = (evt) => {
const { nativeEvent } = evt;
if (nativeEvent.velocityX > 0) {
console.log('Swipe right');
} else {
console.log('Swipe left');
}
};
return (
<PanGestureHandler onGestureEvent={handleGesture}>
// child component
</PanGestureHandler>
);
const handletesture=(evt)=>{
const{nativeEvent}=evt;
如果(nativeEvent.velocityX>0){
console.log(“向右滑动”);
}否则{
console.log(“向左滑动”);
}
};
返回(
//子组件
);
*双重Flingesturehandler请注意,您始终可以找到您的答案。因此,没有必要使用注释来更新您的答案。