import '../global.css'; import { Stack } from 'expo-router'; import { useDatabase } from '../hooks/useDatabase'; import { useTheme } from '../hooks/useTheme'; import { View, Text, ActivityIndicator, AppState } from 'react-native'; import { useEffect } from 'react'; import { PhotoService } from '../services/storage/PhotoService'; export const unstable_settings = { // Ensure that reloading on `/modal` keeps a back button present. initialRouteName: 'index', }; export default function RootLayout() { const { isReady, error } = useDatabase(); // Initialize theme on app start useTheme(); // Clean up temporary photos when app comes to foreground useEffect(() => { const handleAppStateChange = async (nextAppState: string) => { if (nextAppState === 'active') { try { const photoService = PhotoService.getInstance(); await photoService.cleanupTempPhotos(); console.log('Temporary photos cleaned up on app foreground'); } catch (error) { console.warn('Failed to cleanup temp photos on foreground:', error); } } }; const subscription = AppState.addEventListener('change', handleAppStateChange); return () => subscription?.remove(); }, []); if (!isReady) { return ( {error ? ( Database Error {error} ) : ( Initializing Nutriphi... )} ); } return ( ); }