简体   繁体   English

React Native:是否可以在 onPanResponderMove 中停止 PanResponder 事件?

[英]React Native: is it possible to stop PanResponder event inside onPanResponderMove?

I want to add limitations on how far by Y axis can View be dragged inside other View.我想添加对 Y 轴可以将 View 拖动到其他 View 内多远的限制。 My onPanResponderMove looks something like this:我的 onPanResponderMove 看起来像这样:

onPanResponderMove: (evt: any, gestureEvent: any) => {
  if (y >= 0 && y <= backgroundHeight - 40) {
    Animated.event([null, { dx: pan.x, dy: pan.y }], { useNativeDriver: false })(evt, gestureEvent);
  } else if (y < 0) {
    pan.setValue({ x: pan.x._value, y: 0 });
  } else {
    pan.setValue({ x: pan.x._value, y: backgroundHeight - 40 });
  }
}

So now inner View still draggs when its scrolled further limitations and goes back (looks like it's shaking).所以现在内部视图在滚动进一步限制并返回时仍然会拖动(看起来它在摇晃)。 And I want drag stop on hitting these limitations and don't know how.而且我希望在达到这些限制时停止拖动并且不知道如何。

If there is another better solution, that can be implemented, I'd much appreciate your help:)如果有其他更好的解决方案可以实施,我将非常感谢您的帮助:)

Did you manage to get it working the way you want?你设法让它按照你想要的方式工作吗? I came across your question to achieve the same, and managed to do so just with:我遇到了你的问题来达到同样的效果,并设法做到了:

onPanResponderMove: (e, gs) => {
        if (gs.moveY < yOffset) {
          Animated.event([null, {dx: 0, dy: pan.y}], {
            useNativeDriver: false,
          })(e, gs);
        }
      },

So no else after and my image stays while finger is outbound (2D for me, but looks like it's the same?).所以之后没有else了,我的图像在手指出站时保持不变(对我来说是 2D,但看起来是一样的?)。 Otherwise you are still setting pan values, so View is still asking to move isn't it?否则你仍然在设置平移值,所以 View 仍然要求移动,不是吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM