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

Control.Layers: stop relying on Browser android and touch properties #7057

Merged
merged 4 commits into from
Nov 1, 2021

Conversation

johnd0e
Copy link
Collaborator

@johnd0e johnd0e commented Mar 30, 2020

Control.Layers: stop relying on Browser android and touch properties

  • android is useless here, as there are a lot of non-android touch devices (including desktop ones)
  • touch is useless, as mouse can be used on touch-screen too

Now these use cases are covered:

  • mouseenter/leave are handled on touch devices too

    With this PR mouse attached to device with touch support behaves as it should: reacts on mouseover/out events.
    But that is up on browser support, e.g. Chrome on android does not produce mousemove/over/out events.
    (But Firefox does)

  • If Layers control created with {collapsed:false}, and than it collapsed explicitly
    [using .collapse() method], it's now possible to expand it back with click.

Fix #6579.
Fix unexpected layer switching when expanding control on touch

Most browsers produce compatibility mouseenter for touch event, but not all,
so we listen for click also.

The problem is that these compatibility events come all in single batch, so
same touch induces expand and then immediate input switching.

To avoid this we temporarily prevent click on layers section.
Note: more straight-forward way would be relying on e.sourceCapabilities.firesTouchEvents,
but atm it has rather low support: https://caniuse.com/#feat=mdn-api_inputdevicecapabilities_firestouchevents


Related discussions: #6978, #7022.


Test page: https://gist.githack.com/johnd0e/a854f95019bb1a4c1ae909fbc6769d35/raw/pr-7057.html

@johnd0e
Copy link
Collaborator Author

johnd0e commented Apr 4, 2020

Code from 4e2fe35 replaced with plain preventDefault.
In fact I have no idea why there was those excessive actions, and there is nothing explained in original issue discussion (#638).

It seems that this is not sole place where stopPropagation misused, called 'just in case'.
And stop function is evil because it facilitates such approach:

Leaflet/src/dom/DomEvent.js

Lines 205 to 206 in 436430d

// @function stop(ev: DOMEvent): this
// Does `stopPropagation` and `preventDefault` at the same time.

To do:

@johnd0e johnd0e marked this pull request as ready for review April 4, 2020 15:43
@johnd0e
Copy link
Collaborator Author

johnd0e commented Apr 6, 2020

Note: more straight-forward way would be relying on e.sourceCapabilities.firesTouchEvents,

Another alternative: use pointerover, where check e.pointerType, and if it is not from mouse, then do nothing (and call preventDefault in order to suppress mouseover).

In year or two pointer events support should be wide enough to adopt this approach.

@johnd0e johnd0e force-pushed the fix-layers-control branch 3 times, most recently from f086c56 to 5c95d6d Compare January 25, 2021 10:51
johndoe added 3 commits January 25, 2021 13:04
- `android` is useless here, as there are a lot of non-android touch devices (including desktop ones)
- `touch` is useless, as mouse can be used on touch-screen too

Now these usecases are covered:
- `mouseenter/leave` are handled on touch devices too
- If Layers control created with {collapsed:false}, and than it collapsed explicitly
  [using .collapse() method], it's now possible to expand it back with click.
… touch

Most browsers produce compatibility mouseenter for touch event, but not all,
so we listen for click also.

The problem is that these compatibility events come all in single batch, so
same touch induces expand and then immediate input switching.

To avoid this we temporarily prevent click on layers section.
Note: more straight-forward way would be relying on e.sourceCapabilities.firesTouchEvents,
      but atm it has rather low support: https://caniuse.com/#feat=mdn-api_inputdevicecapabilities_firestouchevents
@johnd0e johnd0e force-pushed the fix-layers-control branch from 5c95d6d to e913763 Compare January 25, 2021 11:05
@johnd0e
Copy link
Collaborator Author

johnd0e commented Jan 25, 2021

PR improved.

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 this pull request may close these issues.

Layer Control - touch clicks first layer
2 participants