import { useMemo, useCallback } from 'react'; import { Platform, Pressable, useWindowDimensions } from 'react-native'; import { Tabs, usePathname, useRouter } from 'expo-router'; import { MaterialCommunityIcons } from '@expo/vector-icons'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import type { PressableProps } from 'react-native'; import { useAppColors, shadows } from '../../../src/theme'; import { BREAKPOINTS } from '../../../src/hooks'; import { useHomeTabBarVisibilityStore, useTotalUnreadCount, useHomeTabPressStore } from '../../../src/stores'; import { hrefHome } from '../../../src/navigation/hrefs'; const TAB_BAR_HEIGHT = 56; const TAB_BAR_FLOATING_MARGIN = 12; const TAB_BAR_MARGIN = 20; const TabBarButton = ({ children, style, ...rest }: PressableProps) => ( {children} ); export default function TabsLayout() { const colors = useAppColors(); const { width } = useWindowDimensions(); const insets = useSafeAreaInsets(); const pathname = usePathname(); const router = useRouter(); const unreadCount = useTotalUnreadCount(); const scrollHideTabBar = useHomeTabBarVisibilityStore((s) => s.bottomTabBarHiddenByScroll); const triggerHomeTabPress = useHomeTabPressStore((s) => s.triggerPress); const hideTabBar = Platform.OS === 'web' && width >= BREAKPOINTS.desktop; const isHomeStackRoute = pathname === '/home' || pathname.startsWith('/home/'); const handleHomeTabPress = useCallback( (e: { preventDefault: () => void }) => { if (!isHomeStackRoute) return; e.preventDefault(); if (pathname === '/home') { triggerHomeTabPress(); } else { router.navigate(hrefHome()); } }, [isHomeStackRoute, pathname, triggerHomeTabPress, router] ); const tabBarStyle = useMemo(() => { if (hideTabBar) { return { display: 'none' as const, height: 0, overflow: 'hidden' as const }; } const visibleStyle = { position: 'absolute' as const, left: 0, right: 0, marginHorizontal: TAB_BAR_MARGIN, bottom: TAB_BAR_FLOATING_MARGIN + insets.bottom, height: TAB_BAR_HEIGHT, borderRadius: 22, backgroundColor: colors.background.paper, ...shadows.lg, borderTopWidth: 0, elevation: 100, zIndex: 100, }; if (isHomeStackRoute && scrollHideTabBar) { return { ...visibleStyle, display: 'none' as const, height: 0, opacity: 0, overflow: 'hidden' as const, }; } return visibleStyle; }, [hideTabBar, insets.bottom, isHomeStackRoute, scrollHideTabBar, colors]); return ( , tabBarShowLabel: true, tabBarLabelStyle: { fontSize: 11, fontWeight: '600', marginTop: -1 }, }} > ( ), }} listeners={{ tabPress: handleHomeTabPress, }} /> ( ), }} /> 0 ? (unreadCount > 99 ? 99 : unreadCount) : undefined, tabBarIcon: ({ color, focused }) => ( ), }} /> ( ), }} /> ); }