react-native-draggable-grid
react-native-draggable-grid copied to clipboard
Scrolling When Hitting End of Scrollview
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?
Any update on the above one? If so kindly assist
Nothing yet, waiting on a solution as well
Have anybody found the solution?