UNPKG

@scrolia/react-native-flash-list

Version:

A set of list components for Scrolia React Native

1 lines 3.89 kB
{"version":3,"file":"list/y.mjs","sources":["webpack://@scrolia/react-native-flash-list/./src/list/y.tsx"],"sourcesContent":["\n\nimport type { ScrollCore } from \"@scrolia/react-native-core\";\nimport type { FlashListProps } from \"@shopify/flash-list\";\nimport type {\n LayoutChangeEvent,\n NativeScrollEvent,\n NativeSyntheticEvent,\n} from \"react-native\";\n\nimport { useScrollCore } from \"@scrolia/react-native-core\";\nimport { FlashList } from \"@shopify/flash-list\";\nimport * as React from \"react\";\n\n/** Props for the `FlashListY` component. */\ntype FlashListYProps<T> = FlashListProps<T>;\n\nconst List = <T,>(\n props: FlashListYProps<T>,\n ref: React.Ref<FlashList<T>>,\n): React.JSX.Element => {\n const { children, ...p } = props;\n\n const core: ScrollCore = useScrollCore();\n\n React.useImperativeHandle(ref, (): FlashList<T> => {\n return core.y.elRef.current as FlashList<T>;\n }, [\n core.y.elRef,\n ]);\n\n React.useEffect((): void => {\n core.y.elType.current = \"flatlist\";\n }, [\n core.y.elType,\n ]);\n\n const handleLayout = (event: LayoutChangeEvent): void => {\n if (!core.options.disabled) core.y.handleLayout(event);\n p.onLayout?.(event);\n };\n\n const handleContentSizeChange = (width: number, height: number): void => {\n if (!core.options.disabled)\n core.y.handleContentSizeChange(width, height);\n p.onContentSizeChange?.(width, height);\n };\n\n const handleScroll = (\n event: NativeSyntheticEvent<NativeScrollEvent>,\n ): void => {\n if (!core.options.disabled) core.y.handleScroll(event);\n p.onScroll?.(event);\n };\n\n return (\n <>\n <FlashList\n {...p}\n ref={core.y.elRef}\n showsHorizontalScrollIndicator={false}\n showsVerticalScrollIndicator={core.options.disabled}\n onLayout={handleLayout}\n onContentSizeChange={handleContentSizeChange}\n onScroll={handleScroll}\n horizontal={false}\n scrollEventThrottle={p.scrollEventThrottle ?? 5}\n >\n {children}\n </FlashList>\n </>\n );\n};\n\n/**\n * Vertical list component based on `@shopify/flash-list`.\n *\n * **This component requires `@shopify/flash-list` to be installed.**\n */\nconst FlashListY = React.forwardRef(List) as <T>(\n props: FlashListYProps<T> & {\n ref?: React.Ref<FlashList<T>>;\n },\n) => ReturnType<typeof List>;\n\n// @ts-expect-error\nFlashListY.displayName = \"FlashListY\";\n\nexport type { FlashListYProps };\nexport { FlashListY };\n"],"names":["List","props","ref","children","p","core","useScrollCore","React","handleLayout","event","handleContentSizeChange","width","height","handleScroll","FlashList","FlashListY"],"mappings":";;;;;AAiBA,MAAMA,OAAO,CACTC,OACAC;IAEA,MAAM,EAAEC,QAAQ,EAAE,GAAGC,GAAG,GAAGH;IAE3B,MAAMI,OAAmBC;IAEzBC,oBAA0BL,KAAK,IACpBG,KAAK,CAAC,CAAC,KAAK,CAAC,OAAO,EAC5B;QACCA,KAAK,CAAC,CAAC,KAAK;KACf;IAEDE,UAAgB;QACZF,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,GAAG;IAC5B,GAAG;QACCA,KAAK,CAAC,CAAC,MAAM;KAChB;IAED,MAAMG,eAAe,CAACC;QAClB,IAAI,CAACJ,KAAK,OAAO,CAAC,QAAQ,EAAEA,KAAK,CAAC,CAAC,YAAY,CAACI;QAChDL,EAAE,QAAQ,GAAGK;IACjB;IAEA,MAAMC,0BAA0B,CAACC,OAAeC;QAC5C,IAAI,CAACP,KAAK,OAAO,CAAC,QAAQ,EACtBA,KAAK,CAAC,CAAC,uBAAuB,CAACM,OAAOC;QAC1CR,EAAE,mBAAmB,GAAGO,OAAOC;IACnC;IAEA,MAAMC,eAAe,CACjBJ;QAEA,IAAI,CAACJ,KAAK,OAAO,CAAC,QAAQ,EAAEA,KAAK,CAAC,CAAC,YAAY,CAACI;QAChDL,EAAE,QAAQ,GAAGK;IACjB;IAEA,OAAO,WAAP,GACI;kBACI,kBAACK,WAASA;YACL,GAAGV,CAAC;YACL,KAAKC,KAAK,CAAC,CAAC,KAAK;YACjB,gCAAgC;YAChC,8BAA8BA,KAAK,OAAO,CAAC,QAAQ;YACnD,UAAUG;YACV,qBAAqBE;YACrB,UAAUG;YACV,YAAY;YACZ,qBAAqBT,EAAE,mBAAmB,IAAI;sBAE7CD;;;AAIjB;AAOA,MAAMY,aAAa,WAAbA,GAAaR,WAAiBP;AAOpCe,WAAW,WAAW,GAAG"}