From 78011d1a230d81549edba951b8aea66a4549a168 Mon Sep 17 00:00:00 2001 From: cduivis Date: Thu, 12 Oct 2017 12:09:07 +0200 Subject: [PATCH 1/3] Do not use a timer for an explicit timeout of 0 The `Press` gesture recognizer in HammerJS has problems consistently firing a `pressup` event following a `press` event in the context of small `time` values. This is well-known. See e.g. #1011, #836, #751. We've found that given a pair of `Press` and `Pan` gestures configured as below, the `pressup` event will fairly consistently break ( especially when using touch input ). This particular scenario is used for detecting a `Press` for instant setting of a position and `Pan` gradually controlling a set position ( we specifically use this for creating a "dual-ended between" variant of the `input type="range"` ): ```js { recognizers : [ [ Hammer.Pan, { direction : Hammer.DIRECTION_HORIZONTAL, threshold : 0 }], [ Hammer.Press, { threshold : 1, time : 0 }] ] }``` The root cause is with a granularity problem with browser timeouts as used in the `setTimeoutContext`, which causes part of the gesture logic to fire too late (or not at all). This issue and probably others like it, such as #1011, #836 or #751 can be fixed by not using a timeout at all if the gesture's `time` property is 0. --- src/utils/set-timeout-context.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/utils/set-timeout-context.js b/src/utils/set-timeout-context.js index 9f461bb46..82e7a63d4 100644 --- a/src/utils/set-timeout-context.js +++ b/src/utils/set-timeout-context.js @@ -9,5 +9,10 @@ import bindFn from './bind-fn'; * @returns {number} */ export default function setTimeoutContext(fn, timeout, context) { - return setTimeout(bindFn(fn, context), timeout); + if(timeout === 0) { + fn.call( context ); + return null; + } else { + return setTimeout(bindFn(fn, context), timeout); + } } From 9b1e9da357fe963a265b94716af8c57259f8aeac Mon Sep 17 00:00:00 2001 From: cduivis Date: Fri, 13 Oct 2017 09:30:03 +0200 Subject: [PATCH 2/3] Removed a trailing white-space --- src/utils/set-timeout-context.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/set-timeout-context.js b/src/utils/set-timeout-context.js index 82e7a63d4..de87e8b4d 100644 --- a/src/utils/set-timeout-context.js +++ b/src/utils/set-timeout-context.js @@ -13,6 +13,6 @@ export default function setTimeoutContext(fn, timeout, context) { fn.call( context ); return null; } else { - return setTimeout(bindFn(fn, context), timeout); + return setTimeout(bindFn(fn, context), timeout); } } From e178bb178f91e2efd08e3c0d8151e6d1c0b360ca Mon Sep 17 00:00:00 2001 From: cduivis Date: Fri, 13 Oct 2017 09:35:36 +0200 Subject: [PATCH 3/3] Refactored to adjust to the coding styles --- src/utils/set-timeout-context.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/set-timeout-context.js b/src/utils/set-timeout-context.js index de87e8b4d..3adc1db63 100644 --- a/src/utils/set-timeout-context.js +++ b/src/utils/set-timeout-context.js @@ -9,8 +9,8 @@ import bindFn from './bind-fn'; * @returns {number} */ export default function setTimeoutContext(fn, timeout, context) { - if(timeout === 0) { - fn.call( context ); + if (timeout === 0) { + fn.call(context); return null; } else { return setTimeout(bindFn(fn, context), timeout);