From bd4eaf9f8f95939e6781fd21792feec6af044e44 Mon Sep 17 00:00:00 2001 From: Dante Date: Wed, 24 Mar 2021 07:56:15 +0800 Subject: [PATCH] fix: corrected horizontal slip judgment (#8387) --- src/mixins/touch.js | 3 ++- test/event.ts | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/mixins/touch.js b/src/mixins/touch.js index 45f9190da..2ca378138 100644 --- a/src/mixins/touch.js +++ b/src/mixins/touch.js @@ -28,7 +28,8 @@ export const TouchMixin = { touchMove(event) { const touch = event.touches[0]; - this.deltaX = touch.clientX - this.startX; + // Fix: Safari back will set clientX to negative number + this.deltaX = touch.clientX < 0 ? 0 : touch.clientX - this.startX; this.deltaY = touch.clientY - this.startY; this.offsetX = Math.abs(this.deltaX); this.offsetY = Math.abs(this.deltaY); diff --git a/test/event.ts b/test/event.ts index 458523f9a..1fba3c324 100644 --- a/test/event.ts +++ b/test/event.ts @@ -48,10 +48,22 @@ export function trigger( // simulate drag gesture export function triggerDrag( el: Wrapper | HTMLElement, - x = 0, - y = 0 + relativeX = 0, + relativeY = 0 ): void { - 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);