import { Colors } from "@/constants/Colors"; // Import Colors import { Images } from "@/constants/images"; import { Image } from "expo-image"; import { usePathname, useRouter, useSegments } from "expo-router"; import React from "react"; import { Dimensions, StyleSheet, Text, TouchableOpacity, View, } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; const { width: SCREEN_WIDTH } = Dimensions.get("window"); const tabList = [ { name: "大厅", // Was 首页 route: "/", img: Images.tabs.home, active: Images.tabs.homeActive, }, { name: "矩阵", // Was 开箱 route: "/box", img: Images.tabs.box, active: Images.tabs.boxActive, }, { name: "次元", // Was 福利 route: "/dimension", img: Images.tabs.welfare, active: Images.tabs.welfareActive, }, { name: "档案", // Was 我的 route: "/mine", img: Images.tabs.mine, active: Images.tabs.mineActive, }, ]; export function CustomTabBar() { const router = useRouter(); const segments = useSegments(); const pathname = usePathname(); const insets = useSafeAreaInsets(); const getTabIndex = () => { // Check Box if (segments[1] === "box" || pathname?.startsWith("/box")) return 1; // Check Dimension (formerly Welfare) if ( (segments[1] as string) === "dimension" || pathname?.startsWith("/dimension") ) return 2; // Check Mine if (segments[1] === "mine" || pathname?.startsWith("/mine")) return 3; // Check Home (Explicit) if ( (segments[1] as string) === "index" || pathname === "/" || pathname === "/index" ) return 0; return -1; }; const [currentIndex, setCurrentIndex] = React.useState(() => { const idx = getTabIndex(); return idx === -1 ? 0 : idx; }); React.useEffect(() => { const idx = getTabIndex(); if (idx !== -1) { setCurrentIndex(idx); } }, [segments, pathname]); const handlePress = (index: number) => { const route = tabList[index].route; router.replace(route as any); }; return ( {/* Replaced ImageBackground with View for Cyberpunk style */} {tabList.map((item, index) => { const isActive = currentIndex === index; return ( handlePress(index)} > {item.name} ); })} ); } const styles = StyleSheet.create({ wrapper: { position: "absolute", bottom: 0, left: 0, right: 0, zIndex: 999, }, container: { width: SCREEN_WIDTH, height: 85, // Slightly taller for labels backgroundColor: Colors.darkBg, borderTopWidth: 1, borderTopColor: Colors.neonBlue, borderTopLeftRadius: 20, borderTopRightRadius: 20, // Neon Glow shadowColor: Colors.neonBlue, shadowOffset: { width: 0, height: -2 }, shadowOpacity: 0.3, shadowRadius: 10, elevation: 10, paddingBottom: 20, // For home indicator }, center: { flex: 1, flexDirection: "row", alignItems: "center", }, item: { flex: 1, justifyContent: "center", alignItems: "center", paddingTop: 10, }, iconContainer: { width: 28, height: 28, marginBottom: 4, justifyContent: "center", alignItems: "center", }, activeIconContainer: { // Optional: Add glow behind active icon }, icon: { width: "100%", height: "100%", }, label: { fontSize: 10, fontWeight: "bold", }, });