From 69851d114a327b3bfefab0ab7ba9649b7b5a4b1a Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Wed, 29 Aug 2018 17:26:48 -0700 Subject: [PATCH] Using scroll-touch-edge to record the distance cause wheel event will only fire once each scroll since C69 mainly fix https://github.com/brave/browser-laptop/issues/15114 also fix https://github.com/brave/browser-laptop/issues/14871 fix https://github.com/brave/browser-laptop/issues/14829 fix https://github.com/brave/browser-laptop/issues/14785 Auditor: @bsclifton --- app/renderer/components/main/main.js | 49 +++++++++++----------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/app/renderer/components/main/main.js b/app/renderer/components/main/main.js index 2af195359ab..d886b8f592f 100644 --- a/app/renderer/components/main/main.js +++ b/app/renderer/components/main/main.js @@ -217,8 +217,6 @@ class Main extends React.Component { // Navigates back/forward on macOS two- and or three-finger swipe let trackingFingers = false let startTime = 0 - let isSwipeOnLeftEdge = false - let isSwipeOnRightEdge = false let deltaX = 0 let deltaY = 0 let time @@ -235,22 +233,6 @@ class Main extends React.Component { if (trackingFingers) { deltaX = deltaX + e.deltaX deltaY = deltaY + e.deltaY - const distanceThresholdX = getSetting(settings.SWIPE_NAV_DISTANCE) - const percent = Math.abs(deltaX) / distanceThresholdX - if (isSwipeOnRightEdge) { - if (percent > 1) { - appActions.swipedRight(1) - } else { - appActions.swipedRight(percent) - } - } else if (isSwipeOnLeftEdge) { - if (percent > 1) { - appActions.swipedLeft(1) - } else { - appActions.swipedLeft(percent) - } - } - time = (new Date()).getTime() - startTime } }, { passive: true }) @@ -259,9 +241,9 @@ class Main extends React.Component { const distanceThresholdY = 101 const timeThreshold = 80 if (trackingFingers && time > timeThreshold && Math.abs(deltaY) < distanceThresholdY) { - if (deltaX > distanceThresholdX && isSwipeOnRightEdge) { + if (deltaX > distanceThresholdX) { ipc.emit(messages.SHORTCUT_ACTIVE_FRAME_FORWARD) - } else if (deltaX < -distanceThresholdX && isSwipeOnLeftEdge) { + } else if (deltaX < -distanceThresholdX) { ipc.emit(messages.SHORTCUT_ACTIVE_FRAME_BACK) } } @@ -275,16 +257,23 @@ class Main extends React.Component { ipc.on('scroll-touch-edge', () => { if (trackingFingers) { - if (!isSwipeOnRightEdge && deltaX > 0) { - isSwipeOnRightEdge = true - isSwipeOnLeftEdge = false - time = 0 - deltaX = 0 - } else if (!isSwipeOnLeftEdge && deltaX < 0) { - isSwipeOnLeftEdge = true - isSwipeOnRightEdge = false - time = 0 - deltaX = 0 + const distanceThresholdX = getSetting(settings.SWIPE_NAV_DISTANCE) + const percent = Math.abs(deltaX) / distanceThresholdX + time = (new Date()).getTime() - startTime + if (deltaX > 0) { + if (percent > 1) { + appActions.swipedRight(1) + } else { + appActions.swipedRight(percent) + } + deltaX += 1 + } else if (deltaX < 0) { + if (percent > 1) { + appActions.swipedLeft(1) + } else { + appActions.swipedLeft(percent) + } + deltaX -= 1 } } })