3

I want to add limitations on how far by Y axis can View be dragged inside other View. My onPanResponderMove looks something like this:

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 :)

wlukla
  • 83
  • 4

1 Answers1

0

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 ?). Otherwise you are still setting pan values, so View is still asking to move isn't it ?

CP3c0
  • 36
  • 4