Skip to content

Commit

Permalink
fix(useSwipe): add touchcancel callback (vitest-dev#633)
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Jul 25, 2021
1 parent e3a3ec9 commit ea08e27
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/core/useSwipe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ export function useSwipe(
else
listenerOptions = isPassiveEventSupported ? { passive: true } : { capture: false }

const onTouchEnd = (e: TouchEvent) => {
if (isSwiping.value)
onSwipeEnd?.(e, direction.value)

isSwiping.value = false
}

const stops = [
useEventListener(target, 'touchstart', (e: TouchEvent) => {
if (listenerOptions.capture && !listenerOptions.passive)
Expand All @@ -145,12 +152,8 @@ export function useSwipe(
onSwipe?.(e)
}, listenerOptions),

useEventListener(target, 'touchend', (e: TouchEvent) => {
if (isSwiping.value)
onSwipeEnd?.(e, direction.value)

isSwiping.value = false
}, listenerOptions),
useEventListener(target, 'touchend', onTouchEnd, listenerOptions),
useEventListener(target, 'touchcancel', onTouchEnd, listenerOptions),
]

const stop = () => stops.forEach(s => s())
Expand Down

0 comments on commit ea08e27

Please sign in to comment.