Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ec95406305 | |||
| 6bd1dc8358 |
@@ -6,9 +6,6 @@
|
|||||||
"orientation": "portrait",
|
"orientation": "portrait",
|
||||||
"userInterfaceStyle": "dark",
|
"userInterfaceStyle": "dark",
|
||||||
"backgroundColor": "#0f1117",
|
"backgroundColor": "#0f1117",
|
||||||
"splash": {
|
|
||||||
"backgroundColor": "#0f1117"
|
|
||||||
},
|
|
||||||
"scheme": "sheethappens",
|
"scheme": "sheethappens",
|
||||||
"android": {
|
"android": {
|
||||||
"adaptiveIcon": {
|
"adaptiveIcon": {
|
||||||
|
|||||||
+59
-5
@@ -1,18 +1,55 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect, useState, Component } from "react";
|
||||||
import { Stack, router, SplashScreen } from "expo-router";
|
import type { ReactNode } from "react";
|
||||||
|
import { Stack, router } from "expo-router";
|
||||||
import { StatusBar } from "expo-status-bar";
|
import { StatusBar } from "expo-status-bar";
|
||||||
import { GestureHandlerRootView } from "react-native-gesture-handler";
|
import { GestureHandlerRootView } from "react-native-gesture-handler";
|
||||||
|
import { View, Text, ScrollView } from "react-native";
|
||||||
import "../global.css";
|
import "../global.css";
|
||||||
import { Colors } from "@/constants/theme";
|
import { Colors } from "@/constants/theme";
|
||||||
import { useSettings } from "@/hooks/useSettings";
|
import { useSettings } from "@/hooks/useSettings";
|
||||||
|
|
||||||
|
// Catch JS errors in release mode and show them on-screen instead of
|
||||||
|
// silently crashing to desktop. Remove once the crash is identified.
|
||||||
|
class CrashBoundary extends Component<
|
||||||
|
{ children: ReactNode },
|
||||||
|
{ error: Error | null }
|
||||||
|
> {
|
||||||
|
state = { error: null };
|
||||||
|
static getDerivedStateFromError(e: Error) {
|
||||||
|
return { error: e };
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
const { error } = this.state;
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<View style={{ flex: 1, backgroundColor: "#0f1117", padding: 20, paddingTop: 60 }}>
|
||||||
|
<Text style={{ color: "#ef4444", fontSize: 16, fontWeight: "700", marginBottom: 12 }}>
|
||||||
|
CRASH — copie ce texte
|
||||||
|
</Text>
|
||||||
|
<ScrollView>
|
||||||
|
<Text style={{ color: "#fff", fontSize: 11, fontFamily: "monospace" }}>
|
||||||
|
{String(error)}{"\n\n"}{(error as any).stack}
|
||||||
|
</Text>
|
||||||
|
</ScrollView>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return this.props.children;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default function RootLayout() {
|
export default function RootLayout() {
|
||||||
const { settings, ready } = useSettings();
|
const { settings, ready } = useSettings();
|
||||||
|
const [jsError, setJsError] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ready) return;
|
const prev = (ErrorUtils as any).getGlobalHandler();
|
||||||
SplashScreen.hideAsync();
|
(ErrorUtils as any).setGlobalHandler((e: Error, isFatal: boolean) => {
|
||||||
}, [ready]);
|
if (isFatal) setJsError(`${String(e)}\n\n${(e as any).stack ?? ""}`);
|
||||||
|
prev?.(e, isFatal);
|
||||||
|
});
|
||||||
|
return () => (ErrorUtils as any).setGlobalHandler(prev);
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ready) return;
|
if (!ready) return;
|
||||||
@@ -21,7 +58,23 @@ export default function RootLayout() {
|
|||||||
}
|
}
|
||||||
}, [ready, settings.onboardingDone]);
|
}, [ready, settings.onboardingDone]);
|
||||||
|
|
||||||
|
if (jsError) {
|
||||||
return (
|
return (
|
||||||
|
<View style={{ flex: 1, backgroundColor: "#0f1117", padding: 20, paddingTop: 60 }}>
|
||||||
|
<Text style={{ color: "#ef4444", fontSize: 16, fontWeight: "700", marginBottom: 12 }}>
|
||||||
|
FATAL JS ERROR — copie ce texte
|
||||||
|
</Text>
|
||||||
|
<ScrollView>
|
||||||
|
<Text style={{ color: "#fff", fontSize: 11, fontFamily: "monospace" }}>
|
||||||
|
{jsError}
|
||||||
|
</Text>
|
||||||
|
</ScrollView>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CrashBoundary>
|
||||||
<GestureHandlerRootView style={{ flex: 1, backgroundColor: Colors.bg }}>
|
<GestureHandlerRootView style={{ flex: 1, backgroundColor: Colors.bg }}>
|
||||||
<StatusBar style="light" />
|
<StatusBar style="light" />
|
||||||
<Stack
|
<Stack
|
||||||
@@ -40,5 +93,6 @@ export default function RootLayout() {
|
|||||||
<Stack.Screen name="onboarding" options={{ headerShown: false }} />
|
<Stack.Screen name="onboarding" options={{ headerShown: false }} />
|
||||||
</Stack>
|
</Stack>
|
||||||
</GestureHandlerRootView>
|
</GestureHandlerRootView>
|
||||||
|
</CrashBoundary>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user