Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue] onViewableItemsChanged not firing with/after new data appended to start #117

Open
niek-hdas opened this issue Feb 24, 2025 · 0 comments

Comments

@niek-hdas
Copy link

I have a header component that displays accurate data related to the current most prominent item in view.

It seems like onViewableItemsChanged is not firing when new data is appended at the beginning of the list. Basically it goes to index 0 and then is not firing anymore.

For your idea my implementation:

<LegendList
  refreshControl={
    <RefreshControl
      onRefresh={() => refetchCalendar()}
      refreshing={isRefetchingCalendar}
    />
  }
  data={ungroupedAndSortedCalendar}
  keyExtractor={(item) => {
    return item.startDate;
  }}
  estimatedItemSize={700}
  initialScrollIndex={Math.floor(calendar.pages[0].length / 2)}
  onStartReached={() => {
    if (!isFetchingPreviousPage) {
      fetchPreviousPage();
    }
  }}
  onEndReached={() => {
    if (!isFetchingNextPage) {
      fetchNextPage();
    }
  }}
  onViewableItemsChanged={({ viewableItems, changed }) => {
    if (!viewableItems?.length) {
      return;
    }

    const wait10ms = new Promise((resolve) =>
      setTimeout(resolve, 10)
    );

    wait10ms.then(() => {
      setMonthInView(viewableItems[0].item.title);
    });
  }}
  viewabilityConfig={{
    itemVisiblePercentThreshold: 50,
    waitForInteraction: false,
  }}
  recycleItems
  waitForInitialLayout
  maintainVisibleContentPosition
  renderItem={({ item }: { item: TwelveMonthCalendar[0] }) => {
    return (
      <TwelveMonthCalendarItem
        calendar={item.calendar}
        today={today}
      />
    );
  }}
/>
@jmeistrich jmeistrich mentioned this issue Mar 9, 2025
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant