eletrotupi / tcc/ frontend/app/(tabs)/_layout.tsx6e7ecd390ce119d438ab5b3ab16fa1d9edeb434a
1.7 KB | 66 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
        tabBarActiveTintColor: Colors[colorScheme ?? 'light'].tint,
37
        headerShown: false,
38
        tabBarButton: HapticTab,
39
      }}>
40

41
      <Tabs.Screen
42
        name="index"
43
        options={{
44
          title: 'Home',
45
          tabBarIcon: ({ color }) => <IconSymbol size={28} name="house.fill" color={color} />,
46
        }}
47
      />
48

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

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