_layout.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import React, { useEffect, useState } from 'react';
  2. import { Tabs, useSegments } from 'expo-router';
  3. import { Dimensions, Platform } from 'react-native';
  4. import {
  5. TabAccountIcon,
  6. TabChargingIcon,
  7. TabHomeIcon
  8. } from '../../../component/global/SVG';
  9. export default function TabLayout() {
  10. const { height } = Dimensions.get('window');
  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. },
  33. tabBarStyle: {
  34. height: height * 0.105,
  35. display: tabBarVisible ? 'flex' : 'none'
  36. },
  37. tabBarIconStyle: {
  38. width: 10,
  39. height: 10
  40. }
  41. }}
  42. >
  43. <Tabs.Screen
  44. name="(home)"
  45. options={{
  46. title: '主頁',
  47. // tabBarHideOnKeyboard: true,
  48. tabBarIcon: ({ focused }) => (
  49. <TabHomeIcon color={focused ? '#02677D' : '#BBBBBB'} />
  50. )
  51. }}
  52. />
  53. <Tabs.Screen
  54. name="(charging)"
  55. options={{
  56. title: '充電',
  57. tabBarHideOnKeyboard: true,
  58. tabBarIcon: ({ focused }) => (
  59. <TabChargingIcon
  60. color={focused ? '#02677D' : '#BBBBBB'}
  61. />
  62. )
  63. }}
  64. />
  65. <Tabs.Screen
  66. name="(account)"
  67. options={{
  68. title: '帳戶',
  69. tabBarHideOnKeyboard: true,
  70. tabBarIcon: ({ focused, color }) => (
  71. <TabAccountIcon
  72. color={focused ? '#02677D' : '#BBBBBB'}
  73. />
  74. )
  75. }}
  76. />
  77. </Tabs>
  78. );
  79. }