From 227d747c727cf5a11481ca2c1f2b20018c12a247 Mon Sep 17 00:00:00 2001 From: Paul Kaplan <pkaplan@media.mit.edu> Date: Mon, 29 Jul 2019 15:52:15 -0400 Subject: [PATCH] Fix gestureInProgress after dragEnd to return the correct value Fixes #5031, which is happening because the gestureInProgress call is still returning true after a drag ends. --- src/lib/drag-recognizer.js | 4 +++- test/unit/util/drag-recognizer.test.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib/drag-recognizer.js b/src/lib/drag-recognizer.js index 1f507785a..da7173f8b 100644 --- a/src/lib/drag-recognizer.js +++ b/src/lib/drag-recognizer.js @@ -109,8 +109,10 @@ class DragRecognizer { } _handleEnd () { - this._onDragEnd(); this.reset(); + // Call the callback after reset to make sure if gestureInProgress() + // is used in response, it get the correct value (i.e. no gesture in progress) + this._onDragEnd(); } _isDrag () { diff --git a/test/unit/util/drag-recognizer.test.js b/test/unit/util/drag-recognizer.test.js index 825917ba8..643ded528 100644 --- a/test/unit/util/drag-recognizer.test.js +++ b/test/unit/util/drag-recognizer.test.js @@ -56,6 +56,17 @@ describe('DragRecognizer', () => { expect(onDrag).toHaveBeenCalledTimes(1); // Still 1 }); + test('start -> end calls dragEnd callback after resetting internal state', done => { + onDragEnd = () => { + expect(dragRecognizer.gestureInProgress()).toBe(false); + done(); + }; + dragRecognizer = new DragRecognizer({onDrag, onDragEnd}); + dragRecognizer.start({clientX: 100, clientY: 100}); + window.dispatchEvent(new MouseEvent('touchmove', {clientX: 150, clientY: 106})); + window.dispatchEvent(new MouseEvent('touchend', {clientX: 150, clientY: 106})); + }); + test('start -> reset unbinds', () => { dragRecognizer.start({clientX: 100, clientY: 100}); window.dispatchEvent(new MouseEvent('touchmove', {clientX: 150, clientY: 106})); -- GitLab