92 lines
2.6 KiB
TypeScript
92 lines
2.6 KiB
TypeScript
import { Tabs, useSegments } from "expo-router";
|
|
|
|
import { HapticTab } from "@/components/haptic-tab";
|
|
import { IconSymbol } from "@/components/ui/icon-symbol";
|
|
import { Colors } from "@/constants/theme";
|
|
import { useColorScheme } from "@/hooks/use-color-scheme";
|
|
import { startEvents, stopEvents } from "@/services/device_events";
|
|
import { useEffect, useRef } from "react";
|
|
|
|
export default function TabLayout() {
|
|
const colorScheme = useColorScheme();
|
|
const segments = useSegments();
|
|
const prev = useRef<string | null>(null);
|
|
const currentSegment = segments[1] ?? segments[segments.length - 1] ?? null; // tuỳ cấu trúc của bạn
|
|
useEffect(() => {
|
|
if (prev.current !== currentSegment) {
|
|
// console.log("Tab changed ->", { from: prev.current, to: currentSegment });
|
|
// TODO: xử lý khi chuyển tab ở đây
|
|
if (prev.current === "(tabs)" && currentSegment !== "(tabs)") {
|
|
stopEvents();
|
|
console.log("Stop events");
|
|
} else if (prev.current !== "(tabs)" && currentSegment === "(tabs)") {
|
|
// we came back into the tabs group — restart polling
|
|
startEvents();
|
|
console.log("start events");
|
|
}
|
|
prev.current = currentSegment;
|
|
}
|
|
}, [currentSegment]);
|
|
|
|
return (
|
|
<Tabs
|
|
screenOptions={{
|
|
tabBarActiveTintColor: Colors[colorScheme ?? "light"].tint,
|
|
headerShown: false,
|
|
tabBarButton: HapticTab,
|
|
}}
|
|
>
|
|
<Tabs.Screen
|
|
name="index"
|
|
options={{
|
|
title: "Giám sát",
|
|
tabBarIcon: ({ color }) => (
|
|
<IconSymbol size={28} name="map.fill" color={color} />
|
|
),
|
|
}}
|
|
/>
|
|
|
|
<Tabs.Screen
|
|
name="tripInfo"
|
|
options={{
|
|
title: "Chuyến Đi",
|
|
tabBarIcon: ({ color }) => (
|
|
<IconSymbol size={28} name="ferry.fill" color={color} />
|
|
),
|
|
}}
|
|
/>
|
|
<Tabs.Screen
|
|
name="diary"
|
|
options={{
|
|
title: "Nhật Ký",
|
|
tabBarIcon: ({ color }) => (
|
|
<IconSymbol size={28} name="book.closed.fill" color={color} />
|
|
),
|
|
}}
|
|
/>
|
|
<Tabs.Screen
|
|
name="sensor"
|
|
options={{
|
|
title: "Cảm biến",
|
|
tabBarIcon: ({ color }) => (
|
|
<IconSymbol
|
|
size={28}
|
|
name="dot.radiowaves.left.and.right"
|
|
color={color}
|
|
/>
|
|
),
|
|
}}
|
|
/>
|
|
<Tabs.Screen
|
|
name="setting"
|
|
options={{
|
|
title: "Cài đặt",
|
|
tabBarIcon: ({ color }) => (
|
|
<IconSymbol size={28} name="gear" color={color} />
|
|
),
|
|
}}
|
|
/>
|
|
</Tabs>
|
|
);
|
|
}
|