Skip to content

Commit f45e0e4

Browse files
committed
Updated imports + added global error handler & api submission.
1 parent 6a6a000 commit f45e0e4

1 file changed

Lines changed: 50 additions & 33 deletions

File tree

app/_layout.tsx

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { useEffect, useState } from "react";
33
import { useNavigationContainerRef } from "@react-navigation/native";
44
import { useReactNavigationDevTools } from "@dev-plugins/react-navigation";
55
import { SplashScreen } from "expo-router";
6-
import { usePushNotifications } from "../hooks/usePushNotifications";
7-
import { useNotificationObserver } from "../hooks/usePushNotifications";
8-
// import { registerForPushNotificationsAsync } from "../utils/notifications";
6+
import { usePushNotifications } from "@/hooks/usePushNotifications";
7+
import { useNotificationObserver } from "@/hooks/usePushNotifications";
8+
// import { registerForPushNotificationsAsync } from "@/utils/notifications";
99
// import { getFirebaseApp } from "@/utils/firebase";
1010
import { useFonts } from "expo-font";
1111
import FontAwesome from "@expo/vector-icons/FontAwesome";
@@ -16,8 +16,45 @@ import {
1616
} from "@react-navigation/native";
1717
import { Stack } from "expo-router";
1818
import "react-native-reanimated";
19-
import { useColorScheme } from "@/components/useColorScheme";
19+
import { useColorScheme } from "@/hooks/useColorScheme";
2020
import { registerBackgroundFetch } from "@/utils/tasks.utils";
21+
import ErrorBoundary from "@/components/ErrorBoundary";
22+
// FIX 2: Import the exception handlers from the library
23+
import {
24+
setJSExceptionHandler,
25+
setNativeExceptionHandler,
26+
} from "react-native-exception-handler";
27+
import { reportError } from "@/services/errorReporting.service";
28+
import { ErrorInfo } from "react";
29+
30+
// --- NEW: Import our notification function ---
31+
import { showFatalErrorNotification } from "@/utils/notifications.utils";
32+
33+
// --- Global Exception Handler Setup ---
34+
35+
const jsExceptionHandler = (error: Error, isFatal: boolean) => {
36+
console.log("Caught JS Exception:", error, isFatal);
37+
reportError(error, { isFatal });
38+
39+
if (isFatal) {
40+
// Pass the error to the notification function
41+
showFatalErrorNotification(error);
42+
}
43+
};
44+
45+
const nativeExceptionHandler = (exceptionString: string) => {
46+
console.log("Caught Native Exception:", exceptionString);
47+
const error = new Error(`Native Exception: ${exceptionString}`);
48+
reportError(error, { isFatal: true });
49+
50+
// Pass the newly created error to the notification function
51+
showFatalErrorNotification(error);
52+
};
53+
54+
setJSExceptionHandler(jsExceptionHandler, true);
55+
setNativeExceptionHandler(nativeExceptionHandler);
56+
57+
// --- Component Definition ---
2158

2259
export default function RootLayout() {
2360
const navigationRef = useNavigationContainerRef();
@@ -27,8 +64,8 @@ export default function RootLayout() {
2764
usePushNotifications();
2865
useNotificationObserver();
2966

67+
// Register background fetch task
3068
useEffect(() => {
31-
// Register background fetch task
3269
registerBackgroundFetch();
3370
}, []);
3471

@@ -41,27 +78,6 @@ export default function RootLayout() {
4178
...FontAwesome.font,
4279
});
4380

44-
// useEffect(() => {
45-
// // Initialize Firebase app
46-
// try {
47-
// getFirebaseApp();
48-
// console.log("Firebase initialized in RootLayout");
49-
// } catch (error) {
50-
// console.error("Firebase initialization error:", error);
51-
// }
52-
53-
// // Register for push notifications and get the push token
54-
// registerForPushNotificationsAsync().then((token) => {
55-
// if (token) {
56-
// setExpoPushToken(token); // Store the push token
57-
// }
58-
// });
59-
60-
// return () => {
61-
// console.log("Cleanup RootLayout effect");
62-
// };
63-
// }, []);
64-
6581
// Handle font loading errors
6682
useEffect(() => {
6783
if (error) throw error;
@@ -84,14 +100,15 @@ export default function RootLayout() {
84100

85101
function RootLayoutNav() {
86102
const colorScheme = useColorScheme();
87-
// useNotificationObserver(); // Moved to RootLayout to prevent unnecessary re-renders
88103

89104
return (
90-
<ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
91-
<Stack>
92-
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
93-
<Stack.Screen name="modal" options={{ presentation: "modal" }} />
94-
</Stack>
95-
</ThemeProvider>
105+
<ErrorBoundary>
106+
<ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
107+
<Stack>
108+
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
109+
<Stack.Screen name="modal" options={{ presentation: "modal" }} />
110+
</Stack>
111+
</ThemeProvider>
112+
</ErrorBoundary>
96113
);
97114
}

0 commit comments

Comments
 (0)