import React, { useState } from 'react'; import { View, I18nManager, SafeAreaView, FlatList, TouchableOpacity, } from 'react-native'; import TTypography from '../TTypography/TTypography'; import { TypographyVariant } from '../TTypography/TTypographyEnum'; import PagerView from 'react-native-pager-view'; import { withTheme, useTheme } from '../../core/theming'; import type { Theme } from '../../utils/types'; import { styles } from './TTopBar.style'; interface Props { screens: ScreenData[]; initialPage?: number; tabStyle?: object; tabHighlightColor?: string; tabTextColor?: string; containerHeight?: any; containerWidth?: any; theme: Theme; } interface ScreenData { name: string; component: any; } const MyPager = ({ screens, initialPage, tabStyle, tabHighlightColor, tabTextColor, containerHeight, }: Props): any => { const pagerRef = React.useRef(null); const [selectedPage, setPage] = useState(initialPage || 0); const { colors } = useTheme(); const stylesWithProp = styles({ colors, tabHighlightColor, containerHeight }); const renderItem = (item: any, index: number) => { return ( { pagerRef.current?.setPage(index); }} style={ index === selectedPage ? { ...stylesWithProp.tabContainerSelected, ...tabStyle } : { ...stylesWithProp.tabContainer, ...tabStyle } } > {item.name} ); }; return ( renderItem(item, index)} keyExtractor={(item) => item.name} /> { setPage(event.nativeEvent.position); }} > {screens.map((screen, index) => { return {screen.component()}; })} ); }; export default withTheme(MyPager);