From d0facb0fcd71f155eec9cb6086b050f085d0368b Mon Sep 17 00:00:00 2001 From: Limichange Date: Thu, 30 Aug 2018 14:27:23 +0800 Subject: [PATCH 1/2] refactor: simplified conditional expression --- src/components/tabs/index.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/components/tabs/index.js b/src/components/tabs/index.js index 26fe8d414..941f2bbb3 100644 --- a/src/components/tabs/index.js +++ b/src/components/tabs/index.js @@ -47,15 +47,19 @@ class AtTabs extends AtComponent { const { current } = this.props const touchMove = e.touches[0].pageX - // 向左滑动 - if (!this.isMoving && current + 1 < this.maxIndex && touchMove - this.touchDot <= -40 && this.time < 10) { - this.isMoving = true - this.handleClick(current + 1) - } - // 向右滑动 - if (!this.isMoving && current - 1 >= 0 && touchMove - this.touchDot >= 40 && this.time < 10) { - this.isMoving = true - this.handleClick(current - 1) + const moveDistance = Math.abs(touchMove - this.touchDot) + + if (!this.isMoving && this.time < 10 && moveDistance >= 40) { + // 向左滑动 + if (current + 1 < this.maxIndex) { + this.isMoving = true + this.handleClick(current + 1) + + // 向右滑动 + } else if (current - 1 >= 0) { + this.isMoving = true + this.handleClick(current - 1) + } } } From a2d6717b812a83c2888e4b049fb45934590edf4a Mon Sep 17 00:00:00 2001 From: Limichange Date: Thu, 30 Aug 2018 14:45:55 +0800 Subject: [PATCH 2/2] fix: remove `Math.abs` --- src/components/tabs/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/tabs/index.js b/src/components/tabs/index.js index 941f2bbb3..606e39fb6 100644 --- a/src/components/tabs/index.js +++ b/src/components/tabs/index.js @@ -47,16 +47,16 @@ class AtTabs extends AtComponent { const { current } = this.props const touchMove = e.touches[0].pageX - const moveDistance = Math.abs(touchMove - this.touchDot) + const moveDistance = touchMove - this.touchDot - if (!this.isMoving && this.time < 10 && moveDistance >= 40) { + if (!this.isMoving && this.time < 10) { // 向左滑动 - if (current + 1 < this.maxIndex) { + if (current + 1 < this.maxIndex && moveDistance <= -40) { this.isMoving = true this.handleClick(current + 1) // 向右滑动 - } else if (current - 1 >= 0) { + } else if (current - 1 >= 0 && moveDistance >= 40) { this.isMoving = true this.handleClick(current - 1) }