diff --git a/packages/lib/src/spatial-navigation/components/virtualizedList/VirtualizedList.tsx b/packages/lib/src/spatial-navigation/components/virtualizedList/VirtualizedList.tsx index f3be52ce..808917ec 100644 --- a/packages/lib/src/spatial-navigation/components/virtualizedList/VirtualizedList.tsx +++ b/packages/lib/src/spatial-navigation/components/virtualizedList/VirtualizedList.tsx @@ -140,11 +140,11 @@ export const VirtualizedList = typedMemo( scrollBehavior = 'stick-to-start', testID, }: VirtualizedListProps) => { - const numberOfItemsVisibleOnScreen = getNumberOfItemsVisibleOnScreen( + const numberOfItemsVisibleOnScreen = getNumberOfItemsVisibleOnScreen({ data, listSizeInPx, itemSize, - ); + }); const numberOfItemsToRender = additionalItemsRendered ? additionalItemsRendered + numberOfItemsVisibleOnScreen diff --git a/packages/lib/src/spatial-navigation/components/virtualizedList/helpers/getNumberOfItemsVisibleOnScreen.ts b/packages/lib/src/spatial-navigation/components/virtualizedList/helpers/getNumberOfItemsVisibleOnScreen.ts index af3f4c87..cb9bff03 100644 --- a/packages/lib/src/spatial-navigation/components/virtualizedList/helpers/getNumberOfItemsVisibleOnScreen.ts +++ b/packages/lib/src/spatial-navigation/components/virtualizedList/helpers/getNumberOfItemsVisibleOnScreen.ts @@ -1,4 +1,10 @@ -const getMinSizeOfItems = (data: T[], itemSize: number | ((item: T) => number)) => { +const getMinSizeOfItems = ({ + data, + itemSize, +}: { + data: T[]; + itemSize: number | ((item: T) => number); +}) => { if (typeof itemSize === 'number') { return itemSize; } @@ -14,11 +20,15 @@ const getMinSizeOfItems = (data: T[], itemSize: number | ((item: T) => number return minSize; }; -export const getNumberOfItemsVisibleOnScreen = ( - data: T[], - listSizeInPx: number, - itemSize: number | ((item: T) => number), -) => { - const itemSizeToComputeRanges = getMinSizeOfItems(data, itemSize); +export const getNumberOfItemsVisibleOnScreen = ({ + data, + listSizeInPx, + itemSize, +}: { + data: T[]; + listSizeInPx: number; + itemSize: number | ((item: T) => number); +}) => { + const itemSizeToComputeRanges = getMinSizeOfItems({ data, itemSize }); return Math.floor(listSizeInPx / itemSizeToComputeRanges); };