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 7d970d8 commit 4654ff1
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 4654ff1

Please sign in to comment.