-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_layout.tsx
More file actions
141 lines (117 loc) · 4.52 KB
/
_layout.tsx
File metadata and controls
141 lines (117 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// app/_layout.tsx
import { useEffect } from 'react';
import { useNavigationContainerRef } from '@react-navigation/native';
import { useReactNavigationDevTools } from '@dev-plugins/react-navigation';
import { SplashScreen, Stack } from 'expo-router';
import 'react-native-reanimated';
import { useFonts } from 'expo-font';
import FontAwesome from '@expo/vector-icons/FontAwesome';
import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';
import { View } from 'react-native';
import { StatusBar } from 'expo-status-bar';
import { usePushNotifications, useNotificationObserver } from '@/hooks/usePushNotifications';
import { registerBackgroundFetch } from '@/utils/tasks.utils';
import ErrorBoundary from '@/components/ErrorBoundary';
import { NotificationProvider } from '@/providers/NotificationProvider';
// ✅ import from providers + hooks (don’t import AuthProvider from hooks)
import { AuthProvider } from '@/providers/AuthProvider';
import { SessionProvider } from '@/providers/SessionProvider';
import { useAuth } from '@/hooks/useAuth';
import * as Sentry from '@sentry/react-native';
Sentry.init({
// Adds more context data to events (IP address, cookies, user, etc.)
// For more information, visit: https://docs.sentry.io/platforms/react-native/data-management/data-collected/
sendDefaultPii: true,
// Enable Logs
//enableLogs: true,
// Configure Session Replay
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1,
integrations: [Sentry.mobileReplayIntegration()],
// uncomment the line below to enable Spotlight (https://spotlightjs.com)
// spotlight: __DEV__,
});
// Prevent auto-hiding the splash until fonts are loaded
SplashScreen.preventAutoHideAsync().catch(() => {
/* no-op */
});
// --- Component Definition ---
export default Sentry.wrap(function RootLayout() {
const navigationRef = useNavigationContainerRef();
// Register background fetch task
useEffect(() => {
registerBackgroundFetch();
}, []);
// React Navigation DevTools
useReactNavigationDevTools(navigationRef);
// Load fonts
const [loaded] = useFonts({
SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
...FontAwesome.font,
});
// Hide the splash screen once fonts are loaded
useEffect(() => {
if (loaded) {
SplashScreen.hideAsync().catch(() => {});
}
}, [loaded]);
if (!loaded) return null;
return (
<SessionProvider>
<AuthProvider>
<NotificationBootstrap />
<RootLayoutNav />
</AuthProvider>
</SessionProvider>
);
});
// Forced dark theme (can be extended later for dynamic theming)
const ForcedDarkTheme = {
...DarkTheme,
colors: {
...DarkTheme.colors,
background: '#000000',
card: '#000000',
text: '#ffffff',
border: '#222222',
primary: '#ffffff',
},
};
function RootLayoutNav() {
const { user } = useAuth();
// Avoid logging during render to prevent side-effects in LogViewer
useEffect(() => {
console.log('User: ', user);
}, [user]);
// (global handlers now set at module scope above)
return (
<ErrorBoundary>
<NotificationProvider>
<ThemeProvider value={ForcedDarkTheme}>
<View style={{ flex: 1, backgroundColor: '#000' }}>
<StatusBar style="light" backgroundColor="#000" translucent={false} />
<Stack
screenOptions={{
contentStyle: { backgroundColor: '#000' },
headerStyle: { backgroundColor: '#000' },
headerShown: false,
}}
>
<Stack.Screen name="(tabs)" />
<Stack.Screen name="login" />
<Stack.Screen name="debug" options={{ headerShown: true, title: 'Debug' }} />
<Stack.Screen name="modal" options={{ headerShown: true, presentation: 'modal' }} />
</Stack>
</View>
</ThemeProvider>
</NotificationProvider>
</ErrorBoundary>
);
}
// Separate component so hooks mount within providers
function NotificationBootstrap() {
usePushNotifications();
useNotificationObserver();
return null;
}