question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ListView wont execute onEndReached when onScroll handler is added to its ScrollView

See original GitHub issue

Here is the use case (v 0.41.2):

<ListView
    style={{flex:1}}
    onEndReached={() => alert('Ok, I\'m @ the bottom')}
    renderScrollComponent={(props) => {
        return <ScrollView 
            style={{flex:1}} 
            scrollEventThrottle={50} 
            onScroll={(e) => console.log('I\'m scrolling')}
            />
    }}
    />

I’m not adding all the other props that ListView and ScrollView have but sure thing they are not causing the issue. As soon as onScroll is removed, everything works as expected. This is either a bug, or a missing documentation on how to implement onScroll and not capturing the event.

Update: After some digging in the RN source, I understand the problem. As soon as you add your own onScroll prop to the scroll view, the RN’s one, which owns the logic around onEndReached is overwritten and therefore the ListView’s callback wont work. It could be fixed very easily by the RN team if they add onScroll prop to the ListView itself and execute that callback from their ScrollView’s onScroll implementation.

So, if you want onEndReached and access to the onScroll event at the same time, you have to implement it yourself.

It will be very nice if the RN team expose all the callback props related to scrolling in the ListView and bubble them from the ScrollView’s.

Update 2: There is a way! Create a reference to your ListView component and then inside your onScroll handler just do the following:

// IMPORTANT: Using private methods is not usually a good practive but...
this.listView._onScroll(e); // Call RN's default prop handler

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

1reaction
janicduplessiscommented, Feb 19, 2017

If you put onScroll on the ListView directly instead of the ScrollView it should work.

0reactions
janicduplessiscommented, Feb 20, 2017

Feel free to send a PR to make it clearer 😃, closing this since it has been resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-native: OnEndReached for Flatlist not working in scrollview
I'm trying to use OnEndReached in a flat list which is in a scrollview tab. I use this scrollview because I have 3...
Read more >
Example of Infinite Loading Listview in React Native using ...
A React Native list view that supports infinite scroll with paging.. ... Run the following commands to create a new React Native project...
Read more >
Xamarin.Forms ScrollView - Microsoft Learn
Forms ScrollView is a layout that's capable of scrolling its content. ... the OnScrollViewScrolled event handler is executed when the ...
Read more >
FlatList - React Native
Instead of starting at the top with the first item, start at initialScrollIndex . This disables the "scroll to top" optimization that keeps...
Read more >
How to Create React Native FlatList Load More On Scroll
Check out on udemy: https://bit.ly/3vbA1LX#ReactNative #FlatListLoadMore #expoThis is the video about how we can add load more funcanality ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found