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

multiples 'touchend' event handlers #4794

Closed
annagrudzien opened this issue Mar 8, 2018 · 1 comment · Fixed by #4804
Closed

multiples 'touchend' event handlers #4794

annagrudzien opened this issue Mar 8, 2018 · 1 comment · Fixed by #4804

Comments

@annagrudzien
Copy link

annagrudzien commented Mar 8, 2018

Steps to reproduce

Add handling 'mouse:up' event to canvas, run code on touchable device, every 'mousedown' event causes adding handler for 'touchend' event, and it is not removed,

The reason is this code:
_onMouseDown: function(e) {
this.__onMouseDown(e);
addListener(fabric.document, "touchend", this._onMouseUp, {
passive: false
});

# addListener(fabric.document, "touchmove", this._onMouseMove, {
passive: false
});

removeListener(this.upperCanvasEl, "mousemove", this._onMouseMove);
removeListener(this.upperCanvasEl, "touchmove", this._onMouseMove);
if (e.type === "touchstart") {
removeListener(this.upperCanvasEl, "mousedown", this._onMouseDown);
} else {
addListener(fabric.document, "mouseup", this._onMouseUp);
addListener(fabric.document, "mousemove", this._onMouseMove);
}
},
_onMouseUp: function(e) {
this.__onMouseUp(e);
removeListener(fabric.document, "mouseup", this._onMouseUp);

        **removeListener(fabric.document, "touchend", this._onMouseUp);**
        removeListener(fabric.document, "mousemove", this._onMouseMove);
   ##      removeListener(fabric.document, "touchmove", this._onMouseMove);
        addListener(this.upperCanvasEl, "mousemove", this._onMouseMove);
        addListener(this.upperCanvasEl, "touchmove", this._onMouseMove, {
            passive: false
        });

removeListener shoud be called with the same options as addListener
otherwise the handler is not removed. What is more we need to call it with the same options object:

This won't work:

addListener(fabric.document, "touchend", this._onMouseUp, {
passive: false
});

removeListener(fabric.document, "touchend", this._onMouseUp, {
passive: false
});

# this will work

var options = {
passive: false
}

*addListener(fabric.document, "touchend", this._onMouseUp, options);

removeListener(fabric.document, "touchend", this._onMouseUp, options);

It is a little bit strange:)

@asturur
Copy link
Member

asturur commented Mar 12, 2018

cool good to know, for sure is a fix we can do and will not harm anything else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants