| 1 | import { Tabs, Redirect, router } from "expo-router";
|
| 2 | import React, { useEffect } from "react";
|
| 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 { useColorScheme } from "@/hooks/use-color-scheme";
|
| 9 | import { useAuth } from "@/context/AuthContext";
|
| 10 |
|
| 11 | export default function TabLayout() {
|
| 12 | const colorScheme = useColorScheme();
|
| 13 | const { isAuthenticated, isLoading } = useAuth();
|
| 14 |
|
| 15 | useEffect(() => {
|
| 16 | if (!isLoading && !isAuthenticated) {
|
| 17 | router.replace("/auth/login");
|
| 18 | }
|
| 19 | }, [isAuthenticated, isLoading]);
|
| 20 |
|
| 21 | if (isLoading) {
|
| 22 | return (
|
| 23 | <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
|
| 24 | <ActivityIndicator size="large" />
|
| 25 | </View>
|
| 26 | );
|
| 27 | }
|
| 28 |
|
| 29 | if (!isAuthenticated) {
|
| 30 | return <Redirect href="/auth/login" />;
|
| 31 | }
|
| 32 |
|
| 33 | return (
|
| 34 | <Tabs
|
| 35 | screenOptions={{
|
| 36 | tabBarInactiveTintColor: Colors["light"].tabIconDefault,
|
| 37 | tabBarActiveTintColor: Colors["light"].tabIconSelected,
|
| 38 | headerShown: false,
|
| 39 | tabBarButton: HapticTab,
|
| 40 | }}
|
| 41 | >
|
| 42 | <Tabs.Screen
|
| 43 | name="history"
|
| 44 | options={{
|
| 45 | title: "Histórico",
|
| 46 | tabBarIcon: ({ color }) => (
|
| 47 | <IconSymbol size={28} name="history" color={color} />
|
| 48 | ),
|
| 49 | }}
|
| 50 | />
|
| 51 |
|
| 52 | <Tabs.Screen
|
| 53 | name="insights"
|
| 54 | options={{
|
| 55 | title: "Jornada",
|
| 56 | tabBarIcon: ({ color }) => (
|
| 57 | <IconSymbol size={28} name="book" color={color} />
|
| 58 | ),
|
| 59 | }}
|
| 60 | />
|
| 61 |
|
| 62 | <Tabs.Screen
|
| 63 | name="new"
|
| 64 | options={{
|
| 65 | title: "Novo",
|
| 66 | tabBarIcon: ({ color }) => (
|
| 67 | <IconSymbol size={28} name="add-circle" color={color} />
|
| 68 | ),
|
| 69 | }}
|
| 70 | />
|
| 71 |
|
| 72 | <Tabs.Screen
|
| 73 | name="actions"
|
| 74 | options={{
|
| 75 | title: "Ações",
|
| 76 | tabBarIcon: ({ color }) => (
|
| 77 | <IconSymbol size={28} name="bolt" color={color} />
|
| 78 | ),
|
| 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 | }}
|
| 90 | />
|
| 91 | </Tabs>
|
| 92 | );
|
| 93 | }
|