import * as React from 'react'; import { // DefaultSectionT, SectionList as RNSectionList, SectionListProps as RNSectionListProps, View, } from 'react-native'; import { getElement } from '../../hook'; export type SectionListRef = RNSectionList; export type SectionListProps = RNSectionListProps< ItemT, SectionT > & { /** * Rendered when the list is error. Can be a React Component Class, a render function, or * a rendered element. */ ListErrorComponent?: | React.ComponentType | React.ReactElement | null | undefined; /** * Rendered when the list is loading. Can be a React Component Class, a render function, or * a rendered element. */ ListLoadingComponent?: | React.ComponentType | React.ReactElement | null | undefined; }; export const _SectionList = ( props: SectionListProps, ref?: React.ForwardedRef> ) => { const { ListErrorComponent, ListLoadingComponent } = props; return ( {getElement(ListErrorComponent)} {getElement(ListLoadingComponent)} ); }; /** * @example * * export const SectionList = SectionListFactory<{ id: string }>(); * export function SectionList() {} */ export function SectionListFactory< ItemT = any, SectionT extends Record = Record, >() { return React.forwardRef< SectionListRef, SectionListProps >(_SectionList); } export type SectionListFactoryReturn< ItemT, SectionT extends Record = Record, > = ReturnType>;