From 9c16a6ad2bef05201e2e0136143470072906fc02 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 23 Dec 2021 17:24:20 +0800 Subject: [PATCH] fix(PullRefresh): may trigger browser bounce in some cases (#10090) --- src/mixins/touch.js | 20 +++++++++++++------- src/swipe/index.js | 10 +--------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/mixins/touch.js b/src/mixins/touch.js index 2ca378138..b7e607221 100644 --- a/src/mixins/touch.js +++ b/src/mixins/touch.js @@ -1,13 +1,11 @@ import { on } from '../utils/dom/event'; -const MIN_DISTANCE = 10; - function getDirection(x, y) { - if (x > y && x > MIN_DISTANCE) { + if (x > y) { return 'horizontal'; } - if (y > x && y > MIN_DISTANCE) { + if (y > x) { return 'vertical'; } @@ -28,13 +26,21 @@ export const TouchMixin = { touchMove(event) { const touch = event.touches[0]; - // Fix: Safari back will set clientX to negative number + // 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); - this.direction = - this.direction || getDirection(this.offsetX, this.offsetY); + + // lock direction when distance is greater than a certain value + const LOCK_DIRECTION_DISTANCE = 10; + if ( + !this.direction || + (this.offsetX < LOCK_DIRECTION_DISTANCE && + this.offsetY < LOCK_DIRECTION_DISTANCE) + ) { + this.direction = getDirection(this.offsetX, this.offsetY); + } }, resetTouchStatus() { diff --git a/src/swipe/index.js b/src/swipe/index.js index 01b841964..401db97cd 100644 --- a/src/swipe/index.js +++ b/src/swipe/index.js @@ -210,16 +210,8 @@ export default createComponent({ this.touchMove(event); - // if user starting to touchmove, prevent the event bubbling to - // avoid affecting the parent components - const shouldPrevent = - this.isCorrectDirection || - this.offsetY > this.offsetX === this.vertical; - if (shouldPrevent) { - preventDefault(event, this.stopPropagation); - } - if (this.isCorrectDirection) { + preventDefault(event, this.stopPropagation); this.move({ offset: this.delta }); } },