-
-
Notifications
You must be signed in to change notification settings - Fork 717
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
Emit event when cooperative gestures blocks event #4470
Emit event when cooperative gestures blocks event #4470
Conversation
I have not been able to find where I should add this extra event to the documentation. If someone can tell me how to do that I would happily do it! |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4470 +/- ##
==========================================
+ Coverage 87.53% 87.84% +0.31%
==========================================
Files 246 246
Lines 33446 33450 +4
Branches 2212 2218 +6
==========================================
+ Hits 29276 29384 +108
+ Misses 3153 3055 -98
+ Partials 1017 1011 -6 ☔ View full report in Codecov by Sentry. |
e6268c4
to
1f30526
Compare
I still don't understand how raising these events will allow replacing the current UI. |
.maplibre-cooperative-gestures-container {
display: none !important;
} map.on("cooperativegestureprevented", () => showToast("Press Ctrl"));
map.on("cooperativegestureprevented", () => someObservableState.gesturePrevented = Date.now());
map.on("cooperativegestureprevented", () => analytics.sendEvent("user_tried_to_scroll_map")); I can do whatever I want with this event, including putting my own UI on top of MapLibre, in my host app, sending things to analytics, etc. |
I see, thanks for the info! |
1f30526
to
0c5915f
Compare
OK, documented that and put the logic back to the individual handlers so things like touch counts, etc are all in the concerned handler. |
Previously, the logic for preventing gestures and notifying the user about those gestures was duplicated. Firstly, we checked if the gesture should go through by things like counting touches in other handlers. We would also check the same thing in the CoopGesture handler class, too. This was a source of confusion for me as it wasn't apparent how the Handler was able to prevent other handlers from firing - the answer is that it wasn't and the the other handlers had to check with the CooperativeGestureHandler themselves. Now, this is made explicit as the logic for checking only exists in one place, and the other handlers are responsible for asking the CooperativeGestureHandler to notify the user about the fact that the gesture was blocked.
beac456
to
ab393e1
Compare
Hi, please note that the following was not updated with this logic: I'm not sure what should be the solution there, but please make sure to test all scenarios to make sure nothing is broken. I have updated some small parts of the code, just small refactoring... |
@HarelM I'm not sure what change you are expecting there. The logic has not and should not change. |
There's no event in that case, and since you remove the |
I'm not sure what part of the logic is broken. What I moved is the code that shows the message if the number of touches is exactly equal to 1, which is now in touch_pan, because it relates to touch panning. There was never any message shown (and now there should be no event emitted) when using 2 fingers in an upwards motion (which in non-coop mode means pitch, but in coop mode means pan) because although it's changing the nature of the gesture, it's not blocking it per se.
Yes, and it all seems to work exactly as on main, and using a real mobile device and multiple fingers, too. The behaviour on touch devices is: normal mode:
coop mode:
That's how it is on main and that's how it is on this branch. |
One thing we could do would be to emit a |
Thanks for the clarification, I probably got it wrong, sorry. |
Launch Checklist
Fixes #4464
Adds the ability to subscribe to the case when the
CooperativeGestures
handler prevents a gesture from being handled by the map. This allows users to add custom logic in this case to put up custom UI, for instance.The events emitted are of type
cooperativegestureprevented
and have agestureType: "wheel_zoom" | "touch_pan"
andoriginalEvent: Event
properties, so the developer has as much detail as possible. Arguably,gestureType
can be deduced from theoriginalEvent
but it feels nice to explain the gesture type in MapLibre-ish terms.This also refactors the way in which coop gesture preventions are detected and notified. It wasn't obvious to me when I was working on this how the coop gesture class was preventing the gestures from being handled/bubbled/whatever. It took a while to realise that the
touchmove
andwheel
events in this are run in "parallel" to the other gesture handlers.The refactor makes the coop gesture handler have two distinct responsibilities:
This avoids duplicate logic and makes it easy to find how this module is used elsewhere as it has no intrinsic abilities: it performs logic and actions when requested by other modules.
CHANGELOG.md
under the## main
section.