Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed multiple touchend #4804

Merged
merged 1 commit into from
Mar 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
},
addListener = fabric.util.addListener,
removeListener = fabric.util.removeListener,
RIGHT_CLICK = 3, MIDDLE_CLICK = 2, LEFT_CLICK = 1;
RIGHT_CLICK = 3, MIDDLE_CLICK = 2, LEFT_CLICK = 1,
addEventOptions = { passive: false };

function checkClick(e, value) {
return 'which' in e ? e.which === value : e.button === value - 1;
Expand Down Expand Up @@ -61,8 +62,8 @@
addListener(this.upperCanvasEl, 'dragleave', this._onDragLeave);
addListener(this.upperCanvasEl, 'drop', this._onDrop);
// touch events
addListener(this.upperCanvasEl, 'touchstart', this._onMouseDown, { passive: false });
addListener(this.upperCanvasEl, 'touchmove', this._onMouseMove, { passive: false });
addListener(this.upperCanvasEl, 'touchstart', this._onMouseDown, addEventOptions);
addListener(this.upperCanvasEl, 'touchmove', this._onMouseMove, addEventOptions);

if (typeof eventjs !== 'undefined' && 'add' in eventjs) {
eventjs.add(this.upperCanvasEl, 'gesture', this._onGesture);
Expand Down Expand Up @@ -250,11 +251,11 @@
*/
_onMouseDown: function (e) {
this.__onMouseDown(e);
addListener(fabric.document, 'touchend', this._onMouseUp, { passive: false });
addListener(fabric.document, 'touchmove', this._onMouseMove, { passive: false });
addListener(fabric.document, 'touchend', this._onMouseUp, addEventOptions);
addListener(fabric.document, 'touchmove', this._onMouseMove, addEventOptions);

removeListener(this.upperCanvasEl, 'mousemove', this._onMouseMove);
removeListener(this.upperCanvasEl, 'touchmove', this._onMouseMove);
removeListener(this.upperCanvasEl, 'touchmove', this._onMouseMove, addEventOptions);

if (e.type === 'touchstart') {
// Unbind mousedown to prevent double triggers from touch devices
Expand All @@ -274,13 +275,13 @@
this.__onMouseUp(e);

removeListener(fabric.document, 'mouseup', this._onMouseUp);
removeListener(fabric.document, 'touchend', this._onMouseUp);
removeListener(fabric.document, 'touchend', this._onMouseUp, addEventOptions);

removeListener(fabric.document, 'mousemove', this._onMouseMove);
removeListener(fabric.document, 'touchmove', this._onMouseMove);
removeListener(fabric.document, 'touchmove', this._onMouseMove, addEventOptions);

addListener(this.upperCanvasEl, 'mousemove', this._onMouseMove);
addListener(this.upperCanvasEl, 'touchmove', this._onMouseMove, { passive: false });
addListener(this.upperCanvasEl, 'touchmove', this._onMouseMove, addEventOptions);

if (e.type === 'touchend') {
// Wait 400ms before rebinding mousedown to prevent double triggers
Expand Down