import React, { Children, cloneElement, isValidElement } from 'react'; import { View } from 'react-native'; import { useTheme } from '../../theme'; import { getThemedStyles } from './styles'; import { TabProps, TabsProps } from './types'; export default function Tabs({ children, indicatorPosition = 'bottom', onChange, selectedIndex = 0, style, ...rest }: TabsProps): JSX.Element { const theme = useTheme(); const themedStyle = getThemedStyles(theme, indicatorPosition); const handleOnChange = (nextIndex: number) => { onChange?.(nextIndex); }; return ( {Children.map(children, (child, index) => { if (isValidElement(child)) { return cloneElement(child, { onPress: (event) => { child.props.onPress?.(event); handleOnChange(index); }, indicatorPosition, selected: index === selectedIndex, }); } })} ); }