_layout.tsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { useEffect, useState } from 'react';
  2. import { Tabs, useSegments } from 'expo-router';
  3. import { Dimensions, Platform } from 'react-native';
  4. import { TabAccountIcon, TabChargingIcon, TabHomeIcon } from '../../../component/global/SVG';
  5. import { useColorScheme } from 'nativewind';
  6. import { useTranslation } from '../../../util/hooks/useTranslation';
  7. export default function TabLayout() {
  8. const { height } = Dimensions.get('window');
  9. const { colorScheme } = useColorScheme();
  10. const { t } = useTranslation();
  11. const activeColor = colorScheme === 'dark' ? '#36DFFF' : '#02677D';
  12. const inactiveColor = colorScheme === 'dark' ? '#666666' : '#BBBBBB';
  13. const segment = useSegments();
  14. const [tabBarVisible, setTabBarVisible] = useState(true);
  15. // Calculate marginBottom based on screen height
  16. const calculateMarginBottom = () => {
  17. if (Platform.OS === 'ios') return 0;
  18. if (height < 600) return 0;
  19. return 15;
  20. };
  21. useEffect(() => {
  22. // Determine if the tab bar should be visible based on the current segment
  23. const isScanQrPage = segment[segment.length - 1] === 'scanQrPage';
  24. setTabBarVisible(!isScanQrPage);
  25. }, [segment]);
  26. return (
  27. <Tabs
  28. screenOptions={{
  29. headerShown: false,
  30. tabBarLabelStyle: {
  31. fontSize: 16,
  32. marginBottom: calculateMarginBottom(),
  33. color: colorScheme === 'dark' ? '#CCCCCC' : '#666666'
  34. },
  35. tabBarStyle: {
  36. height: height * 0.105,
  37. display: tabBarVisible ? 'flex' : 'none',
  38. backgroundColor: colorScheme === 'dark' ? '#041316' : '#FFFFFF'
  39. },
  40. tabBarIconStyle: {
  41. width: 10,
  42. height: 10,
  43. marginTop: 15,
  44. marginBottom: 15
  45. }
  46. }}
  47. >
  48. <Tabs.Screen
  49. name="(home)"
  50. options={{
  51. title: t('tabs.home'),
  52. // tabBarHideOnKeyboard: true,
  53. tabBarIcon: ({ focused }) => <TabHomeIcon color={focused ? activeColor : inactiveColor} />
  54. }}
  55. />
  56. <Tabs.Screen
  57. name="(charging)"
  58. options={{
  59. title: t('tabs.charging'),
  60. tabBarHideOnKeyboard: true,
  61. tabBarIcon: ({ focused }) => <TabChargingIcon color={focused ? activeColor : inactiveColor} />
  62. }}
  63. />
  64. <Tabs.Screen
  65. name="(account)"
  66. options={{
  67. title: t('tabs.account'),
  68. tabBarHideOnKeyboard: true,
  69. tabBarIcon: ({ focused }) => <TabAccountIcon color={focused ? activeColor : inactiveColor} />
  70. }}
  71. />
  72. </Tabs>
  73. );
  74. }