import * as Icons from '@/assets/icons'; import { BottomSpacer, Text, Touchable } from '@/components/core'; import { HORIZONTAL_SAFETY_EDGES, TAB_BAR_HEIGHT } from '@/core/constants'; import { TabScreenName } from '@/core/enums'; import { useAppTranslation, useKeyboard, useTailwind } from '@/hooks'; import { BottomTabBarProps } from '@react-navigation/bottom-tabs'; import { FC, useMemo } from 'react'; import { View } from 'react-native'; import Animated, { useAnimatedStyle, withTiming } from 'react-native-reanimated'; import { SafeAreaView } from 'react-native-safe-area-context'; import { SvgProps } from 'react-native-svg'; interface TabUI { icon: FC; focusedIcon: FC; focusedColor?: string; label: string; } const AnimatedSafeAreaView = Animated.createAnimatedComponent(SafeAreaView); export default function CustomizedTabBar({ state, descriptors, navigation }: BottomTabBarProps) { const tw = useTailwind(); const { t } = useAppTranslation('tab'); const { keyboardShown } = useKeyboard(); const tabUI: Record = useMemo( () => ({ [TabScreenName.Home]: { icon: Icons.Home, focusedIcon: Icons.HomeFocused, focusedColor: tw.color('violet-500'), label: t('home'), }, [TabScreenName.Messages]: { icon: Icons.Messages, focusedIcon: Icons.MessagesFocused, focusedColor: tw.color('orange-500'), label: t('messages'), }, [TabScreenName.Notification]: { icon: Icons.Notification, focusedIcon: Icons.NotificationFocused, focusedColor: tw.color('red-500'), label: t('notification'), }, [TabScreenName.Profile]: { icon: Icons.Profile, focusedIcon: Icons.ProfileFocused, focusedColor: tw.color('blue-500'), label: t('profile'), }, }), [t, tw], ); const tabBarAnimatedStyle = useAnimatedStyle( () => ({ transform: [{ translateY: withTiming(keyboardShown ? 100 : 0) }], }), [keyboardShown], ); return ( {state.routes.map((route, index) => { const { options } = descriptors[route.key]; const screenName = route.name as TabScreenName; const { icon: Icon, focusedIcon: FocusedIcon, focusedColor, label } = tabUI[screenName]; const isFocused = state.index === index; const onPress = () => { const event = navigation.emit({ type: 'tabPress', target: route.key, canPreventDefault: true, }); if (!isFocused && !event.defaultPrevented) { navigation.navigate({ name: screenName, params: undefined, merge: true, }); } }; const onLongPress = () => { navigation.emit({ type: 'tabLongPress', target: route.key, }); }; return ( {isFocused ? ( ) : ( )} {label} ); })} ); }