import { Stack, useRouter } from 'expo-router'; import { DatabaseProvider } from '@/hooks/useDatabase'; import { SettingsProvider } from '@/theme'; import { FriendsProvider } from '@/hooks/useFriends'; import { GestureHandlerRootView } from 'react-native-gesture-handler'; import { StatusBar } from 'expo-status-bar'; import { UpdateNotifier } from '@/components/UpdateNotifier'; import { Linking } from 'react-native'; import { useEffect } from 'react'; import { requestQuickAddFocus } from '@/utils/quickAddFocus'; import { registerForPushNotificationsAsync, setupNotificationChannels, addNotificationResponseReceivedListener, removeNotificationSubscription } from '@/services/pushNotifications'; import * as Notifications from 'expo-notifications'; import { Platform } from 'react-native'; Notifications.setNotificationHandler({ handleNotification: async () => ({ shouldShowAlert: true, shouldPlaySound: true, shouldSetBadge: true, shouldShowBanner: true, shouldShowList: true, }), }); function RootNavigator() { const router = useRouter(); useEffect(() => { setupNotificationChannels(); registerForPushNotificationsAsync().catch(() => {}); const responseListener = addNotificationResponseReceivedListener((response) => { const data = response.notification.request.content.data as Record | undefined; if (!data) return; switch (data.type) { case 'task_reminder': case 'task_assignment': if (data.taskId) { router.push({ pathname: '/task-detail', params: { id: data.taskId } }); } break; case 'friend_request': if (data.friendshipId) { router.push({ pathname: '/(tabs)/settings' }); } break; } }); const handleUrl = (url: string | null) => { if (!url || !url.includes('://quick-add')) return; router.replace('/(tabs)'); requestQuickAddFocus(); }; Linking.getInitialURL().then(handleUrl).catch(() => {}); const subscription = Linking.addEventListener('url', ({ url }) => handleUrl(url)); return () => { subscription.remove(); removeNotificationSubscription(responseListener); }; }, [router]); return ( ); } export default function RootLayout() { return ( ); }