import { Pagination } from "@/api/types"; import { ReactElement, RefObject } from "react"; import { ScrollView, View } from "react-native"; import { Button, ButtonText } from "../button"; import { ThemedText } from "../themed-text"; type CustomFlatListProps = { pagination?: Pagination; skeleton: ReactElement; skeletonStartCount?: number; currentPage: number; setCurrentPage: (v: number) => void; isLoadingPage: boolean; renderItem: (item: T) => ReactElement; pagesRadius?: number; dividerHeight?: number; scrollView?: RefObject; }; const PaginationList = ({ pagination, skeleton, currentPage, setCurrentPage, isLoadingPage, renderItem, scrollView, pagesRadius = 3, skeletonStartCount = 4, dividerHeight = 16, }: CustomFlatListProps) => { const renderSkeleton = () => { const skeletonCount = pagination ? pagination.meta.per_page : skeletonStartCount; return Array.from({ length: skeletonCount }).map((_, i) => ( {skeleton} )); }; const handlePagePress = (page: number) => { if (page === currentPage) return; setCurrentPage(page); scrollView?.current?.scrollTo({ y: 0, animated: false }); }; if (!pagination || isLoadingPage) return renderSkeleton(); return ( {pagination.data.map((item, index) => ( {renderItem(item)} ))} {pagination.data.length === 0 && ( No items found. )} {currentPage > 1 && ( )} {currentPage !== pagination.meta.last_page && ( )} ); }; export default PaginationList;