React-native: [Android] ScrollView events are not triggered when manually calling scrollTo

Created on 2 Jan 2017  路  18Comments  路  Source: facebook/react-native

Description

When having a ScrollView with onMomentumX events, these event will not be triggered on Android if the scroll was triggered by a manual scrollTo call.

I expected the events to be triggered on both platforms, but they were only triggered on iOS.

Reproduction

Here is a small demo app to reproduce the issue on rnplay:
https://rnplay.org/apps/aPVzIg

The app has a state change (in this case, the width of the container) triggered by the ScrollView's onMomentumScrollEnd event, and a timeout to manually call scrollTo after 2,000ms.

When running the sample on iOS, the state change will be triggered automatically after 2 seconds due to the onMomentumScrollEndevent being triggered post scrollTo.

When running the sample on Android, the state change will not be triggered automatically after 2 seconds (even though the scrollTo call could be seen to have been executed as the offset of the ScrollView changes).

When manually scrolling the view on Android, the event is being called as expected.

Additional Information

  • React Native version: 0.33
  • Platform: Android
Locked

Most helpful comment

This is still an issue in RN 0.51

All 18 comments

I have a problem like yours. Do you solve it?

I have react-native in 0.40.0 version and I even don't get onMomentumScrollEnd when I normally scroll... But only in Android, iOS works

+1

This still seems to be the case in 0.44. Would be really nice to have this same onMomentumScrollEnd hook for programmatic scrolls on Android. Is there any inherent reason why this behavior can't be implemented for Android?

Because the scroll position you want to scroll is not rendered yet, you have to wait for all rows to be rendered before you scroll to that position.

I'm on the same boat with onMomentumScrollEnd being triggered on manual scroll only on Android, whereas it's triggered after scrollTo too on iOS. An acceptable workaround would be a scrollTo callback function I guess.

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

Any chance we could re-open this? I'm still experiencing it on RN 0.48, Android 7.1 on a Nexus 6.

In particular, I'm using a FlatList which triggers onMomentumScrollEnd when I swipe between items but not when I call scrollToIndex on Android. But if I call scrollToIndex on iOS, it correctly calls onMomentumScrollEnd.

same for us. RN 0.48

It should be open it!

+1, seems hacky to manually trigger "onScrollEnd" when you manually scroll to an item, with an "expected" offset.

This is still an issue in RN 0.51

The issue is that onScroll or onMomentumScrollEnd does not trigger if scroll is triggered manually using scrollTo on Android.

For some reason setting animated: true in scrollTo seems to make it work.

This issue is showing up for RN 0.55.4.
@superandrew213 had it right; onMomentumScrollEnd does not trigger on android if you use scrollTo but, setting animated: true does not seem to make a difference for me.

@ledbetterljoshua both onScroll or onMomentumScrollEnd don't trigger?

This is still an issue in RN 0.55.3

Android ScrollView scrollTo doesn't do anything. :(
this.scrView.scrollTo({x:contentOffset.x-8,animated:true})

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aniss picture aniss  路  3Comments

madwed picture madwed  路  3Comments

phongyewtong picture phongyewtong  路  3Comments

axelg12 picture axelg12  路  3Comments

lazywei picture lazywei  路  3Comments