Skip to content

Commit 227d747

Browse files
committed
Fix gestureInProgress after dragEnd to return the correct value
Fixes scratchfoundation#5031, which is happening because the gestureInProgress call is still returning true after a drag ends.
1 parent c1dcbb0 commit 227d747

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/lib/drag-recognizer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ class DragRecognizer {
109109
}
110110

111111
_handleEnd () {
112-
this._onDragEnd();
113112
this.reset();
113+
// Call the callback after reset to make sure if gestureInProgress()
114+
// is used in response, it get the correct value (i.e. no gesture in progress)
115+
this._onDragEnd();
114116
}
115117

116118
_isDrag () {

test/unit/util/drag-recognizer.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ describe('DragRecognizer', () => {
5656
expect(onDrag).toHaveBeenCalledTimes(1); // Still 1
5757
});
5858

59+
test('start -> end calls dragEnd callback after resetting internal state', done => {
60+
onDragEnd = () => {
61+
expect(dragRecognizer.gestureInProgress()).toBe(false);
62+
done();
63+
};
64+
dragRecognizer = new DragRecognizer({onDrag, onDragEnd});
65+
dragRecognizer.start({clientX: 100, clientY: 100});
66+
window.dispatchEvent(new MouseEvent('touchmove', {clientX: 150, clientY: 106}));
67+
window.dispatchEvent(new MouseEvent('touchend', {clientX: 150, clientY: 106}));
68+
});
69+
5970
test('start -> reset unbinds', () => {
6071
dragRecognizer.start({clientX: 100, clientY: 100});
6172
window.dispatchEvent(new MouseEvent('touchmove', {clientX: 150, clientY: 106}));

0 commit comments

Comments
 (0)