-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Add option to smoothly animate stepped mouse scroll deltas #32120
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
Comments
I ported Chrome's rather complex smooth scrolling algorithm (see https://bit.ly/smoothscrolling) I can clean it up a bit (make the code a bit more Dart-y) and make a PR, if using Chrome's smooth scrolling is acceptable. |
/cc @gspencergoog It seems like this is going to need a design proposal, or at least discussion, for how it would be controlled, since it should almost certainly be optional. Smooth scrolling with scroll wheels is definitely not universal behavior on desktop platforms. |
Notably, Windows (UWP apps) and Mac OS have their own smooth scrolling behaviors. Linux doesn't really have a default, so I feel that using Chrome's implementation (at least on Linux) would be good enough. |
For UWP, a lot of the logic can be found here (Scroller.cpp), and some keyboard scrolling logic can be found here (ScrollViewer.cpp) |
Marking this as a |
Is anyone working on this? I see this problem in the Android emulator. Using the scrollwheel leads to very erratic behavior. Sometimes it scrolls the list down, them pops back. (is not limited to webviews - also happens with listviews) |
@ds84182 Your smooth scroll algorithm looks pretty good from what I can see in the GIF. Could you share your code on how you implemented it? I have flutter web project and a smooth scroll algorithm would greatly increase the user experience. As far as I can tell, every browser supports smooth scrolling and so a flutter website feels a bit odd in comparison to other native websites when being scrolled. |
Do u have the smooth scroll algorithm can u share it ? |
Reproducible on the latest master Minimal reproducible code sample
flutter doctor -v
|
@Mikephii |
This comment was marked as off-topic.
This comment was marked as off-topic.
heres a minimal example of my solution. I think this can be used by the flutter team and can easily be a boolean flag in the scroll controller. Unsure of any side effects but it works fine for me and doesnt break
|
I agree. Mouse scrolling on lists are confusing. Items simply disappear off the screen. If not numbered, it's hard to keep track on what I am looking at. |
I've just published the scroll_animator package, which aims to be a direct port of Chromium's smooth scrolling algorithm (ported along with related unit tests, just to make sure it works as expected). There are some edge cases which I know about and plan to resolve in the coming days, but there's probably a bunch more of them I don't know about yet, so I wouldn't use it in production just yet, but I would be grateful for testing and bug reports. When the package is stable enough, I'll probably try to refactor the code and try to upstream it. In regards to the previous attempts at resolving this problem, it turns out we don't have to know if the user is scrolling using a mouse wheel or a trackpad. Chromium developers solved that problem by adjusting the algorithm so it works well with small, frequent scroll deltas as well as large, infrequent scroll deltas. See this bug report for more details. |
I just gave it a try but when scrolling up/down quickly, the scroll seems to stop completely every now and again. Once fixed, this packages seems like a great fix to the problem. |
Yeah, I'll probably have to get a new mouse, my current one has a broken wheel, when scrolling in one direction it sporadically decides to go the other way, so I wasn't able to verify quick scrolls, I'll look into that. Also, regarding upstreaming into Flutter, I think it would be best if Flutter provided an abstract animation factory (like the one in my package), so that third-party packages could provide alternative scroll animation implementations. Flutter could include a single default implementation, but then there would be pub packages for Mac-like or Edge-like scrolling. The recently proposed solution with just a boolean would lack that customizability. |
@BennyKirschner unfortunately I wasn't able to reproduce your issue, but I've just published a new version with an additional diagnostic example, available here: https://pub.dev/packages/scroll_animator/example. If you could try to reproduce your issue while capturing this diagnostic data, I might be able to synthetically reproduce your scroll inputs and hopefully the issue itself. Also, I suggest opening an issue over at the scroll_animator repository, so we don't spam this issue. |
I wanted to share a little progress update, since I've published the initial version of scroll_animator last week, quite a bit changed:
|
@kszczek, First I have to say, wonderful work with the package. It works flawlessly, and honestly it's better than some of the previous solutions. I have to ask, if it's possible for you to add support for the package |
@water-mizuu thanks for the feedback, I appreciate it! Regarding the package you've mentioned, I've glanced over its source and it seems like it has the base I'd submit a PR as it's a quite simple thing to do, but it seems like the google/flutter.widgets repository where this package lives is not very active, with the last commit dating December 2023 and multiple stale PRs. If I were you I'd just clone this package to my machine, edit this line to instantiate an AnimatedScrollController and use the path dependency syntax. A long-term solution for this issue is to integrate the smooth scrolling logic into the base |
I just tried @kszczek's scroll_animator package and holy crap it works perfectly. It feels like proper native scrolling instead of feeling like some bad mobile port. |
Just cross-linking to a related issue over on the W3C side: w3c/uievents#337 |
I get why this is currently blocked for web, but is there anything preventing this from being implemented for desktop platforms? |
I don't think differentiating between trackpad and mouse wheel events should be considered a blocker for web/desktop implementation. In fact, I believe the reason stated for this blockage is a misunderstanding. I've mentioned this previously, but it's worth reiterating: some years ago, Chromium developers also implemented a heuristic for differentiating between trackpad and mouse wheel inputs. However, this approach caused more issues than it resolved. So, instead of disabling scroll smoothing specifically for trackpads, Chromium developers improved the scroll smoothing algorithm to handle high-frequency, low-delta inputs better (see https://issues.chromium.org/issues/41210665#comment16). All of the above is highlighted in the
As described above, I was in the process of upstreaming my work into Flutter last year, but got overwhelmed with other work. I plan to get back to this soon though, here's a rough roadmap:
|
(although knowing that a trackpad is used for scrolling is still useful info. It would allow us to implement fling gestures. But its still not a blocker - only a cherry on top) |
It's really bad right now, and I don't get why this was downgraded from P1 to P2. It definitely deserves highest priority and should be considered a severe bug. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
iapicca Now it looks like it's better not to target for web and Windows. Every app has scrollable components but it's very unconfortable to scroll with mouse and this issue still remains open. After 6 years |
Update 12/12/23
Steps to Reproduce
Gif example:

The text was updated successfully, but these errors were encountered: