Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/__tests__/RecyclerView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,32 @@ describe("RecyclerView", () => {
});
});

describe("Viewability after data updates", () => {
it("reports visible items when data is replaced at the same indices", () => {
const onViewableItemsChanged = jest.fn();
const result = render(
<FlashList
data={[{ id: "a" }]}
keyExtractor={(item) => item.id}
onViewableItemsChanged={onViewableItemsChanged}
viewabilityConfig={{ minimumViewTime: 0 }}
renderItem={({ item }) => <Text>{item.id}</Text>}
/>
);

result.act(() => jest.runAllTimers());
onViewableItemsChanged.mockClear();

result.setProps({ data: [{ id: "b" }] });
result.act(() => jest.runAllTimers());

expect(onViewableItemsChanged).toHaveBeenCalledWith({
viewableItems: [expect.objectContaining({ item: { id: "b" } })],
changed: [expect.objectContaining({ item: { id: "b" } })],
});
});
});

describe("Item separators in grid mode", () => {
const Separator = () => <View style={{ height: 10 }} />;

Expand Down
1 change: 1 addition & 0 deletions src/recyclerview/RecyclerViewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export class RecyclerViewManager<T> {
}

processDataUpdate() {
this.itemViewabilityManager.clearLastReportedViewableIndices();
if (this.hasLayout()) {
this.modifyChildrenLayout([], this.propsRef.data?.length ?? 0);
if (this.hasRenderedProgressively && !this.recomputeEngagedIndices()) {
Expand Down
Loading