_layout.tsx 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 } 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 logAppConfig = async () => {
  18. console.log('=== App Configuration ===');
  19. console.log('Environment:', EXPO_PUBLIC_NODE_ENV);
  20. console.log('App Version:', Constants.expoConfig?.version);
  21. console.log('Runtime Version:', Constants.expoConfig?.runtimeVersion);
  22. console.log('Update Channel:', Constants.expoConfig?.updates?.channel);
  23. console.log('Release Channel:', Constants.manifest?.releaseChannel);
  24. console.log('======================');
  25. };
  26. const init = async () => {
  27. try {
  28. await logAppConfig();
  29. console.log('Fetching version info...');
  30. const response = await authenticationService.getVersion();
  31. console.log('Version response:', response);
  32. console.log('Checking version...');
  33. checkVersion(response);
  34. console.log('Initialization complete');
  35. } catch (error) {
  36. console.error('Initialization error:', error);
  37. // Log additional context but don't crash
  38. Alert.alert('Initialization Error', 'Please check your connection and try again.');
  39. }
  40. };
  41. init();
  42. }, []);
  43. useEffect(() => {
  44. const fetchVersion = async () => {
  45. const response = await authenticationService.getVersion();
  46. checkVersion(response);
  47. };
  48. fetchVersion();
  49. }, []);
  50. return (
  51. <GestureHandlerRootView style={{ flex: 1 }}>
  52. <AuthProvider>
  53. <Stack>
  54. <Stack.Screen name="(auth)/(tabs)" options={{ headerShown: false }} />
  55. <Stack.Screen name="(public)/login" options={{ headerShown: false }} />
  56. <Stack.Screen name="(public)/registerChooseVehiclesOne" options={{ headerShown: false }} />
  57. <Stack.Screen name="(public)/registerChooseVehiclesTwo" options={{ headerShown: false }} />
  58. {/* Testing Purpose */}
  59. {EXPO_PUBLIC_NODE_ENV == 'development' ? (
  60. <Stack.Screen
  61. name="(public)/test"
  62. options={{
  63. headerShown: false,
  64. title: 'Test Component Page'
  65. }}
  66. />
  67. ) : (
  68. <></>
  69. )}
  70. </Stack>
  71. </AuthProvider>
  72. </GestureHandlerRootView>
  73. );
  74. }