eletrotupi / tcc/ frontend/app/(tabs)/_layout.tsx114be98ec7798e84a9f63b79b00cf224e5f3c8d8
2.3 KB | 94 lines Raw
1
import { Tabs } from "expo-router/js-tabs";
2
import { Redirect, router } from "expo-router";
3
import React, { useEffect } from "react";
4
import { View, ActivityIndicator } from "react-native";
5

6
import { HapticTab } from "@/components/misc/haptic-tab";
7
import { IconSymbol } from "@/components/ui/icon-symbol";
8
import { Colors } from "@/constants/theme";
9
import { useColorScheme } from "@/hooks/use-color-scheme";
10
import { useAuth } from "@/context/AuthContext";
11

12
export default function TabLayout() {
13
  const colorScheme = useColorScheme();
14
  const { isAuthenticated, isLoading } = useAuth();
15

16
  useEffect(() => {
17
    if (!isLoading && !isAuthenticated) {
18
      router.replace("/auth/login");
19
    }
20
  }, [isAuthenticated, isLoading]);
21

22
  if (isLoading) {
23
    return (
24
      <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
25
        <ActivityIndicator size="large" />
26
      </View>
27
    );
28
  }
29

30
  if (!isAuthenticated) {
31
    return <Redirect href="/auth/login" />;
32
  }
33

34
  return (
35
    <Tabs
36
      screenOptions={{
37
        tabBarInactiveTintColor: Colors["light"].tabIconDefault,
38
        tabBarActiveTintColor: Colors["light"].tabIconSelected,
39
        headerShown: false,
40
        tabBarButton: HapticTab,
41
      }}
42
    >
43
      <Tabs.Screen
44
        name="history"
45
        options={{
46
          title: "Histórico",
47
          tabBarIcon: ({ color }) => (
48
            <IconSymbol size={28} name="history" color={color} />
49
          ),
50
        }}
51
      />
52

53
      <Tabs.Screen
54
        name="insights"
55
        options={{
56
          title: "Jornada",
57
          tabBarIcon: ({ color }) => (
58
            <IconSymbol size={28} name="book" color={color} />
59
          ),
60
        }}
61
      />
62

63
      <Tabs.Screen
64
        name="new"
65
        options={{
66
          title: "Novo",
67
          tabBarIcon: ({ color }) => (
68
            <IconSymbol size={28} name="add-circle" color={color} />
69
          ),
70
        }}
71
      />
72

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

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