Skip to main content

PageFlatList

Overview

page-swiper-example

Basic usage

PageSwiperSample.tsx
import { PageSwiper, Page } from 'react-native-awesome-swiper';

const Basic = () => {
const [activeIndex, setActiveIndex] = useState(3);

const { top } = useSafeAreaInsets();

const ref = useRef<FlatList<Page>>(null);

const pages: Page[] = [
{ label: 'pink', Component: SamplePage },
{ label: 'purple', Component: SamplePage },
{ label: 'green', Component: SamplePage },
{ label: 'yellow', Component: SamplePage },
{ label: 'gray', Component: SamplePage },
{ label: 'black', Component: SamplePage },
{ label: 'skyblue', Component: SamplePage },
];

return (
<PageSwiper.Provider>
<PageSwiper.AnimatedLineTabs
pages={pages}
activeIndex={activeIndex}
topInset={top}
/>
{/*or PageSwiper.MemoizedPageSwiper*/}
<PageSwiper.PageFlatList
ref={ref}
pages={pages}
onActivePageIndexChange={setActiveIndex}
initialScrollIndex={activeIndex}
/>
</PageSwiper.Provider>
);
};

Features 🚀

  • Implemented with FlatList API

  • getItemLayout, snapToInterval etc props are managed internally

  • Use <PageSwiper.MemoizedPageSwiper /> for optimization

  • All FlatList props supported except data, renderItem, snapToInterval

Issues ✍️

  • Only handles full screen width pages with horizontal for now (can be updated in next update)

pages

page data T should extend Page type

TypeDefaultRequired
T []undefinedYES
interface PageProps {
label: string;
index: number;
}

interface Page {
label: string;
Component: React.FunctionComponent<PageProps>;
}

onActivePageIndexChange

callback when currently visible page index changed

TypeDefaultRequired
(index: number) => voidundefinedNO

minimumViewTime

same with ViewabilityConfig['minimumViewTime']

TypeDefaultRequired
number200NO

itemVisiblePercentThreshold

same with ViewabilityConfig['itemVisiblePercentThreshold']

TypeDefaultRequired
number70NO

waitForInteraction

same with ViewabilityConfig['waitForInteraction']

TypeDefaultRequired
booleantrueNO