eletrotupi / tcc/ frontend/app/(tabs)/_layout.tsx03018f2d5beb66e0c1bd781f487e742a516ef4bc
1.8 KB | 67 lines Raw
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="index"
44
        options={{
45
          title: 'Home',
46
          tabBarIcon: ({ color }) => <IconSymbol size={28} name="house.fill" color={color} />,
47
        }}
48
      />
49

50
      <Tabs.Screen
51
        name="explore"
52
        options={{
53
          title: 'Explore',
54
          tabBarIcon: ({ color }) => <IconSymbol size={28} name="paperplane.fill" color={color} />,
55
        }}
56
      />
57

58
      <Tabs.Screen
59
        name="settings"
60
        options={{
61
          title: 'Configurações',
62
          tabBarIcon: ({ color }) => <IconSymbol size={28} name="settings.fill" color={color} />,
63
        }}
64
      />
65
    </Tabs>
66
  );
67
}