React-native: onEndReached is not called on Android

Created on 15 Dec 2016  路  19Comments  路  Source: facebook/react-native

I'm trying to implement endless listview on Android using the ListView component, and both methods onScroll and onEndReached are not been fired.

Code

        <ListView
          dataSource={ this.state.dataSource }
          onEndReached={() => {console.log('fetch more')}}
          onEndReachedThreshold={10}
          initialListSize={ 20 }
          onScroll={() => { console.log('onScroll') }}
          renderRow={(rowData) => <ProductRow {...rowData} /> }
        />

Additional Information

  • React Native version: 0.38.0 and 0.39.0
  • Platform: Android
  • Operating System: MacOS
Locked

Most helpful comment

I actually got this working quite well playing with onEndReachedThreshold prop.
On IOS I set it to 0 and on Android to 1.

const isIOS = Platform.OS === 'ios';
...
onEndReachedThreshold={isIOS ? 0 : 1}

All 19 comments

+1

+1

+1

We have no problems with this on RN 0.38.0
Running in production without any problems.

Can you tell me what I'm doing wrong @ptomasroos ?

Hi @ptomasroos, I work with @aterribili. He forgot to mention that we place the react native view inside a Fragment.

Can you provide a sample app like on rnplay.org that reproduces this problem? Without the ability to repro it's going to be hard for anyone else to figure this out.

When I use ReactActivity the onEndReached of ListView is triggered, but when I use AppCompactActivity and Fragment it's doesn't work.

+1, any solution?

I am using React Native 0.39.2 on Android
onScroll works but onEndReached never called

+1

Same problem with RN 0.41.

It's easy to make up for it, but it's still annoying

    <ListView
      ...
      onLayout={isAndroid ? this._onLayoutAndroid : undefined}
    />

    /**
     * Store the height of the list once it's been mounted or
     * updated to trigger the onEndReached on Android
     */
    _onLayoutAndroid = (event) => {
        this.setState({ listViewHeight: event.nativeEvent.layout.height });
    }


    /**
     * Makes up for a bug on Android where `onEndReach` callback
     * is not fired on the ListView.
     * See : https://github.com/facebook/react-native/issues/11489
     */
    _onScrollAndroid (event) {
        const { listViewHeight } = this.state;
        const { y } = event.nativeEvent.contentOffset;
        const { onEndReachedThreshold } = this.props;

        if (y + onEndReachedThreshold >= listViewHeight) {
            this._onEndReached();
        }
    }

+1 on 0.41.2 . onendreached just called one time

Any nested ScrollView?

<ScrollView>
    <ScrollView>
    </ScrollView>
</ScrollView>

In this case, onEndReached or onScroll function will not be called on 2nd level of ScrollViews...

0.43.1 and Flatlist, onEndReached never called on Android

I actually got this working quite well playing with onEndReachedThreshold prop.
On IOS I set it to 0 and on Android to 1.

const isIOS = Platform.OS === 'ios';
...
onEndReachedThreshold={isIOS ? 0 : 1}

@sexykodo you are my release saviour

Hi,

I was able to reproduce this behavior too.

It happens notably when I'm using the pageSize attribute:

pageSize={this.state.layout.columns * this.props.pageRows}

I do this because my ListView is actually a gallery of pictures and there are 3 pictures per row. When I remove the pageSize attribute it works fine

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.

Was this page helpful?
0 / 5 - 0 ratings