facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
117.77k stars 24.16k forks source link

[FlatList] Android: onMomentumScrollEnd doesn't trigger when use scrollToOffset #21718

Open myl0204 opened 5 years ago

myl0204 commented 5 years ago

Environment

React Native Environment Info: System: OS: macOS High Sierra 10.13.6 CPU: x64 Intel(R) Core(TM) i5-5675R CPU @ 3.10GHz Memory: 60.77 MB / 8.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 8.11.1 - /usr/local/bin/node Yarn: 1.9.4 - /usr/local/bin/yarn npm: 5.6.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0 IDEs: Android Studio: 3.0 AI-171.4443003 Xcode: 10.0/10A255 - /usr/bin/xcodebuild npmPackages: react: 16.5.0 => 16.5.0 react-native: 0.57.2 => 0.57.2

Description

onMomentumScrollEnd doesn't trigger when use scrollToOffset in Android.

And in iOS it works.

also i find that other methods e.g. scrollToIndex, have the same issue.

Reproducible Demo

export default class App extends Component<Props> {
  renderItem = ({item: { source }}) => {
    return (
      <TouchableOpacity onPress={() => {this.scrollView.scrollToOffset({offset: 375, animated: true})}}>
        <Image
          source={{uri: source.uri}}
          style={{width: 375, height: 375}}
        />
      </TouchableOpacity>
    )
  }

  onMomentumScrollEnd = () => {
    console.log('scrollend')
  }

  render() {
    return (
      <FlatList
        style={{ flex: 1, backgroundColor: 'black' }}
        data={[
          { source: { uri: 'http://i.imgur.com/XP2BE7q.jpg' } },
          { source: { uri: 'http://i.imgur.com/5nltiUd.jpg' } },
          { source: { uri: 'http://i.imgur.com/6vOahbP.jpg' } },
          { source: { uri: 'http://i.imgur.com/kj5VXtG.jpg' } }
        ]}
        renderItem={this.renderItem}
        ref={view => this.scrollView = view}
        onMomentumScrollEnd={this.onMomentumScrollEnd}
        scrollEnabled={true}
        horizontal={true}
      />
    );
  }
}
react-native-bot commented 5 years ago

Can you run react-native info and edit your issue to include these results under the Environment section?

If you believe this information is irrelevant to the reported issue, you may write [skip envinfo] under Environment to let us know.

myl0204 commented 5 years ago

did anyone have check this issue? just let me know there is somebody following this. Or, maybe some of you can tell me that's not an issue with react-native itself. Thanks!

mccjul commented 5 years ago

I am also currently having this issue with react native 0.57.5

otusweb commented 5 years ago

ANyone has a workaround for this issue?

leolusoli commented 5 years ago

+1

alexandrecanuto commented 5 years ago

Having this issue as well.

csath commented 5 years ago

+1 on react-native 0.57.8v

joseph-perez commented 5 years ago

I was running into this issue also on 0.57.1. In my case, I was trying to use the scrollTo method on a Scroll View. I wanted to trigger something after scrolling to a specific location on the screen. I was able to use the onScroll prop to achieve this šŸ˜„

onScroll(event) {
     if (event.nativeEvent.contentOffset.y === this.targetScreenOffsetY) {
        this.doSomething();
     }
}
stale[bot] commented 5 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

IseeUDenis commented 5 years ago

I am also currently having this issue with react native 0.59

Ryabchikus commented 4 years ago

I am also currently having this issue with react native 0.61.2 @joseph-perez thanks for workaround!

gwl002 commented 4 years ago

I feel really bad to use scrollview in react-native.Another bug,onMomentumScrollEnd not work when scroll slowly on ios.

Bardiamist commented 4 years ago

I faced with it. I also use horizontal FlatList. onMomentumScrollEnd very often not called if stop scroll with small velocity.

Bardiamist commented 4 years ago

I accidentally found a solution for myself. I wrapped every FlatList item in TouchableOpacity.

PaxLyj commented 4 years ago

Same problem in 0.61.5, scrollToOffset didn't trigger onMomentumScrollEnd callback. @Bardiamist no luck for me, it didn't work šŸ˜¢

stale[bot] commented 4 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

ManAnRuck commented 4 years ago

