Files
FarmaFinder/apps/frontend-mobile/app/(tabs)/_layout.tsx
T
Antoni Nuñez Romeu 69ef048388
Run Tests on Branches / Detect Changes (push) Successful in 8s
Run Tests on Branches / Backend Tests (push) Has been skipped
Run Tests on Branches / Frontend Tests (push) Has been skipped
Run Tests on Branches / Frontend Mobile Tests (push) Successful in 1m39s
fix: tab bar not visible on Android
Add SafeAreaProvider to root layout and use dynamic safe area insets
for tab bar height/padding instead of hardcoded values that didn't
account for Android system navigation bar.
2026-07-07 21:04:42 +02:00

128 lines
3.1 KiB
TypeScript

import { Tabs } from 'expo-router';
import { Ionicons } from '@expo/vector-icons';
import { View, StyleSheet, Platform } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { colors, shadows } from '../../constants/theme';
function ScanIcon({ color, size }: { color: string; size: number }) {
return (
<View style={styles.fabContainer}>
<View style={[styles.fab, shadows.scanButton]}>
<Ionicons name="scan" size={size} color="#ffffff" />
</View>
</View>
);
}
export default function TabLayout() {
const insets = useSafeAreaInsets();
const bottomPadding = Platform.OS === 'ios' ? insets.bottom : 8;
return (
<Tabs
screenOptions={{
tabBarActiveTintColor: colors.primary,
tabBarInactiveTintColor: colors.textSecondary,
tabBarStyle: {
...styles.tabBar,
height: 60 + bottomPadding,
paddingBottom: bottomPadding,
},
tabBarLabelStyle: styles.tabBarLabel,
headerStyle: styles.header,
headerTintColor: colors.primary,
headerTitleStyle: styles.headerTitle,
}}
>
<Tabs.Screen
name="home"
options={{
title: 'Inicio',
tabBarIcon: ({ color, size }) => (
<Ionicons name="home" size={size} color={color} />
),
}}
/>
<Tabs.Screen
name="index"
options={{
title: 'Buscar',
tabBarIcon: ({ color, size }) => (
<Ionicons name="search" size={size} color={color} />
),
}}
/>
<Tabs.Screen
name="scan"
options={{
title: 'Escanear',
tabBarIcon: ({ color, size }) => <ScanIcon color={color} size={size} />,
tabBarLabel: () => null,
}}
/>
<Tabs.Screen
name="alerts"
options={{
title: 'Avisos',
tabBarIcon: ({ color, size }) => (
<Ionicons name="notifications" size={size} color={color} />
),
}}
/>
<Tabs.Screen
name="map"
options={{
href: null,
}}
/>
<Tabs.Screen
name="profile"
options={{
title: 'Perfil',
tabBarIcon: ({ color, size }) => (
<Ionicons name="person" size={size} color={color} />
),
}}
/>
</Tabs>
);
}
const styles = StyleSheet.create({
tabBar: {
backgroundColor: colors.card,
borderTopColor: colors.border,
paddingTop: 8,
},
tabBarLabel: {
fontSize: 11,
fontWeight: '500',
},
header: {
backgroundColor: colors.card,
shadowColor: '#000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.05,
shadowRadius: 4,
elevation: 1,
},
headerTitle: {
color: colors.text,
fontWeight: '600',
fontSize: 17,
},
fabContainer: {
position: 'absolute',
top: -16,
alignItems: 'center',
},
fab: {
width: 52,
height: 52,
borderRadius: 26,
backgroundColor: colors.scanButton,
alignItems: 'center',
justifyContent: 'center',
},
});