Skip to content

Commit

Permalink
chore(example): extract itemSize function
Browse files Browse the repository at this point in the history
  • Loading branch information
pierpo committed Sep 13, 2024
1 parent 7219765 commit 4c8b816
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions packages/example/src/modules/program/view/ProgramList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ export const ProgramList = ({
[data, variant],
);

const itemSize = useMemo(
() => {
if (variant === 'normal') {
return theme.sizes.program.portrait.width + GAP_BETWEEN_ELEMENTS;
}

return (item: ProgramInfo) =>
isItemLarge(item)
? theme.sizes.program.landscape.width + GAP_BETWEEN_ELEMENTS
: theme.sizes.program.portrait.width + GAP_BETWEEN_ELEMENTS;
}, // Default item size for "normal"
[theme.sizes.program.landscape.width, theme.sizes.program.portrait.width, variant],
);

return (
<SpatialNavigationNode>
{({ isActive }) => (
Expand All @@ -70,14 +84,7 @@ export const ProgramList = ({
orientation={orientation}
data={programInfos}
renderItem={renderItem}
itemSize={
variant === 'variable-size'
? (item) =>
isItemLarge(item)
? theme.sizes.program.landscape.width + GAP_BETWEEN_ELEMENTS
: theme.sizes.program.portrait.width + GAP_BETWEEN_ELEMENTS
: theme.sizes.program.portrait.width + GAP_BETWEEN_ELEMENTS // Default item size for "normal"
}
itemSize={itemSize}
numberOfRenderedItems={WINDOW_SIZE}
numberOfItemsVisibleOnScreen={NUMBER_OF_ITEMS_VISIBLE_ON_SCREEN}
onEndReachedThresholdItemsNumber={NUMBER_OF_ITEMS_VISIBLE_ON_SCREEN}
Expand Down

0 comments on commit 4c8b816

Please sign in to comment.