Skip to content
Open
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
41 changes: 31 additions & 10 deletions src/recyclerview/RecyclerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ const RecyclerViewComponent = <T,>(

renderTimeTracker.startTracking();

const layoutRetryCountRef = useRef(0);
const MAX_LAYOUT_RETRIES = 5;


// Sticky header config
const stickyHeaderOffset = stickyHeaderConfig?.offset ?? 0;
const stickyHeaderUseNativeDriver =
Expand Down Expand Up @@ -183,7 +187,7 @@ const RecyclerViewComponent = <T,>(
},
isHorizontalRTL && recyclerViewManager.hasLayout()
? firstItemOffset -
recyclerViewManager.getChildContainerDimensions().width
recyclerViewManager.getChildContainerDimensions().width
: firstItemOffset
);
}
Expand Down Expand Up @@ -227,16 +231,33 @@ const RecyclerViewComponent = <T,>(
console.warn(WarningMessages.exceededMaxRendersWithoutCommit);
}

if (
recyclerViewManager.modifyChildrenLayout(layoutInfo, data?.length ?? 0) &&
!hasExceededMaxRendersWithoutCommit
) {
// Trigger re-render if layout modifications were made
setRenderId((prev) => prev + 1);
} else {
const layoutChanged = recyclerViewManager.modifyChildrenLayout(
layoutInfo,
data?.length ?? 0
);

const shouldRetryLayout =
layoutChanged && !hasExceededMaxRendersWithoutCommit;

const commitLayoutAndCorrectOffset = () => {
layoutRetryCountRef.current = 0;
viewHolderCollectionRef.current?.commitLayout();
applyOffsetCorrection();
};


if (shouldRetryLayout) {
layoutRetryCountRef.current += 1;

if (layoutRetryCountRef.current <= MAX_LAYOUT_RETRIES) {
// Retry render to stabilize layout
setRenderId((prev) => prev + 1);
return;
}
}
// Commit path: layout is stable OR retries exhausted
commitLayoutAndCorrectOffset();


if (
horizontal &&
Expand Down Expand Up @@ -585,8 +606,8 @@ const RecyclerViewComponent = <T,>(
return Math.max(
0,
windowSize -
childContainerSize -
recyclerViewManager.firstItemOffset
childContainerSize -
recyclerViewManager.firstItemOffset
);
}}
refHolder={refHolder}
Expand Down