Skip to content

Commit

Permalink
Attempt fix for cellsAroundViewport reaching out of bounds
Browse files Browse the repository at this point in the history
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
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 5, 2022
1 parent a50e6fb commit 7aa203b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Libraries/Lists/VirtualizeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion Libraries/Lists/VirtualizedList_EXPERIMENTAL.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 7aa203b

Please sign in to comment.