facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.17k stars 24.21k 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}
      />
    );
  }
}
arasrezaei commented 1 year ago

yes... i tested it with reanimated's useSrollHandler

useAnimatedScrollHandler({
onMomentumEnd: (event) => {
        console.log('hello')
      },
})

and sadly it's not working

SomniumDigital commented 10 months ago

I've found this to be an issue also on the ScrollView component, I've experienced this happening in RN 0.71 on Android API's 31-33 (Android 12 & 13) on both physical devices and the emulators.

Shivemmer commented 7 months ago

any update in this??

raajnadar commented 4 months ago

I thought I was alone, I can see the bug in version 0.73.6 also, I think this will be solved in the next major release of the new architecture.

dimaportenko commented 4 months ago

I think this will be solved in the next major release of the new architecture.

@raajnadar why do you think so?

raajnadar commented 4 months ago

@dimaportenko https://github.com/facebook/react-native/commit/681b35daab2d0443278fe18c364b0e72c8c85673

This commit was picked and released on 0.74.0, waiting for expo SDK 51 to test and confirm

dimaportenko commented 4 months ago

@raajnadar unfortunately it's about a different issue https://github.com/facebook/react-native/issues/32235. It shouldn't have any effect on this one.

raajnadar commented 4 months ago

I can confirm this bug is also present on the React Native Web ~0.19.6

WayneKim92 commented 2 months ago

I got the same issue. In RN 0.74.