diff --git a/src/composables/use-touch.ts b/src/composables/use-touch.ts index 7becdd053..86c28d056 100644 --- a/src/composables/use-touch.ts +++ b/src/composables/use-touch.ts @@ -42,7 +42,8 @@ export function useTouch() { const move = ((event: TouchEvent) => { const touch = event.touches[0]; - deltaX.value = touch.clientX - startX.value; + // Fix: Safari back will set clientX to negative number + deltaX.value = touch.clientX < 0 ? 0 : touch.clientX - startX.value; deltaY.value = touch.clientY - startY.value; offsetX.value = Math.abs(deltaX.value); offsetY.value = Math.abs(deltaY.value); diff --git a/test/event.ts b/test/event.ts index ae8b7f94a..6c73e2a8e 100644 --- a/test/event.ts +++ b/test/event.ts @@ -57,10 +57,22 @@ export function triggerDrag( | VueWrapper> | DOMWrapper | HTMLElement, - x = 0, - y = 0 + relativeX = 0, + relativeY = 0 ) { - trigger(el, 'touchstart', 0, 0); + let x = relativeX; + let y = relativeY; + let startX = 0; + let startY = 0; + if (relativeX < 0) { + startX = Math.abs(relativeX); + x = 0; + } + if (relativeY < 0) { + startY = Math.abs(relativeY); + y = 0; + } + trigger(el, 'touchstart', startX, startY); trigger(el, 'touchmove', x / 4, y / 4); trigger(el, 'touchmove', x / 3, y / 3); trigger(el, 'touchmove', x / 2, y / 2);