feat: add smooth scroll zooming - #2198
Conversation
fef6a96 to
2c9a434
Compare
|
Hey @vinlet, Wow! This is hugely appreciated - and something I've wanted to implement and has been top of my personal priority list for a while, but I've always been put off by needing to handle the whole trackpad/mouse thing (it's a well known issue in Flutter as well, see flutter/flutter#32120). Although it's true that most users use flutter_map on mobile platforms, one of flutter_map's biggest advantages is that it does actually run on web and desktop unlike the alternatives, so any improvements that bring that support even further ahead are great. Given this is such a big thing to test and get right, and because the gesture handling has historically been a messy part of flutter_map, this might not be merged quickly (especially as I'm about to be unavailable for coding/testing for a while). But we'll look into it. Thanks again! |
|
@JaffaKetchup that's ok! I'll try to be available and respond if there's news. |
There was a problem hiding this comment.
Hey, thanks for this again! I think this looks good to me. I'm considering releasing this into a prerelease first to see whether we can drum up some testers, since I'm aware that this part of the code can be very very fiddly and behave differently with different devices and on different platforms - but I'm not sure yet.
I've also made some changes to the API and example app, and removed a couple redundant (IMO) tests.
Add smooth scrolling toggle to demo page
…mOptions` Removed redundant tests
|
I've updated the example app and the API. Also removed a couple tests that I believe are redundant (the ones testing defaults of the constructors of |
|
hey, sorry for the late reply, haven't logged on in a while. Yeah we should do quite a bit more testing especially if we make this the default. If anyone stumbles across this PR and wants this feature, please test it locally with all the platforms and mice and laptop trackpads you have and report the results :) Ideally it would be great to see the scroll deltas and timings if you find an issue, but you'll have to add logging yourself... |
Improved deprecation and transition behaviour Adjusted smooth scroll wheel zoom rate
|
I've managed to test this on a mac mini and my Ubuntu dualboot, seems to be working OK both on platform and on web on each :) Unfortunately I don't have a special mouse or anything (like an Apple mouse), but I have been testing with a trackpad on Windows and Ubuntu (platform+web) as well, and that seems to be working. I've also changed the API a little again, and improved the behaviour of the deprecation and transition. The new smooth behaviour will be the default for all users in v8.4+, unless the current/old scroll wheel velocity argument is not at its default (and the new arguments have not been changed from their defaults). Looking good so far, definitely looking to get this merged in now! |
smooth_scroll_zoom.mp4
With some help from Claude Code and Opus 4.6 (I'm sorry) I ported MapLibre GL JS's implementation of animated smooth zooming for mouse wheel scrolls. I feel like this was sorely missing from
flutter_map, though I'm aware web/desktop users are probably not in the majority.MapLibre's implementation tries to differentiate mouse wheels from trackpads through some magic (whic is apparently damn hard). I ported that logic verbatim but not sure how well it applies to Flutter. Apparently pretty well.
On top of MapLibre's implementation I made the scroll rate and animation duration configurable, but non-defaults probably dont't play well with some of the other hardcoded delays from MapLibre's implementation.
The old behavior still exists but I made smooth scrolling the default which is technically a breaking change, so let me know if that's not ok...
Manually tested it in:
Random notes:
DateTime.now(), but I found somewhat of a clever/ugly hack to fake it out withpackage:clockwithout adding it as a dependency.TestAppinscroll_wheel_zoom_test.dartto add in custominteractionOptionsbut realized it's a bad idea long term. So instead I added aninteractionOptionsparam toTestApp. But this still feels like pointless busywork. In my projects I typically have something likewrapInTestApp(Widget child)where you can pass in anyFlutterMapyou like. I didn't do this here because the PR would blow up.TestApp, tests still work and don't pointlessly print messages when running tests.InteractionOptions.scrollWheelVelocityand move it intoScrollZoomOptions, maybe even merge it withScrollZoomOptions.wheelZoomRatesomehow?Credit where credit is due: