_layout.tsx 2.3 KB

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