Skip to content

Scrolling with trackpad continues momentum animation for too long #107752

Closed

Description

@moffatman

The ballistic simulation which follows a scroll when using BouncingScrollPhysics gives good behaviour for a touchscreen, but causes much more scrolling than other desktop and trackpad apps. The amount of friction should be increased of the source of the scroll is a trackpad, to match expectations and behavior of other applications.

_frictionSimulation = FrictionSimulation(0.135, position, velocity);

Reproduced using https://github.com/flutter/platform_tests/tree/master/scroll_overlay on Apple Silicon macOS. The same discrepancy is seen on iPadOS.

scrolling.mov

Activity

  1. maheshj01 commented on Jul 18, 2022

    @maheshj01
    Member

    Hi @moffatman, Thanks for filing the issue. I do see the scroll animation is longer on the latest master channel, But not on the stable channel.

    Stable

    Screen.Recording.2022-07-18.at.12.47.13.PM.mov

    master

    Screen.Recording.2022-07-18.at.12.50.58.PM.mov
    flutter doctor -v (mac)
    [✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-arm, locale en-IN)
        • Flutter version 3.0.5 at /Users/mahesh/Documents/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision f1875d570e (5 days ago), 2022-07-13 11:24:16 -0700
        • Engine revision e85ea0e79c
        • Dart version 2.17.6
        • DevTools version 2.12.2
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-32, build-tools 33.0.0-rc4
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2021.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 61.2.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.67.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.44.0
    
    [✓] Connected device (3 available)
        • sdk gphone arm64 (mobile) • emulator-5554 • android-arm64  • Android 11 (API 30) (emulator)
        • macOS (desktop)           • macos         • darwin-arm64   • macOS 12.4 21F79 darwin-arm
        • Chrome (web)              • chrome        • web-javascript • Google Chrome 103.0.5060.114
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    [✓] Flutter (Channel master, 3.1.0-0.0.pre.1594, on macOS 12.4 21F79 darwin-arm, locale en-IN)
        • Flutter version 3.1.0-0.0.pre.1594 on channel master at /Users/mahesh/Documents/flutter_master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 082ad11422 (2 days ago), 2022-07-11 11:40:07 +0200
        • Engine revision 2b5d5c3b2d
        • Dart version 2.18.0 (build 2.18.0-271.0.dev)
        • DevTools version 2.15.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-32, build-tools 33.0.0-rc4
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 13C100
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2021.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 61.2.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.67.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.44.0
    
    [✓] Connected device (3 available)
        • Redmi K20 Pro (mobile) • 192.168.1.2:5555 • android-arm64  • Android 11 (API 30)
        • macOS (desktop)        • macos            • darwin-arm64   • macOS 12.4 21F79 darwin-arm
        • Chrome (web)           • chrome           • web-javascript • Google Chrome 103.0.5060.114
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
  2. added
    c: regressionIt was better in the past than it is now
    frameworkflutter/packages/flutter repository. See also f: labels.
    platform-macosBuilding on or for macOS specifically
    f: scrollingViewports, list views, slivers, etc.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Jul 18, 2022
  3. HansMuller commented on Jul 19, 2022

    @HansMuller
    Contributor
  4. Piinks commented on Jul 19, 2022

    @Piinks
    Contributor

    So there could be 2 things at play here. We know that ballistic scroll animations can be triggered more than they should, see #11599 That could be contributing to what it showing here.

    And then there could be some additional adjustment that needs to be made to BouncingScrollPhysics.

    The first has a proposed fix in progress in #107735. After than lands, we should check this again and see if the update to the ballistic scroll animation makes this any better..

    Since this is specific to only the trackpad input device, is it possible @moffatman that the trackpad input is applying too much delta? Should't the scroll physics be the same across input devices? Currently we don't have dynamic scroll physics that adapt to the input device so we will need to investigate this a bit.

  5. added
    a: fidelityMatching the OEM platforms better
    and removed
    c: regressionIt was better in the past than it is now
    on Jul 19, 2022
  6. moffatman commented on Jul 19, 2022

    @moffatman
    ContributorAuthor

    @Piinks

    I noticed there were a lot of goBallistic calls, but in BouncingScrollPhysics that doesn't matter since it's using exponential deceleration, no state is being lost and the calculation is continuous. I verified by commenting out some of the goBallistic calls to only get one at the start.

    It looks like #107735 only affects clamping scroll physics? This is with BouncingScrollPhysics.

    Trackpad input is the correct delta, since when scrolling without releasing, the lists track correctly. It's the scroll simulation phase which doesn't match.

    I have been trying to adjust BouncingScrollPhysics to get it to match. This is going to require dynamic scroll physics, for proper trackpad scroll deceleration, there needs to be more friction. Here's where I'm at:

    Screen.Recording.2022-07-19.at.3.22.06.PM.mov

    Changes so far:

    1. Apply constant deceleration on top of the friction factor (right now 2800pt/s^2). This ends up needing quite complex math to calculate the stopping point.
    2. Change friction factor on overscroll from 0.52 to 0.07
    3. Adjust velocity estimation algorithm to more heavily weight recent samples (also needs to be different on trackpad vs touchscreen)
    4. Increase kMaxFlingVelocity to infinity, it's not uncommon to see ~24000pt/s velocity from the trackpad.

    Still doesn't quite match though.

    The easiest way to have dynamic scroll behavior would be to have a trackpad physics and touch physics, but that would make it quite complex for anyone switching from the defaults. Probably the physics object should know about the PointerDeviceKind.

    Another issue: on iPadOS itself, the trackpad actually has the same friction as touch, but when iPad app is running on an M1 mac, it uses Mac-specific scrolling friction. Right now those devices show up as Platform.iOS, some refactor would be needed to represent this runtime scenario.

  7. Piinks commented on Jul 19, 2022

    @Piinks
    Contributor

    Thank you for digging into this!

    It looks like #107735 only affects clamping scroll physics? This is with BouncingScrollPhysics.

    Yeah, it is updating clamping scroll physics, but also fixing that ballistic issue at the same time.

    The easiest way to have dynamic scroll behavior would be to have a trackpad physics and touch physics

    That is a really interesting idea, but probably really complex to implement. Flutter does not know what input devices are available until it actually receives the input, and there would be a lot of edge cases to account for when using both. Imagine a scroll animation running from mouse input is interrupted by a scroll animation from a trackpad... Right now all of scrolling in Flutter assumes one type of scroll physics, so supporting more than one would be tricky.

    I think what it sounds like is that we might want to consider having proper desktop scroll physics. ClampingSP is based on Android, while BouncingSP is based on iOS. We have not actually compared/contrasted/considered what Mac, Linux and Windows scroll physics should be.

    Another issue: on iPadOS itself, the trackpad actually has the same friction as touch, but when iPad app is running on an M1 mac, it uses Mac-specific scrolling friction.

    Emulators running on desktop can make this a bit murky - it does sound like the scroll physics are different on mac from iOS. If the iPad scrolling matches on the physical device, that is the source of truth. There are a lot of things that simulators are just a bit off by. Like in the above scroll_overlay, no matter how fine tuned you get it, it will always be just a bit off because of inconsistent compositing, performance, etc on simulators.

    Right now those devices show up as Platform.iOS, some refactor would be needed to represent this runtime scenario.

    This is something we are really unlikely to do. Adding another target platform is a large scale breaking change for the framework, especially since iPadOS is really iOS.

  8. moffatman commented on Jul 19, 2022

    @moffatman
    ContributorAuthor

    So I think I will try to get a good match of Mac scrolling behavior and add it as a new default physics for Mac, and forget about different physics for trackpad vs touch. What do you think @Piinks ?

    For the iOS app running in emulation, I can deal with it on my own apps, I have some code to detect if running in that environment and then I'll switch the default scroll configuration. You're right that it would be a big breaking change for a pretty small edge case.

  9. Piinks commented on Jul 19, 2022

    @Piinks
    Contributor

    That sounds awesome! Thank you so much for all of your contributions!

    It could be that we add a platform-specific variation to BouncingScrollPhysics, rather than a whole new ScrollPhysics class, but I trust you'll be able to determine the best course there.

    I don't think the scroll_overlay app has an underlying mac app in it for comparison, we'll have to add one in there to be able to compare the overlay like on iOS and Android.

  10. Piinks commented on Jul 19, 2022

    @Piinks
    Contributor

    Update: Actually it looks like that app doesn't even have mac enabled. 😜

  11. moffatman commented on Jul 19, 2022

    @moffatman
    ContributorAuthor

    I'm running the iOS version on "My Mac (Designed for iPad)". That's what those videos are from, in that mode the scroll events are generated from AppKit using the same physics as other mac apps. I don't know how to make one specifically for mac, I don't think you can put mix native and flutter on desktop yet?

  12. Piinks commented on Jul 19, 2022

    @Piinks
    Contributor

    AppKit using the same physics as other mac apps

    Oh! TIL! I think it is ok to work off that then. :)

  13. added
    P2Important issues not at the top of the work list
    on Jul 21, 2022
  14. github-actions commented on Oct 3, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  15. locked as resolved and limited conversation to collaborators on Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: desktopRunning on desktopa: fidelityMatching the OEM platforms betterf: scrollingViewports, list views, slivers, etc.found in release: 3.1Found to occur in 3.1frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-macosBuilding on or for macOS specifically

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions