From 2ae9e4ef3becb1c2995576c497a9eca1a503e134 Mon Sep 17 00:00:00 2001 From: Hunter Perrin Date: Sun, 3 Dec 2023 09:28:28 -0800 Subject: [PATCH] Fix diagonal swipe calculations. --- DemoSwipeable.js | 45 ++++++++++++++++++++++----------- README.md | 9 ++++--- dist/TinyGesture.js | 35 +++++++++++++++++--------- dist/TinyGesture.js.map | 2 +- src/TinyGesture.ts | 56 +++++++++++++++++++++++++++-------------- 5 files changed, 96 insertions(+), 51 deletions(-) diff --git a/DemoSwipeable.js b/DemoSwipeable.js index bb0a78d..e450c00 100644 --- a/DemoSwipeable.js +++ b/DemoSwipeable.js @@ -5,8 +5,9 @@ import { addTransition, removeTransition } from './DemoTransitions.js'; * This function can be used as a Svelte action. */ export default function Swipeable(node) { - const gesture = new TinyGesture(node); - let timeout; + const gesture = new TinyGesture(node, { diagonalSwipes: true }); + let goRaf; + let backTimeout; const preventDefault = (event) => { event.preventDefault(); }; @@ -16,26 +17,39 @@ export default function Swipeable(node) { // Don't allow the page to scroll when the target is first pressed. node.addEventListener('touchstart', preventDefault, { passive: false }); + let xpos = 0; + let ypos = 0; + + function doTransform() { + node.style.transform = `perspective(1000px) translate3d(${xpos}px, ${ypos}px, 0)`; + clearTimeout(backTimeout); + backTimeout = setTimeout(() => { + xpos = 0; + ypos = 0; + node.style.transform = ''; + }, 1000); + } + // When the target is swiped, fling it really far in that direction before coming back to origin. gesture.on('swiperight', () => { - node.style.transform = 'perspective(1000px) translate3d(2000px, 0, 0)'; - clearTimeout(timeout); - setTimeout(() => (node.style.transform = ''), 1000); + xpos = 2000; + cancelAnimationFrame(goRaf); + goRaf = requestAnimationFrame(doTransform); }); gesture.on('swipeleft', () => { - node.style.transform = 'perspective(1000px) translate3d(-2000px, 0, 0)'; - clearTimeout(timeout); - setTimeout(() => (node.style.transform = ''), 1000); + xpos = -2000; + cancelAnimationFrame(goRaf); + goRaf = requestAnimationFrame(doTransform); }); gesture.on('swipeup', () => { - node.style.transform = 'perspective(1000px) translate3d(0, -2000px, 0)'; - clearTimeout(timeout); - setTimeout(() => (node.style.transform = ''), 1000); + ypos = -2000; + cancelAnimationFrame(goRaf); + goRaf = requestAnimationFrame(doTransform); }); gesture.on('swipedown', () => { - node.style.transform = 'perspective(1000px) translate3d(0, 2000px, 0)'; - clearTimeout(timeout); - setTimeout(() => (node.style.transform = ''), 1000); + ypos = 2000; + cancelAnimationFrame(goRaf); + goRaf = requestAnimationFrame(doTransform); }); return { @@ -43,7 +57,8 @@ export default function Swipeable(node) { node.removeEventListener('touchstart', preventDefault, { passive: false, }); - clearTimeout(timeout); + cancelAnimationFrame(goRaf); + clearTimeout(backTimeout); node.style.transform = ''; removeTransition(node, 'transform'); gesture.destroy(); diff --git a/README.md b/README.md index 457c792..bce703b 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ const options = { 0.15 * (type === 'x' ? window.innerWidth || document.body.clientWidth - : window.innerHeight || document.body.clientHeight) - ) + : window.innerHeight || document.body.clientHeight), + ), ), // Minimum velocity the gesture must be moving when the gesture ends to be // considered a swipe. @@ -46,8 +46,9 @@ const options = { // If false, whichever direction the pointer moved more will be the only swipe // fired. diagonalSwipes: false, - // The degree limit to consider a swipe when diagonalSwipes is true. - diagonalLimit: Math.tan(((45 * 1.5) / 180) * Math.PI), + // The degree limit to consider a diagonal swipe when diagonalSwipes is true. + // It's calculated as 45deg±diagonalLimit. + diagonalLimit: 15, // Listen to mouse events in addition to touch events. (For desktop support.) mouseSupport: true, }; diff --git a/dist/TinyGesture.js b/dist/TinyGesture.js index 619ea60..b691917 100644 --- a/dist/TinyGesture.js +++ b/dist/TinyGesture.js @@ -142,33 +142,44 @@ class TinyGesture { const absX = Math.abs(x); const y = this.touchEndY - ((_c = this.touchStartY) !== null && _c !== void 0 ? _c : 0); const absY = Math.abs(y); - if (absX > this.thresholdX || absY > this.thresholdY) { - this.swipedHorizontal = this.opts.diagonalSwipes - ? Math.abs(x / y) <= this.opts.diagonalLimit - : absX >= absY && absX > this.thresholdX; - this.swipedVertical = this.opts.diagonalSwipes - ? Math.abs(y / x) <= this.opts.diagonalLimit - : absY > absX && absY > this.thresholdY; + const distance = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); + const absDistance = Math.abs(distance); + const diagonal = absY / absX; + if (absX > this.thresholdX || + absY > this.thresholdY || + (this.opts.diagonalSwipes && (absDistance > this.thresholdX || absDistance > this.thresholdY))) { + this.swipedHorizontal = absX > this.thresholdX || (this.opts.diagonalSwipes && absDistance > this.thresholdX); + this.swipedVertical = absY > this.thresholdY || (this.opts.diagonalSwipes && absDistance > this.thresholdY); + if (!this.opts.diagonalSwipes || + diagonal < Math.tan(((45 - this.opts.diagonalLimit) * Math.PI) / 180) || + diagonal > Math.tan(((45 + this.opts.diagonalLimit) * Math.PI) / 180)) { + if (absX >= absY) { + this.swipedVertical = false; + } + if (absY > absX) { + this.swipedHorizontal = false; + } + } if (this.swipedHorizontal) { if (x < 0) { - if (((_d = this.velocityX) !== null && _d !== void 0 ? _d : 0) < -this.opts.velocityThreshold || x < -this.disregardVelocityThresholdX) { + if (((_d = this.velocityX) !== null && _d !== void 0 ? _d : 0) < -this.opts.velocityThreshold || distance < -this.disregardVelocityThresholdX) { this.fire('swipeleft', event); } } else { - if (((_e = this.velocityX) !== null && _e !== void 0 ? _e : 0) > this.opts.velocityThreshold || x > this.disregardVelocityThresholdX) { + if (((_e = this.velocityX) !== null && _e !== void 0 ? _e : 0) > this.opts.velocityThreshold || distance > this.disregardVelocityThresholdX) { this.fire('swiperight', event); } } } if (this.swipedVertical) { if (y < 0) { - if (((_f = this.velocityY) !== null && _f !== void 0 ? _f : 0) < -this.opts.velocityThreshold || y < -this.disregardVelocityThresholdY) { + if (((_f = this.velocityY) !== null && _f !== void 0 ? _f : 0) < -this.opts.velocityThreshold || distance < -this.disregardVelocityThresholdY) { this.fire('swipeup', event); } } else { - if (((_g = this.velocityY) !== null && _g !== void 0 ? _g : 0) > this.opts.velocityThreshold || y > this.disregardVelocityThresholdY) { + if (((_g = this.velocityY) !== null && _g !== void 0 ? _g : 0) > this.opts.velocityThreshold || distance > this.disregardVelocityThresholdY) { this.fire('swipedown', event); } } @@ -197,7 +208,7 @@ TinyGesture.defaults = { disregardVelocityThreshold: (type, self) => Math.floor(0.5 * (type === 'x' ? self.element.clientWidth : self.element.clientHeight)), pressThreshold: 8, diagonalSwipes: false, - diagonalLimit: Math.tan(((45 * 1.5) / 180) * Math.PI), + diagonalLimit: 15, longPressTime: 500, doubleTapTime: 300, mouseSupport: true, diff --git a/dist/TinyGesture.js.map b/dist/TinyGesture.js.map index fc90bbf..c4ad367 100644 --- a/dist/TinyGesture.js.map +++ b/dist/TinyGesture.js.map @@ -1 +1 @@ -{"version":3,"file":"TinyGesture.js","sourceRoot":"","sources":["../src/TinyGesture.ts"],"names":[],"mappings":"AASA,MAAqB,WAAW;IA2C9B,YAAmB,OAAgB,EAAE,OAAmC;QAArD,YAAO,GAAP,OAAO,CAAS;QAzC5B,gBAAW,GAAkB,IAAI,CAAC;QAClC,gBAAW,GAAkB,IAAI,CAAC;QAClC,cAAS,GAAkB,IAAI,CAAC;QAChC,cAAS,GAAkB,IAAI,CAAC;QAChC,eAAU,GAAkB,IAAI,CAAC;QACjC,eAAU,GAAkB,IAAI,CAAC;QACjC,cAAS,GAAkB,IAAI,CAAC;QAChC,cAAS,GAAkB,IAAI,CAAC;QAEhC,mBAAc,GAAkB,IAAI,CAAC;QACrC,mBAAc,GAAkB,IAAI,CAAC;QAErC,qBAAgB,GAAY,KAAK,CAAC;QAClC,eAAU,GAAW,CAAC,CAAC;QACvB,eAAU,GAAW,CAAC,CAAC;QACvB,gCAA2B,GAAW,CAAC,CAAC;QACxC,gCAA2B,GAAW,CAAC,CAAC;QAExC,sBAAiB,GAAY,KAAK,CAAC;QACnC,oBAAe,GAAY,KAAK,CAAC;QACjC,qBAAgB,GAA4B,IAAI,CAAC;QACjD,qBAAgB,GAAY,KAAK,CAAC;QAClC,mBAAc,GAAY,KAAK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E,GAAG;IAClB,aAAa,EAAE,GAAG;IAClB,YAAY,EAAE,IAAI;CACnB,AApBc,CAoBb;eAnOiB,WAAW;AAuQhC,IAAI,kBAAkB,GAA8B,KAAK,CAAC;AAE1D,IAAI;IACF,MAAM,CAAC,gBAAgB,CACrB,MAAM,EACN,IAAW,EACX,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,SAAS,EAAE;QACnC,GAAG,EAAE;YACH,kBAAkB,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACzC,CAAC;KACF,CAAC,CACH,CAAC;CACH;AAAC,OAAO,GAAG,EAAE,GAAE"} \ No newline at end of file +{"version":3,"file":"TinyGesture.js","sourceRoot":"","sources":["../src/TinyGesture.ts"],"names":[],"mappings":"AASA,MAAqB,WAAW;IA2C9B,YACS,OAAgB,EACvB,OAAmC;QAD5B,YAAO,GAAP,OAAO,CAAS;QA1ClB,gBAAW,GAAkB,IAAI,CAAC;QAClC,gBAAW,GAAkB,IAAI,CAAC;QAClC,cAAS,GAAkB,IAAI,CAAC;QAChC,cAAS,GAAkB,IAAI,CAAC;QAChC,eAAU,GAAkB,IAAI,CAAC;QACjC,eAAU,GAAkB,IAAI,CAAC;QACjC,cAAS,GAAkB,IAAI,CAAC;QAChC,cAAS,GAAkB,IAAI,CAAC;QAEhC,mBAAc,GAAkB,IAAI,CAAC;QACrC,mBAAc,GAAkB,IAAI,CAAC;QAErC,qBAAgB,GAAY,KAAK,CAAC;QAClC,eAAU,GAAW,CAAC,CAAC;QACvB,eAAU,GAAW,CAAC,CAAC;QACvB,gCAA2B,GAAW,CAAC,CAAC;QACxC,gCAA2B,GAAW,CAAC,CAAC;QAExC,sBAAiB,GAAY,KAAK,CAAC;QACnC,oBAAe,GAAY,KAAK,CAAC;QACjC,qBAAgB,GAA4B,IAAI,CAAC;QACjD,qBAAgB,GAAY,KAAK,CAAC;QAClC,mBAAc,GAAY,KAAK,CAAC;QAEhC,aAAQ,GAAa;YAC1B,QAAQ,EAA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AAE,EAAE,CACzB,IAAI,CAAC,GAAG,CACN,EAAE,EACF,IAAI,CAAC,KAAK,CACR,IAAI;QACF,CAAC,IAAI,KAAK,GAAG;YACX,CAAC,CAAC,MAAM,CAAC,UAAU,IAAI,QAAQ,CAAC,IAAI,CAAC,WAAW;YAChD,CAAC,CAAC,MAAM,CAAC,WAAW,IAAI,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CACxD,CACF;IACH,iBAAiB,EAAE,EAAE;IACrB,0BAA0B,EAAE,CAAC,IAAI,EAAE,IAAiB,EAAE,EAAE,CACtD,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACzF,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE,KAAK;IACrB,aAAa,EAAE,EAAE;IACjB,aAAa,EAAE,GAAG;IAClB,aAAa,EAAE,GAAG;IAClB,YAAY,EAAE,IAAI;CACnB,AApBc,CAoBb;eArPiB,WAAW;AAyRhC,IAAI,kBAAkB,GAA8B,KAAK,CAAC;AAE1D,IAAI;IACF,MAAM,CAAC,gBAAgB,CACrB,MAAM,EACN,IAAW,EACX,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,SAAS,EAAE;QACnC,GAAG,EAAE;YACH,kBAAkB,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACzC,CAAC;KACF,CAAC,CACH,CAAC;CACH;AAAC,OAAO,GAAG,EAAE,GAAE"} \ No newline at end of file diff --git a/src/TinyGesture.ts b/src/TinyGesture.ts index 1f8e6de..c88865f 100644 --- a/src/TinyGesture.ts +++ b/src/TinyGesture.ts @@ -46,11 +46,14 @@ export default class TinyGesture { longpress: [], }; - private _onTouchStart: typeof this['onTouchStart'] = this.onTouchStart.bind(this); - private _onTouchMove: typeof this['onTouchMove'] = this.onTouchMove.bind(this); - private _onTouchEnd: typeof this['onTouchEnd'] = this.onTouchEnd.bind(this); + private _onTouchStart: (typeof this)['onTouchStart'] = this.onTouchStart.bind(this); + private _onTouchMove: (typeof this)['onTouchMove'] = this.onTouchMove.bind(this); + private _onTouchEnd: (typeof this)['onTouchEnd'] = this.onTouchEnd.bind(this); - constructor(public element: Element, options?: Partial>) { + constructor( + public element: Element, + options?: Partial>, + ) { this.opts = Object.assign({}, TinyGesture.defaults, options); this.element.addEventListener('touchstart', this._onTouchStart, passiveIfSupported); this.element.addEventListener('touchmove', this._onTouchMove, passiveIfSupported); @@ -166,23 +169,38 @@ export default class TinyGesture { const absX = Math.abs(x); const y = this.touchEndY - (this.touchStartY ?? 0); const absY = Math.abs(y); + const distance = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); + const absDistance = Math.abs(distance); + const diagonal = absY / absX; - if (absX > this.thresholdX || absY > this.thresholdY) { - this.swipedHorizontal = this.opts.diagonalSwipes - ? Math.abs(x / y) <= this.opts.diagonalLimit - : absX >= absY && absX > this.thresholdX; - this.swipedVertical = this.opts.diagonalSwipes - ? Math.abs(y / x) <= this.opts.diagonalLimit - : absY > absX && absY > this.thresholdY; + if ( + absX > this.thresholdX || + absY > this.thresholdY || + (this.opts.diagonalSwipes && (absDistance > this.thresholdX || absDistance > this.thresholdY)) + ) { + this.swipedHorizontal = absX > this.thresholdX || (this.opts.diagonalSwipes && absDistance > this.thresholdX); + this.swipedVertical = absY > this.thresholdY || (this.opts.diagonalSwipes && absDistance > this.thresholdY); + if ( + !this.opts.diagonalSwipes || + diagonal < Math.tan(((45 - this.opts.diagonalLimit) * Math.PI) / 180) || + diagonal > Math.tan(((45 + this.opts.diagonalLimit) * Math.PI) / 180) + ) { + if (absX >= absY) { + this.swipedVertical = false; + } + if (absY > absX) { + this.swipedHorizontal = false; + } + } if (this.swipedHorizontal) { if (x < 0) { // Left swipe. - if ((this.velocityX ?? 0) < -this.opts.velocityThreshold || x < -this.disregardVelocityThresholdX) { + if ((this.velocityX ?? 0) < -this.opts.velocityThreshold || distance < -this.disregardVelocityThresholdX) { this.fire('swipeleft', event); } } else { // Right swipe. - if ((this.velocityX ?? 0) > this.opts.velocityThreshold || x > this.disregardVelocityThresholdX) { + if ((this.velocityX ?? 0) > this.opts.velocityThreshold || distance > this.disregardVelocityThresholdX) { this.fire('swiperight', event); } } @@ -190,12 +208,12 @@ export default class TinyGesture { if (this.swipedVertical) { if (y < 0) { // Upward swipe. - if ((this.velocityY ?? 0) < -this.opts.velocityThreshold || y < -this.disregardVelocityThresholdY) { + if ((this.velocityY ?? 0) < -this.opts.velocityThreshold || distance < -this.disregardVelocityThresholdY) { this.fire('swipeup', event); } } else { // Downward swipe. - if ((this.velocityY ?? 0) > this.opts.velocityThreshold || y > this.disregardVelocityThresholdY) { + if ((this.velocityY ?? 0) > this.opts.velocityThreshold || distance > this.disregardVelocityThresholdY) { this.fire('swipedown', event); } } @@ -222,15 +240,15 @@ export default class TinyGesture { 0.15 * (type === 'x' ? window.innerWidth || document.body.clientWidth - : window.innerHeight || document.body.clientHeight) - ) + : window.innerHeight || document.body.clientHeight), + ), ), velocityThreshold: 10, disregardVelocityThreshold: (type, self: TinyGesture) => Math.floor(0.5 * (type === 'x' ? self.element.clientWidth : self.element.clientHeight)), pressThreshold: 8, diagonalSwipes: false, - diagonalLimit: Math.tan(((45 * 1.5) / 180) * Math.PI), + diagonalLimit: 15, longPressTime: 500, doubleTapTime: 300, mouseSupport: true, @@ -280,6 +298,6 @@ try { get: function () { passiveIfSupported = { passive: true }; }, - }) + }), ); } catch (err) {}