import { DarkTheme, DefaultTheme, ThemeProvider as NavigationThemeProvider } from '@react-navigation/native';
import { Stack } from 'expo-router';
import { StatusBar } from 'expo-status-bar';
import { useEffect } from 'react';
import { AppState } from 'react-native';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import 'react-native-reanimated';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { useColorScheme } from '@/hooks/use-color-scheme';
import { ThemeProvider } from '@/contexts/theme-context';
import { notificationService } from '@/services';
function RootLayoutNav() {
const colorScheme = useColorScheme();
return (
<NavigationThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
<Stack screenOptions={{ headerShown: false }}>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="project/[id]" options={{ headerShown: false }} />
<Stack.Screen name="archive" options={{ headerShown: false }} />
<Stack.Screen name="repeating" options={{ headerShown: false }} />
<Stack.Screen
name="modal"
options={{
presentation: 'transparentModal',
animation: 'fade',
headerShown: false
}}
/>
<Stack.Screen
name="project-modal"
options={{
presentation: 'transparentModal',
animation: 'fade',
headerShown: false
}}
/>
<Stack.Screen name="webdav-setup" options={{ headerShown: false }} />
</Stack>
<StatusBar style="auto" />
</NavigationThemeProvider>
);
}
export default function RootLayout() {
useEffect(() => {
notificationService.refreshDailyNotificationIfEnabled();
// Recount when leaving the app as well, so a reminder reflects the tasks as
// they were when the app was last used, not when it was last scheduled.
const subscription = AppState.addEventListener('change', state => {
if (state === 'background' || state === 'active') {
notificationService.refreshDailyNotificationIfEnabled();
}
});
return () => subscription.remove();
}, []);
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<SafeAreaProvider>
<ThemeProvider>
<RootLayoutNav />
</ThemeProvider>
</SafeAreaProvider>
</GestureHandlerRootView>
);
}