Skip to content

Commit

Permalink
Mildly improve the loadouts virtualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
bhollis committed Dec 15, 2024
1 parent 3b04bf5 commit 9550f96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/app/dim-ui/VirtualList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import styles from './VirtualList.m.scss';

interface VirtualListProps {
numElements: number;
estimatedSize: number;
estimatedSize: number | ((index: number) => number);
className?: string;
itemContainerClassName?: string;
/**
Expand Down Expand Up @@ -46,7 +46,7 @@ export const VirtualList = forwardRef(function VirtualList(
const virtualizer = useVirtualizer({
count: numElements,
getScrollElement: () => parentRef.current,
estimateSize: () => estimatedSize,
estimateSize: typeof estimatedSize === 'function' ? estimatedSize : () => estimatedSize,
getItemKey,
overscan,
});
Expand Down Expand Up @@ -124,7 +124,7 @@ export const WindowVirtualList = forwardRef(function WindowVirtualList(

const virtualizer = useWindowVirtualizer({
count: numElements,
estimateSize: () => estimatedSize,
estimateSize: typeof estimatedSize === 'function' ? estimatedSize : () => estimatedSize,
scrollMargin: parentOffsetRef.current,
scrollPaddingStart: headerHeightRef.current,
getItemKey,
Expand Down
4 changes: 3 additions & 1 deletion src/app/loadout/Loadouts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ function Loadouts({ account }: { account: DestinyAccount }) {
ref={virtualListRef}
numElements={loadoutRows.length}
itemContainerClassName={styles.loadoutRow}
estimatedSize={270}
estimatedSize={(index) =>
'id' in loadoutRows[index] ? (isPhonePortrait ? 1450 : 300) : 51
}
getItemKey={(index) => {
const loadoutOrSeason = loadoutRows[index];
return 'id' in loadoutOrSeason ? loadoutOrSeason.id : loadoutOrSeason.startDate!;
Expand Down

0 comments on commit 9550f96

Please sign in to comment.