Attempt fix for cellsAroundViewport reaching out of bounds

Summary: VirtualizedList would more gracefully handle out of range cells than VirtualizedList_EXPERIMENTAL, which treats it as an invariant violation. This attempts to fix an issue where recalculation of cells around viewport can include out of range cells.

Reviewed By: rshest

Differential Revision: D39244112

fbshipit-source-id: 20fe6ea552035061d9d00720fcab77b29a785771
This commit is contained in:
Nick Gerleman
2022-09-05 11:45:12 -07:00
committed by Facebook GitHub Bot
parent a50e6fb341
commit 7aa203beda
2 changed files with 4 additions and 2 deletions
+1 -1
View File
@@ -128,7 +128,7 @@ export function computeWindowedRenderLimits(
} {
const itemCount = props.getItemCount(props.data);
if (itemCount === 0) {
return prev;
return {first: 0, last: -1};
}
const {offset, velocity, visibleLength, zoomScale = 1} = scrollMetrics;
@@ -641,7 +641,9 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
!this._scrollMetrics.offset &&
Math.abs(distanceFromEnd) >= Number.EPSILON
) {
return cellsAroundViewport;
return cellsAroundViewport.last >= getItemCount(data)
? VirtualizedList._constrainToItemCount(cellsAroundViewport, props)
: cellsAroundViewport;
}
newCellsAroundViewport = computeWindowedRenderLimits(