eletrotupi / tcc/ frontend/app/(tabs)/_layout.tsxc167b931829e73be76860df22b78f8ac0951550e
1.5 KB | 56 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
      <Tabs.Screen
41
        name="index"
42
        options={{
43
          title: 'Home',
44
          tabBarIcon: ({ color }) => <IconSymbol size={28} name="house.fill" color={color} />,
45
        }}
46
      />
47
      <Tabs.Screen
48
        name="explore"
49
        options={{
50
          title: 'Explore',
51
          tabBarIcon: ({ color }) => <IconSymbol size={28} name="paperplane.fill" color={color} />,
52
        }}
53
      />
54
    </Tabs>
55
  );
56
}