eletrotupi / tcc/ frontend/app/(tabs)/_layout.tsxd0ab9930b8d2efe12277e2365410dade4162f9c5
2.5 KB | 91 lines Raw
1
import { Tabs } from "expo-router/js-tabs";
2
import { Redirect } from "expo-router";
3
import { View, ActivityIndicator } from "react-native";
4

5
import { HapticTab } from "@/components/misc/haptic-tab";
6
import { IconSymbol } from "@/components/ui/icon-symbol";
7
import { Colors } from "@/constants/theme";
8
import { useAuth } from "@/context/AuthContext";
9

10
export default function TabLayout() {
11
  const { isAuthenticated, isLoading } = useAuth();
12

13
  if (isLoading) {
14
    return (
15
      <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
16
        <ActivityIndicator size="large" />
17
      </View>
18
    );
19
  }
20

21
  if (!isAuthenticated) {
22
    return <Redirect href="/auth/login" />;
23
  }
24

25
  return (
26
    <Tabs
27
      screenOptions={{
28
        tabBarInactiveTintColor: Colors["light"].tabIconDefault,
29
        tabBarActiveTintColor: Colors["light"].tabIconSelected,
30
        headerShown: false,
31
        tabBarButton: HapticTab,
32
        freezeOnBlur: true,
33
      }}
34
    >
35
      <Tabs.Screen
36
        name="history"
37
        options={{
38
          title: "Histórico",
39
          tabBarIcon: ({ color }) => (
40
            <IconSymbol size={28} name="history" color={color} />
41
          ),
42
          tabBarButton: (props) => <HapticTab {...props} testID="tab-history" />,
43
        }}
44
      />
45

46
      <Tabs.Screen
47
        name="insights"
48
        options={{
49
          title: "Jornada",
50
          tabBarIcon: ({ color }) => (
51
            <IconSymbol size={28} name="book" color={color} />
52
          ),
53
          tabBarButton: (props) => <HapticTab {...props} testID="tab-journey" />,
54
        }}
55
      />
56

57
      <Tabs.Screen
58
        name="new"
59
        options={{
60
          title: "Novo",
61
          tabBarIcon: ({ color }) => (
62
            <IconSymbol size={28} name="add-circle" color={color} />
63
          ),
64
          tabBarButton: (props) => <HapticTab {...props} testID="tab-new" />,
65
        }}
66
      />
67

68
      <Tabs.Screen
69
        name="actions"
70
        options={{
71
          title: "Ações",
72
          tabBarIcon: ({ color }) => (
73
            <IconSymbol size={28} name="bolt" color={color} />
74
          ),
75
          tabBarButton: (props) => <HapticTab {...props} testID="tab-actions" />,
76
        }}
77
      />
78

79
      <Tabs.Screen
80
        name="settings"
81
        options={{
82
          title: "Ajustes",
83
          tabBarIcon: ({ color }) => (
84
            <IconSymbol size={28} name="settings.fill" color={color} />
85
          ),
86
          tabBarButton: (props) => <HapticTab {...props} testID="tab-settings" />,
87
        }}
88
      />
89
    </Tabs>
90
  );
91
}