Skip to content

Instantly share code, notes, and snippets.

@naqvitalha
Created February 5, 2024 21:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naqvitalha/8676fe58b306e87f5d46a34e7ad52403 to your computer and use it in GitHub Desktop.
Save naqvitalha/8676fe58b306e87f5d46a34e7ad52403 to your computer and use it in GitHub Desktop.
LazyScrollView
export const LazyScrollView = forwardRef(function LazyScrollView(
props: LazyScrollViewProps,
ref: ForwardedRef<FlashList<unknown[]>>,
): JSX.Element {
const {children, estimatedScrollViewSize, estimatedItemSize} =
props;
const data = isArray(children) ? children : Children.toArray(children);
// No specific reason for 2000, just a big number. Roughly 2x the screen size
const drawDistance = 2000;
if (estimatedItemSize === undefined) {
console.warn(
"LazyScrollView: 'estimatedItemSize' is missing, check FlashList warning for a recommended value.",
);
}
return (
<FlashList
ref={ref}
{...props}
data={data}
renderItem={({item}) => item}
getItemType={(_, index) => {
// Disables recycling of items by assigning a unique type to each item
return index;
}}
estimatedListSize={estimatedScrollViewSize}
drawDistance={drawDistance}
/>
);
});
@hirbod
Copy link

hirbod commented Mar 6, 2024

@naqvitalha would you mind sharing the utilities and types as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment