Skip to content

Commit

Permalink
refactor: switch to object args for numberOfItemsVisibleOnScreenFunct…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
JulienIzz committed Sep 18, 2024
1 parent 5ffeda3 commit 1abc64a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ export const VirtualizedList = typedMemo(
scrollBehavior = 'stick-to-start',
testID,
}: VirtualizedListProps<T>) => {
const numberOfItemsVisibleOnScreen = getNumberOfItemsVisibleOnScreen(
const numberOfItemsVisibleOnScreen = getNumberOfItemsVisibleOnScreen({
data,
listSizeInPx,
itemSize,
);
});

const numberOfItemsToRender = additionalItemsRendered
? additionalItemsRendered + numberOfItemsVisibleOnScreen
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
const getMinSizeOfItems = <T>(data: T[], itemSize: number | ((item: T) => number)) => {
const getMinSizeOfItems = <T>({
data,
itemSize,
}: {
data: T[];
itemSize: number | ((item: T) => number);
}) => {
if (typeof itemSize === 'number') {
return itemSize;
}
Expand All @@ -14,11 +20,15 @@ const getMinSizeOfItems = <T>(data: T[], itemSize: number | ((item: T) => number

return minSize;
};
export const getNumberOfItemsVisibleOnScreen = <T>(
data: T[],
listSizeInPx: number,
itemSize: number | ((item: T) => number),
) => {
const itemSizeToComputeRanges = getMinSizeOfItems(data, itemSize);
export const getNumberOfItemsVisibleOnScreen = <T>({
data,
listSizeInPx,
itemSize,
}: {
data: T[];
listSizeInPx: number;
itemSize: number | ((item: T) => number);
}) => {
const itemSizeToComputeRanges = getMinSizeOfItems({ data, itemSize });
return Math.floor(listSizeInPx / itemSizeToComputeRanges);
};

0 comments on commit 1abc64a

Please sign in to comment.