diff --git a/src/lib/components/gallery-main.jsx b/src/lib/components/gallery-main.jsx index d0fa8b6..577d7b7 100644 --- a/src/lib/components/gallery-main.jsx +++ b/src/lib/components/gallery-main.jsx @@ -119,12 +119,41 @@ export const GalleryMain = ({ renderGalleryItem, className, ...props }) => { previous, ]) + const handlePointerLeave = useCallback(() => { + if (!draggable) return + + if (touchState.isDragging) { + if (Math.abs(touchState.xOffset) > swipeThreshold) { + if (touchState.xOffset < 0) next() + else previous() + } + + setTouchState((prevState) => ({ + ...prevState, + isDragging: false, + xOffset: 0, + start: 0, + offsetting: false, + scrolling: false, + })) + } + }, [ + draggable, + touchState.isDragging, + touchState.xOffset, + swipeThreshold, + setTouchState, + next, + previous, + ]) + return (