|
1 | | -import { Styles } from "@/constants/Colors"; |
2 | 1 | import { Link, usePathname } from "expo-router"; |
3 | | -import { StyleSheet, Text, View } from "react-native"; |
| 2 | +import { Text, View } from "react-native"; |
4 | 3 | import GameBoardIcon from "./icons/gameBoard"; |
5 | 4 | import NewsIcon from "./icons/news"; |
6 | 5 | import RankIcon from "./icons/rank"; |
7 | 6 | import RegisterIcon from "./icons/register"; |
8 | 7 |
|
| 8 | +type TabItemProps = { |
| 9 | + icon: React.ComponentType<{ size: number }>; |
| 10 | + label: string; |
| 11 | + href?: string; |
| 12 | + disabled?: boolean; |
| 13 | + isActive?: boolean; |
| 14 | +}; |
| 15 | + |
| 16 | +type TabType = { |
| 17 | + icon: React.ComponentType<{ size: number; color?: string }>; |
| 18 | + label: string; |
| 19 | + href?: string; |
| 20 | + disabled?: boolean; |
| 21 | +}; |
| 22 | + |
| 23 | +const ICON_SIZE = 20; |
| 24 | + |
| 25 | +const TABS: TabType[] = [ |
| 26 | + { icon: RegisterIcon, label: "Register", disabled: true }, |
| 27 | + { icon: GameBoardIcon, label: "Game Board", href: "/" }, |
| 28 | + { icon: RankIcon, label: "Rank", disabled: true }, |
| 29 | + { icon: NewsIcon, label: "News", href: "/news" }, |
| 30 | +]; |
| 31 | + |
9 | 32 | export const Footer = () => { |
10 | 33 | const path = usePathname(); |
11 | 34 |
|
12 | | - if (path === "/chat") { |
13 | | - return null; |
14 | | - } |
| 35 | + if (path === "/chat") return null; |
15 | 36 |
|
16 | | - return ( |
17 | | - <View style={styles.footer}> |
18 | | - <View style={styles.disabledTab}> |
19 | | - <RegisterIcon size={20} /> |
20 | | - <Text style={styles.tabText}>Register</Text> |
| 37 | + const TabItem = ({ |
| 38 | + icon: Icon, |
| 39 | + label, |
| 40 | + href, |
| 41 | + disabled = false, |
| 42 | + isActive = false, |
| 43 | + }: TabItemProps) => { |
| 44 | + const content = ( |
| 45 | + <View |
| 46 | + className={`flex-col items-center p-2.5 |
| 47 | + ${disabled ? "opacity-50" : ""} |
| 48 | + ${isActive ? "opacity-100" : "opacity-70"}`} |
| 49 | + > |
| 50 | + <Icon size={ICON_SIZE} /> |
| 51 | + <Text className="text-white font-[Rubik_400Regular] text-sm mt-1.5"> |
| 52 | + {label} |
| 53 | + </Text> |
21 | 54 | </View> |
22 | | - <Link href="/" style={styles.resetLink}> |
23 | | - <View style={styles.tab}> |
24 | | - <GameBoardIcon size={20} /> |
25 | | - <Text style={styles.tabText}>Game Board</Text> |
26 | | - </View> |
27 | | - </Link> |
28 | | - <View style={styles.disabledTab}> |
29 | | - <RankIcon size={20} /> |
30 | | - <Text style={styles.tabText}>Rank</Text> |
31 | | - </View> |
32 | | - <Link href="/news" style={styles.resetLink}> |
33 | | - <View style={styles.tab}> |
34 | | - <NewsIcon size={20} /> |
35 | | - <Text style={styles.tabText}>News</Text> |
36 | | - </View> |
37 | | - </Link> |
| 55 | + ); |
| 56 | + |
| 57 | + if (href) { |
| 58 | + return ( |
| 59 | + <Link |
| 60 | + href={href as "/chat" | "/"} |
| 61 | + className="no-underline p-0 m-0" |
| 62 | + > |
| 63 | + {content} |
| 64 | + </Link> |
| 65 | + ); |
| 66 | + } |
| 67 | + |
| 68 | + return content; |
| 69 | + }; |
| 70 | + |
| 71 | + return ( |
| 72 | + <View className="flex-row justify-around items-center bg-[#1F1B1B] w-full h-[8%]"> |
| 73 | + {TABS.map((tab, index) => ( |
| 74 | + <TabItem |
| 75 | + key={index} |
| 76 | + icon={tab.icon} |
| 77 | + label={tab.label} |
| 78 | + href={tab.href} |
| 79 | + disabled={tab.disabled} |
| 80 | + isActive={tab.href ? path === tab.href : false} |
| 81 | + /> |
| 82 | + ))} |
38 | 83 | </View> |
39 | 84 | ); |
40 | 85 | }; |
41 | | - |
42 | | -const styles = StyleSheet.create({ |
43 | | - resetLink: { |
44 | | - textDecorationLine: "none", |
45 | | - padding: 0, |
46 | | - margin: 0, |
47 | | - }, |
48 | | - footer: { |
49 | | - flexDirection: "row", |
50 | | - justifyContent: "space-around", |
51 | | - alignItems: "center", |
52 | | - backgroundColor: Styles.colour.backgroundColour, |
53 | | - width: "100%", |
54 | | - height: "8%", |
55 | | - }, |
56 | | - tab: { |
57 | | - flexDirection: "column", |
58 | | - alignItems: "center", |
59 | | - padding: 10, |
60 | | - }, |
61 | | - tabText: { |
62 | | - color: "white", |
63 | | - fontFamily: "Rubik_400Regular", |
64 | | - fontSize: 14, |
65 | | - marginTop: 5, |
66 | | - }, |
67 | | - disabledTab: { |
68 | | - flexDirection: "column", |
69 | | - alignItems: "center", |
70 | | - opacity: 0.5, |
71 | | - padding: 10, |
72 | | - }, |
73 | | -}); |
|
0 commit comments