import React from "react"; import { StyleProp, TextStyle, ViewStyle } from "react-native"; import { Button } from "../Button"; import { Icon } from "../Icon"; import { Stack } from "../Stack"; import styles from "./styles"; type Props = { count: number; // total pages rangeSize?: number; // number of pages to show selected: number; previousIcon?: React.ReactNode; nextIcon?: React.ReactNode; buttonStyle?: StyleProp; selectedButtonStyle?: StyleProp; buttonTextStyle?: StyleProp; onPageChange: (index: number) => void; }; const Pagination = ({ count, selected, rangeSize = 4, buttonStyle, buttonTextStyle, selectedButtonStyle, previousIcon = , nextIcon = , onPageChange, }: Props) => { const pages = []; const getPageButton = (index) => ( ); } if (count <= rangeSize) { for (let index = 0; index < count; index++) { pages.push(getPageButton(index)); } } else { let rangeStart = rangeSize / 2; let rangeEnd = rangeSize - rangeStart; if (selected > count - rangeSize / 2) { rangeEnd = count - selected; rangeStart = rangeSize - rangeEnd; } else if (selected < rangeSize / 2) { rangeStart = selected; rangeEnd = rangeSize - rangeStart; } let page; let gapView; for (let index = 0; index < count; index++) { page = index + 1; if (page <= 1) { pages.push(getPageButton(index)); continue; } if (page > count - 1) { pages.push(getPageButton(index)); continue; } if (index >= selected - rangeStart && index <= selected + rangeEnd) { pages.push(getPageButton(index)); continue; } if (pages[pages.length - 1] !== gapView) { gapView = ( ); } return ( pages.length > 1 && ( {pages} ) ); }; export default Pagination;