Skip to content

Commit

Permalink
fix(Swiper): fix a dragging gesture bug when imperatively call `jumpT…
Browse files Browse the repository at this point in the history
…o` in the `onClick` event of `Swiper.Item`
  • Loading branch information
awmleer committed Jul 27, 2022
1 parent 68f3692 commit be90116
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/components/swiper/swiper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,15 @@ export const Swiper = forwardRef<SwiperRef, SwiperProps>(
[count]
)

const forceDragCancelRef = useRef(() => {})

const bind = useDrag(
state => {
forceDragCancelRef.current = () => {
state.cancel()
setDragging(false)
}
if (!state.intentional) return
const slidePixels = getSlidePixels()
if (!slidePixels) return
const paramIndex = isVertical ? 1 : 0
Expand Down Expand Up @@ -181,6 +188,7 @@ export const Swiper = forwardRef<SwiperRef, SwiperProps>(
(position.get() / 100) * slidePixels,
]
},
triggerAllEvents: true,
bounds: () => {
if (loop) return {}
const slidePixels = getSlidePixels()
Expand Down Expand Up @@ -318,6 +326,7 @@ export const Swiper = forwardRef<SwiperRef, SwiperProps>(
if (draggingRef.current) {
e.stopPropagation()
}
forceDragCancelRef.current()
}}
{...(props.allowTouchMove ? bind() : {})}
>
Expand Down

0 comments on commit be90116

Please sign in to comment.