_layout.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { Stack } from 'expo-router/stack';
  2. import AuthProvider, { useAuth } from '../context/AuthProvider';
  3. import { EXPO_PUBLIC_NODE_ENV } from '@env';
  4. import { GestureHandlerRootView } from 'react-native-gesture-handler';
  5. import { useEffect, useState } from 'react';
  6. import { checkVersion } from '../component/checkVersion';
  7. import { authenticationService } from '../service/authService';
  8. import { usePushNotifications } from './hooks/usePushNotifications';
  9. import Constants from 'expo-constants';
  10. import { Alert, AppState } from 'react-native';
  11. export default function RootLayout() {
  12. const [isLoading, setIsLoading] = useState(true);
  13. const { user } = useAuth();
  14. const { expoPushToken, notification } = usePushNotifications();
  15. const data = JSON.stringify(notification, undefined, 2);
  16. useEffect(() => {
  17. const fetchVersion = async () => {
  18. const response = await authenticationService.getVersion();
  19. checkVersion(response);
  20. };
  21. // Initial version check
  22. fetchVersion();
  23. // Set up AppState listener
  24. const subscription = AppState.addEventListener('change', (nextAppState) => {
  25. if (nextAppState === 'active') {
  26. fetchVersion();
  27. }
  28. });
  29. // Cleanup subscription on unmount
  30. return () => {
  31. subscription.remove();
  32. };
  33. }, []);
  34. return (
  35. <GestureHandlerRootView style={{ flex: 1 }}>
  36. <AuthProvider>
  37. <Stack>
  38. <Stack.Screen name="(auth)/(tabs)" options={{ headerShown: false }} />
  39. <Stack.Screen name="(public)/login" options={{ headerShown: false }} />
  40. <Stack.Screen name="(public)/registerChooseVehiclesOne" options={{ headerShown: false }} />
  41. <Stack.Screen name="(public)/registerChooseVehiclesTwo" options={{ headerShown: false }} />
  42. {/* Testing Purpose */}
  43. {EXPO_PUBLIC_NODE_ENV == 'development' ? (
  44. <Stack.Screen
  45. name="(public)/test"
  46. options={{
  47. headerShown: false,
  48. title: 'Test Component Page'
  49. }}
  50. />
  51. ) : (
  52. <></>
  53. )}
  54. </Stack>
  55. </AuthProvider>
  56. </GestureHandlerRootView>
  57. );
  58. }