From dc4b7cd5c3c3129feb1ba2ee1da93a4fde73b94d Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 13 Apr 2018 10:13:51 +0800 Subject: [PATCH] [bugfix] CellSwipe: only trigger swipe when drag horizontally (#866) --- packages/cell-swipe/index.vue | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/cell-swipe/index.vue b/packages/cell-swipe/index.vue index f80d3547b..221dc3411 100644 --- a/packages/cell-swipe/index.vue +++ b/packages/cell-swipe/index.vue @@ -96,8 +96,9 @@ export default create({ startDrag(event) { this.draging = true; - this.startX = event.touches[0].pageX; - this.startY = event.touches[0].pageY; + this.direction = ''; + this.startX = event.touches[0].clientX; + this.startY = event.touches[0].clientY; if (this.opened) { this.startX -= this.offset; @@ -105,8 +106,9 @@ export default create({ }, onDrag(event) { - const offsetTop = event.touches[0].pageY - this.startY; - const offsetLeft = event.touches[0].pageX - this.startX; + const offsetTop = event.touches[0].clientY - this.startY; + const offsetLeft = event.touches[0].clientX - this.startX; + if ((offsetLeft < 0 && -offsetLeft > this.rightWidth) || (offsetLeft > 0 && offsetLeft > this.leftWidth) || (offsetLeft > 0 && !this.leftWidth) || @@ -117,7 +119,9 @@ export default create({ const y = Math.abs(offsetTop); const x = Math.abs(offsetLeft); const swiping = !(x < 5 || (x >= 5 && y >= x * 1.73)); - if (swiping) { + this.direction = this.direction || this.getDirection(event.touches[0]); + + if (swiping && this.direction === 'horizontal') { event.preventDefault(); this.swipeMove(offsetLeft); }; @@ -130,6 +134,12 @@ export default create({ }; }, + getDirection(touch) { + const offsetX = Math.abs(touch.clientX - this.startX); + const offsetY = Math.abs(touch.clientY - this.startY); + return offsetX > offsetY ? 'horizontal' : offsetX < offsetY ? 'vertical' : ''; + }, + onClick(position = 'outside') { if (!this.offset) { return;