|
| 1 | +import React from 'react' |
| 2 | + |
| 3 | +import MaterialIcons from '@expo/vector-icons/MaterialIcons' |
| 4 | +import { Link, Tabs } from 'expo-router' |
| 5 | +import { Button, Platform, View } from 'react-native' |
| 6 | + |
| 7 | +import { HapticTab } from '@/components/HapticTab' |
| 8 | +import TabBarBackground from '@/components/ui/TabBarBackground' |
| 9 | +import { Colors } from '@/constants/Colors' |
| 10 | +import { useAuth } from '@/context/auth' |
| 11 | +import { useColorScheme } from '@/hooks/useColorScheme' |
| 12 | + |
| 13 | +export default function TabLayout() { |
| 14 | + const colorScheme = useColorScheme() |
| 15 | + const { isAuthenticated, logOut } = useAuth() |
| 16 | + |
| 17 | + return ( |
| 18 | + <Tabs |
| 19 | + screenOptions={{ |
| 20 | + tabBarActiveTintColor: Colors[colorScheme ?? 'light'].tint, |
| 21 | + tabBarButton: HapticTab, |
| 22 | + tabBarBackground: TabBarBackground, |
| 23 | + tabBarStyle: Platform.select({ |
| 24 | + ios: { |
| 25 | + // Use a transparent background on iOS to show the blur effect |
| 26 | + position: 'absolute', |
| 27 | + }, |
| 28 | + default: {}, |
| 29 | + }), |
| 30 | + headerRight: () => ( |
| 31 | + <View style={{ marginRight: 16 }}> |
| 32 | + {isAuthenticated ? ( |
| 33 | + <Button onPress={logOut} title="Logout" color="red" /> |
| 34 | + ) : ( |
| 35 | + <Link href="/modal">Login</Link> |
| 36 | + )} |
| 37 | + </View> |
| 38 | + ), |
| 39 | + }} |
| 40 | + > |
| 41 | + <Tabs.Screen |
| 42 | + name="index" |
| 43 | + options={{ |
| 44 | + title: 'Posts', |
| 45 | + tabBarIcon: ({ color }) => ( |
| 46 | + <MaterialIcons name="article" size={28} color={color} /> |
| 47 | + ), |
| 48 | + }} |
| 49 | + /> |
| 50 | + <Tabs.Screen |
| 51 | + name="admin" |
| 52 | + options={{ |
| 53 | + title: 'Admin', |
| 54 | + tabBarIcon: ({ color }) => ( |
| 55 | + <MaterialIcons |
| 56 | + name="admin-panel-settings" |
| 57 | + size={28} |
| 58 | + color={color} |
| 59 | + /> |
| 60 | + ), |
| 61 | + }} |
| 62 | + /> |
| 63 | + </Tabs> |
| 64 | + ) |
| 65 | +} |
0 commit comments