import { useEffect } from 'react'; import { Center, HStack, Icon, Pressable, Text } from 'native-base'; import { Platform } from 'react-native'; import { MaterialCommunityIcons } from '@expo/vector-icons'; import { useNavigate, useLocation } from 'expo-react-router-wrapper'; import { useStoredState } from 'react-native-use-stored-state'; interface Tab { label: string; icon: string; target: string; } const tabs: Tab[] = [ { label: 'Home', icon: 'home', target: '/', }, { label: 'About', icon: 'information', target: '/About', }, ]; export const Navigation = () => { const location = useLocation(); const navigate = useNavigate(); const [selectedTab, setSelectedTab] = useStoredState('ACTIVE_NAV_TAB', 0); useEffect(() => { tabs.forEach((tab: Tab, id: number) => { if (tab.label && location.pathname.includes(tab.label)) { setSelectedTab(id); } }); }, [location, setSelectedTab]); return ( {tabs.map((tab: Tab, id: number) => ( { setSelectedTab(id); navigate(tab.target) }} >
{tab.label}
))}
); };