From 884d0d84ea72b2123ace12ed85b502f7726b9693 Mon Sep 17 00:00:00 2001 From: q404365631 Date: Fri, 24 Apr 2026 02:21:23 +0800 Subject: [PATCH] fix: reset drag state on pointer leave to prevent stuck transitions When the draggable prop is enabled and the pointer leaves the gallery area during a drag, the gallery previously remained in an in-between state because isDragging was never reset. This adds an onPointerLeave handler that mirrors the onPointerUp logic: it checks the swipe threshold and transitions to the nearest item, then resets all touch state. Closes #112 --- src/lib/components/gallery-main.jsx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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 (