aboutsummaryrefslogtreecommitdiff
path: root/src/services/gesture_service
diff options
context:
space:
mode:
authorTusooa Zhu <tusooa@kazv.moe>2021-08-02 21:19:04 -0400
committerTusooa Zhu <tusooa@kazv.moe>2022-03-13 12:00:44 -0400
commit6980e4ddf1aa8dfd8c3bba0ea6cc7de90f531ba9 (patch)
treebd015030e00b9b28cb3479c390469ce3a944e0c7 /src/services/gesture_service
parentcb19db1006e84d9429d57d8a574dfaa9980d8ca7 (diff)
Scale swipe threshold with viewport width
Diffstat (limited to 'src/services/gesture_service')
-rw-r--r--src/services/gesture_service/gesture_service.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/services/gesture_service/gesture_service.js b/src/services/gesture_service/gesture_service.js
index cd9e3ba2..97a26ba7 100644
--- a/src/services/gesture_service/gesture_service.js
+++ b/src/services/gesture_service/gesture_service.js
@@ -25,8 +25,8 @@ const project = (v1, v2) => {
return [scalar * v2[0], scalar * v2[1]]
}
-const debug = console.log
-// const debug = () => {}
+// const debug = console.log
+const debug = () => {}
// direction: either use the constants above or an arbitrary 2d vector.
// threshold: how many Px to move from touch origin before checking if the
@@ -92,7 +92,7 @@ class SwipeAndClickGesture {
this.swipeEndCallback = swipeEndCallback || nop
this.swipeCancelCallback = swipeCancelCallback || nop
this.swipelessClickCallback = swipelessClickCallback || nop
- this.threshold = threshold
+ this.threshold = typeof threshold === 'function' ? threshold : () => threshold
this.perpendicularTolerance = perpendicularTolerance
this._reset()
}
@@ -162,7 +162,10 @@ class SwipeAndClickGesture {
const delta = deltaCoord(this._startPos, coord)
const sign = (() => {
- if (vectorLength(delta) < this.threshold) {
+ debug(
+ 'threshold = ', this.threshold(),
+ 'vector len =', vectorLength(delta))
+ if (vectorLength(delta) < this.threshold()) {
return 0
}
// movement is opposite from direction