Created
February 5, 2024 21:56
-
-
Save naqvitalha/8676fe58b306e87f5d46a34e7ad52403 to your computer and use it in GitHub Desktop.
LazyScrollView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | |
/> | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@naqvitalha would you mind sharing the utilities and types as well?