import { memo, useState, useMemo } from "react"; import { useIsDarkMode } from "@showtime-xyz/universal.hooks"; import { ChevronRight } from "@showtime-xyz/universal.icon"; import { Pressable } from "@showtime-xyz/universal.pressable"; import { colors } from "@showtime-xyz/universal.tailwind"; import { Text } from "@showtime-xyz/universal.text"; import { View } from "@showtime-xyz/universal.view"; import { Route } from "."; type TabBarVerticalProps = { routes: Route[]; index: number; onPress?: (index: number) => void; tw?: string; }; const OFFSET = 16; export const TabBarVertical = memo( function TabBarVertical({ routes, index: propIndex, onPress, tw = "" }) { const isDark = useIsDarkMode(); const [tabsHeight, setTabsHeight] = useState<{ [index: number]: number; }>({}); const outputRange = useMemo( () => routes.reduce((acc, _, i) => { if (i === 0) return [OFFSET]; return [...acc, acc[i - 1] + tabsHeight[i - 1]]; }, []), [routes, tabsHeight] ); return ( {routes.map((item, index) => ( onPress?.(index)} onLayout={({ nativeEvent: { layout: { height }, }, }) => { const tabs = Object.assign(tabsHeight, { [index]: height, }); if (Object.keys(tabsHeight).length === routes.length) { setTabsHeight({ ...tabs }); } }} > {item.title} ))} ); } );