_layout.tsx 2.7 KB

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