+1

gibrangul commented 4 years ago

+1

a-eid commented 4 years ago

still facing this issue even with a ScrollView as well, it some times trigger but very rarly and not consistent ...

Jaycexx commented 4 years ago

still reproduce this issue in 0.57.7

amblicity commented 3 years ago

i think i can shed some light to when onMomentumScrollEnd does not trigger on android as of RN0.61.5 when dragged manually (and released without velocity), albeit only little related to this issue. that might sound weird but after fiddling for hours to fix this issue, we solved it by replacing margins with paddings on the children and each child needed a backgroundColor property, whether with 'transparent' or a color. not setting this property made the bug reproducible again and we weren't able to get the onMomentumScrollEnd event to fire.

i'm trying to provide a working demo for this as currently we fixed it in a non-abstractable screen.

ajpaulingalls commented 3 years ago

any work arounds to get onMomentumScrollEnd to fire after a call to scrollToOffset?

ajpaulingalls commented 3 years ago

I have added a PR to address this. If anyone here could test it or review it and comment on the PR, I'd love to get some momentum to help it get merged. Thanks!

esinanturan commented 3 years ago

this issue still exists on 0.64 but it causes to trigger 4 times

mohity777 commented 3 years ago

It exists in 0.64, scrollToIndex does not fire onMomentumScrollEnd at the end of scrolling. It is called when user drags it but not when scrollToIndex is used.

milky-grech commented 3 years ago

I have found a tricky workaround for this - you can use onScroll instead and check for some conditions.

For instance, check if paginated scroll completed scrolling to the next page with if (event.nativeEvent.contentOffset % Dimensions.get('window').width === 0) { %something you wanted to trigger in onMomentumScrollEnd% }

LukeAppGuy commented 3 years ago

Still having this problem on Android, is there no workaround for using onMomentumScrollEnd together with scrollToOffset? I am using onMomentumScrollEnd to detect the index of the current item, then when a button is pressed the pagination/index is incremented.

SGarcia710 commented 3 years ago

I didn't found any answered thread so I got a way to solve it.

      flatList?.current?.scrollToOffset({
        offset: (currentIndex + 1) * width,
        animated: true,
      }); // This will trigger the onMomentunScrollEnd on iOS.
      if (Platform.OS === 'android') {
        setCurrentIndex(currentIndex + 1); // this is what we trigger on the onMomentunScrollEnd
      }

This problem only happens on Android, so you can manually trigger the update that's not being call on android.

stale[bot] commented 2 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

exzos28 commented 2 years ago

actual

PDabek-StreamitApp commented 2 years ago

still reproducible

lelukas commented 2 years ago

still reproducible

gijsfonk commented 2 years ago

Same here

demedos commented 1 year ago

Still an issue on 0.67.4. I faced it using scrollToIndex, but the result is the same

ivankdev commented 1 year ago

same issue

etrpekson99 commented 1 year ago

still exists pls fix

chj-damon commented 1 year ago

still have this issue in RN 0.66

meagher43 commented 1 year ago

Facing this issue today please fix

anatoleblanc commented 1 year ago

Same here

SerranoPablo commented 1 year ago

same here

nescroft commented 1 year ago

still an issue on 71.7 ... onmomentumscrollend is not called when using scrollTo and scrollToIndex

dhruvtailor7 commented 1 year ago

+1

novirusallowed commented 1 year ago

+1

Bardiamist commented 1 year ago

Is it related maybe? https://github.com/facebook/react-native/commit/681b35daab2d0443278fe18c364b0e72c8c85673

lekbit commented 1 year ago

Well, 5 years have passed, and the problem is still relevant. I think it's a good reason for me to switch to learning Kotlin. Thank you for the time spent learning Facebook/React Native.

dayze commented 1 year ago

Here is a reproducible repository : https://github.com/dayze/eventOnMomuntumScrollEnd I'll try to look into it

github-actions[bot] commented 1 year ago
:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.
github-actions[bot] commented 1 year ago
:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.
netojose commented 1 year ago

Five years and counting... The problem still exists :(

FlushNorris commented 11 months ago

wow... this is still an issue? Stuff like this needs to be addressed maybe not instantly, but 4 years later this cannot be an issue if React Native must survive.