eletrotupi / tcc/ frontend/app/(tabs)/_layout.tsx11443325051f8ebf8d5bdcba4d184e4c95d1f887
2.7 KB | 94 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
import { routeForStatus } from "@/context/authRouting";
10

11
export default function TabLayout() {
12
  const { status, user } = useAuth();
13
  const href = routeForStatus(status, user);
14

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

23
  // `active` with onboarding seen is the only state that may render the tabs.
24
  if (status !== "active" || !user?.onboardingSeenAt) {
25
    return <Redirect href={href} />;
26
  }
27

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

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

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

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

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