import React from 'react'; import { View } from 'react-native'; import { TabBar } from './TabBar'; import type { StyleProp, ViewStyle } from 'react-native'; import type { Route, RenderTabBar, RenderScene } from './types'; type Props = { routes: ReadonlyArray; onPress: (index: number) => void; renderTabBar: RenderTabBar; renderScene: RenderScene; style?: StyleProp; tabBarStyle?: StyleProp; tabBarContentContainerStyle?: StyleProp; tabBarOverflowWitdth?: number; }; export function TabView({ routes, onPress, renderTabBar, renderScene, style, tabBarStyle, tabBarContentContainerStyle, tabBarOverflowWitdth, }: Props) { const [currentIndex, setCurrentIndex] = React.useState(0); const onTabPress = React.useCallback( (index: number) => { setCurrentIndex(index); onPress(index); }, [onPress] ); const scene = React.useMemo(() => { renderScene(routes[currentIndex] as Route); }, [currentIndex, renderScene, routes]); return ( {scene} ); }