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

Fix mouse functionality on touch devices. #1960

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
15 changes: 3 additions & 12 deletions src/view/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -1076,18 +1076,9 @@ new function() { // Injection scope for event handling on the browser
mousemove = 'pointermove MSPointerMove';
mouseup = 'pointerup pointercancel MSPointerUp MSPointerCancel';
} else {
Copy link
Member

@eeropic eeropic Mar 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should try changing line 1073

if (navigator.pointerEnabled || navigator.msPointerEnabled) {
to if ('PointerEvent' in window) { and check whether it solves your problem

(instead of the changes proposed below)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately there seems to be some possible breaking behaviour, which I'm not fully aware of atm #1810 (comment)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using PointerEvent does fix it for me but I still see no harm in always listening to all the events instead of depending on the userAgent string. The mouse events shouldn't be called after calling preventDefault on the touch events anyways.

mousedown = 'touchstart';
mousemove = 'touchmove';
mouseup = 'touchend touchcancel';
// Do not add mouse events on mobile and tablet devices
if (!('ontouchstart' in window && navigator.userAgent.match(
/mobile|tablet|ip(ad|hone|od)|android|silk/i))) {
// For non pointer events browsers and mixed browsers, like chrome
// on Windows8 touch laptop.
mousedown += ' mousedown';
mousemove += ' mousemove';
mouseup += ' mouseup';
}
mousedown = 'touchstart mousedown';
mousemove = 'touchmove mousemove';
mouseup = 'touchend touchcancel mouseup';
}

var viewEvents = {},
Expand Down