import { View, Dimensions, Animated, StyleSheet, FlatList } from 'react-native'; import React from 'react'; import { Pagination } from './Pagination'; import type { OnboardingProps } from '../types'; import { SkipButton } from './button'; const { width } = Dimensions.get('window'); type CustomPagesProps = OnboardingProps & { children?: React.ReactNode[]; currentPage: number; setPage: (newPageIndex: number) => void; flatListRef: React.RefObject; scrollX: Animated.Value; nextPage: () => void; numberOfScreens: number; }; export type SliderProps = { index?: number; currentPage: number; numberOfScreens: number; nextPage: () => void; }; export const CustomPages = ({ showPagination = true, showNext = true, ...props }: CustomPagesProps) => { return ( {props.skipButtonPosition && props.showSkip && ( )} {showPagination && props.paginationPosition === 'top' && ( <> {props.customFooter && props.customFooter({ nextPage: props.nextPage })} {!props.customFooter && ( )} )} { const pageIndex = Math.round( event.nativeEvent.contentOffset.x / width ); props.setPage(pageIndex || 0); }} keyExtractor={(_, index) => index.toString()} renderItem={({ item, index }) => { return React.cloneElement( item as React.ReactElement, { currentPage: props.currentPage, numberOfScreens: props.numberOfScreens, nextPage: props.nextPage, index, } as SliderProps ); }} /> {showPagination && props.paginationPosition !== 'top' && ( <> {props.customFooter && props.customFooter({ nextPage: props.nextPage })} {!props.customFooter && ( )} )} ); }; const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', }, screen: { width, justifyContent: 'center', alignItems: 'center', backgroundColor: 'blue', }, pagination: { flexDirection: 'row', alignItems: 'center', paddingVertical: 10, paddingHorizontal: 20, width, }, dot: { height: 10, width: 10, borderRadius: 5, backgroundColor: '#333', margin: 5, }, dotsContainer: { flexDirection: 'row', flex: 1, justifyContent: 'center', }, });