react-native-draggable-grid icon indicating copy to clipboard operation
react-native-draggable-grid copied to clipboard

Scrolling When Hitting End of Scrollview

Open harryrein3 opened this issue 2 years ago • 3 comments

Hello, I have a list of 25 items that are each 25% of the screen height. When I try to move the first item to the 10th spot, the containing scrollview does not scroll when you hit the bottom of the parent view.

Have you handled this case in your solution?

I built a custom "auto-scroller", but the issue is when you scroll the scrollview behind the scenes, the cell being dragged also scrolls since the positioning seems relative to the scrollview.

  const [startDragPosition, setStartDragPosition] = useState(scrollViewRefScrollY);
  const [isAutoDragging, setIsAutoDragging] = useState(false);
  const [dragDistance, setDragDistance] = useState(scrollViewRefScrollY);
  const handleAutoScroll = data => {
   if (!enableAutoScroll || isAutoDragging) return;
   const screenHeightRatio = (100 * data.moveY) / DEVICE.height;
   const isNearTop = screenHeightRatio < 20;
   const isNearBottom = screenHeightRatio > 80;

    if (isNearTop) {
      const totalDragDistance = dragDistance - 200;
      setIsAutoDragging(true);
      scrollViewRef?.current?.scrollTo({ y: startDragPosition + totalDragDistance, animated: true });
      setTimeout(() => setIsAutoDragging(false), 200);
      setDragDistance(totalDragDistance);
    }
    if (isNearBottom) {
      const totalDragDistance = dragDistance + 200;
      setIsAutoDragging(true);
      scrollViewRef?.current?.scrollTo({ y: startDragPosition + totalDragDistance, animated: true });
      setTimeout(() => setIsAutoDragging(false), 200);
      setDragDistance(totalDragDistance);
    }
  };

Can you assist?

harryrein3 avatar Feb 17 '23 14:02 harryrein3

Any update on the above one? If so kindly assist

arunvignesh-foodhub avatar Aug 16 '23 10:08 arunvignesh-foodhub

Nothing yet, waiting on a solution as well

harryrein3 avatar Aug 16 '23 15:08 harryrein3

Have anybody found the solution?

MianIbrarHussain avatar Oct 23 '23 17:10 MianIbrarHussain