Skip to content

[Android] ScrollView momentum not stopping when calling scrollTo programmatically #32235

Closed

Description

@chr-sk

Description

When scrolling down a long ScrollView or FlatList on Android and calling scrollTo programmatically while the ScrollView's momentum is still going, the momentum does not stop and the resulting scrolling is stuttering and simply wrong.

React Native version / Platform

0.65.1 / Android

With 0.63.4, this bug was not yet present.

Steps To Reproduce

  1. Render a ScrollView (or FlatList) with long content and a button with onPress={() => scrollViewRef.scrollTo({ y: 0, animated: true })}.
  2. Scroll quickly down with your finger so that a momentum occurs.
  3. Press the button while the momentum is still going.

Expected Results

The momentum should stop and the ScrollView should scroll to its beginning.

Possible reason

It seems that the reason for this bug lies in the following commit: 10314fe

Activity

  1. reepush commented on Nov 29, 2021

    @reepush
    Contributor

    10314fe made scrolling worse on Android :(

  2. yiuyiu commented on Jan 11, 2022

    @yiuyiu

    Running into the same issue.

  3. RosCoder commented on Dec 17, 2022

    @RosCoder

    React Native 0.70.6. The same issue..

  4. bolan9999 commented on Dec 30, 2022

    @bolan9999

    Any update? fk rn

  5. moremorefun commented on Jan 11, 2023

    @moremorefun

    scrollViewRef.scrollTo({ y: xxx, animated: false})

    Nor did it move to the specified location, the new target location did not overwrite the old target location

  6. anatoleblanc commented on Feb 1, 2023

    @anatoleblanc

    Would love to have an update on this :)

  7. stitesExpensify commented on Feb 6, 2023

    @stitesExpensify

    I would also appreciate an update if anyone has found a solution

  8. halftheopposite commented on Feb 7, 2023

    @halftheopposite

    This is also something we are facing on Android only (RN 0.70.1), and for a little bit more context:

    1. Scroll down fast
    2. onScroll reports normal scrolling values (ex: 1200, 1220, 1240, etc.)
    3. Trigger a scrollTo to y: 0 with an outside action
    4. onScroll correctly reports a scroll of y: 0 once, but then continues with its momentum (ex: 1240, 0, 1260, 1280, etc.)
  9. moremorefun commented on Feb 7, 2023

    @moremorefun

    This is also something we are facing, and for a little bit more context:

    1. Scroll down fast

    2. onScroll reports normal scrolling values (ex: 1200, 1220, 1240, etc.)

    3. Trigger a scrollTo to y: 0 with an outside action

    4. onScroll correctly reports a scroll of y: 0 once, but then continues with its momentum (ex: 1240, 0, 1260, 1280, etc.)

    same issue

  10. tomekzaw commented on Feb 7, 2023

    @tomekzaw
    Contributor

    The issue still persists on 0.71.2, both on Android emulator as well as physical device.

    I've made a repro: https://github.com/tomekzaw/Issue32235

    Here's a video recording:

    recording.mov

    I will investigate this issue further.

    Edit: As a workaround, you can use scrollTo function from react-native-reanimated: tomekzaw/Issue32235@81f34c4 Note that it only works for animated: true (smooth scroll), for animated: false (immediate scroll) the issue still persists.

    workaround.mov

    Edit: After many hours of debugging, I came up with the following change that seems to resolve the issue. I will submit a pull request with this change soon.

       public void scrollTo(int x, int y) {
    +    mScroller.abortAnimation();
         super.scrollTo(x, y);
         ReactScrollViewHelper.updateFabricScrollState(this);
         setPendingContentOffsets(x, y);
       }
    fixed.mov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions