GetStream / react-native-bidirectional-infinite-scroll

📜 React Native - Bidirectional Infinite Smooth Scroll
https://getstream.github.io/react-native-bidirectional-infinite-scroll/
MIT License
236 stars 27 forks source link

onStartReached not being called #12

Open krishan-gandhi3 opened 3 years ago

krishan-gandhi3 commented 3 years ago

Code: Lib Version: 0.3.3 React Native: 0.61.5

import { FlatList } from "react-native-bidirectional-infinite-scroll";

<FlatList
        ref={(ref) => setFlatListRef(ref)}
        initialNumToRender={Math.min(formattedList.length, 45)}
        style={styles.flatList}
        data={data}
        keyExtractor={(item, index) => item.id}
        renderItem={renderCard}
        showsVerticalScrollIndicator={false}
        onMomentumScrollBegin={() => {
          onEndReachedCalledDuringMomentum = false;
        }}
        onEndReached={onListEndReached}
        onStartReached={onListTopReached}
        onScrollToIndexFailed={scrollToIndexFailed}
        viewabilityConfig={viewConfigRef.current}
        onViewableItemsChanged={onViewableItemsChangedRef.current}
        showDefaultLoadingIndicators={false}
        removeClippedSubviews
      />

I have a huge list and when scrolling upwards, I render 10 records at a time. I have to implement a logic as to when more than 60 records are added to list, I have to slice the list from bottom, ensuring only 50 records at max should be there. While implementing this, everything else works fine, but onStartReached stops getting invoked at all after certain calls. Removing this logic works fine though.

Any ideas / suggestions?

Thanks in advance!

kovkev commented 2 years ago

My onStartReached stops getting invoked after 3 times. It was unclear, you said Removing this logic works fine though.. What do you mean?

Ainias commented 2 years ago

I know it it an old Issue, but I took a look into the sourcecode for another issue. When data is fetched (aka onEndReached/onStartReached is called), the component remembers if the functions are already called for the current number of items. If on some past point the end or start was reached with the same number of items, it is not called again, even if the items or the number of items changed inbetween.

If you cut the data to 50, the functions will not be called again since they are already called

domoretrix commented 1 year ago

Is there a way to deactivate length memoization for the data list? would be very useful for infinite list optimization