| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import { useEffect, useState } from 'react';
- import { Tabs, useSegments } from 'expo-router';
- import { Dimensions, Platform } from 'react-native';
- import { TabAccountIcon, TabChargingIcon, TabHomeIcon } from '../../../component/global/SVG';
- import { useColorScheme } from 'nativewind';
- import { useTranslation } from '../../../util/hooks/useTranslation';
- export default function TabLayout() {
- const { height } = Dimensions.get('window');
- const { colorScheme } = useColorScheme();
- const { t } = useTranslation();
- const activeColor = colorScheme === 'dark' ? '#36DFFF' : '#02677D';
- const inactiveColor = colorScheme === 'dark' ? '#666666' : '#BBBBBB';
- const segment = useSegments();
- const [tabBarVisible, setTabBarVisible] = useState(true);
- // Calculate marginBottom based on screen height
- const calculateMarginBottom = () => {
- if (Platform.OS === 'ios') return 0;
- if (height < 600) return 0;
- return 15;
- };
- useEffect(() => {
- // Determine if the tab bar should be visible based on the current segment
- const isScanQrPage = segment[segment.length - 1] === 'scanQrPage';
- setTabBarVisible(!isScanQrPage);
- }, [segment]);
- return (
- <Tabs
- screenOptions={{
- headerShown: false,
- tabBarLabelStyle: {
- fontSize: 16,
- marginBottom: calculateMarginBottom(),
- color: colorScheme === 'dark' ? '#CCCCCC' : '#666666'
- },
- tabBarStyle: {
- height: height * 0.105,
- display: tabBarVisible ? 'flex' : 'none',
- backgroundColor: colorScheme === 'dark' ? '#041316' : '#FFFFFF'
- },
- tabBarIconStyle: {
- width: 10,
- height: 10,
- marginTop: 15,
- marginBottom: 15
- }
- }}
- >
- <Tabs.Screen
- name="(home)"
- options={{
- title: t('tabs.home'),
- // tabBarHideOnKeyboard: true,
- tabBarIcon: ({ focused }) => <TabHomeIcon color={focused ? activeColor : inactiveColor} />
- }}
- />
- <Tabs.Screen
- name="(charging)"
- options={{
- title: t('tabs.charging'),
- tabBarHideOnKeyboard: true,
- tabBarIcon: ({ focused }) => <TabChargingIcon color={focused ? activeColor : inactiveColor} />
- }}
- />
- <Tabs.Screen
- name="(account)"
- options={{
- title: t('tabs.account'),
- tabBarHideOnKeyboard: true,
- tabBarIcon: ({ focused }) => <TabAccountIcon color={focused ? activeColor : inactiveColor} />
- }}
- />
- </Tabs>
- );
- }
|