react-native: [Android] ScrollView events are not triggered when manually calling scrollTo
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 onMomentumScrollEnd
event 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
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 8
- Comments: 18 (2 by maintainers)
This is still an issue in RN 0.51
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 callscrollToIndex
on Android. But if I callscrollToIndex
on iOS, it correctly callsonMomentumScrollEnd
.The issue is that
onScroll
oronMomentumScrollEnd
does not trigger if scroll is triggered manually usingscrollTo
on Android.For some reason setting
animated: true
inscrollTo
seems to make it work.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?
I have
react-native
in0.40.0
version and I even don’t getonMomentumScrollEnd
when I normally scroll… But only in Android, iOS works