|
1 | 1 | import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native'; |
2 | | -import { Stack } from 'expo-router'; |
3 | | -import { StatusBar } from 'expo-status-bar'; |
4 | 2 | import { PortalHost } from '@rn-primitives/portal'; |
| 3 | +import * as Sentry from '@sentry/react-native'; |
| 4 | +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; |
| 5 | +import { SplashScreen, Stack } from 'expo-router'; |
| 6 | +import { StatusBar } from 'expo-status-bar'; |
5 | 7 | import 'react-native-reanimated'; |
6 | 8 | import '../global.css'; |
7 | | -import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; |
8 | 9 |
|
9 | | -import { useColorScheme } from '@/hooks/use-color-scheme'; |
10 | | -import { StyleSheet } from 'react-native'; |
11 | 10 | import { AuthProvider } from '@/features/auth/auth-context'; |
| 11 | +import { useAppTheme } from '@/hooks/use-app-theme'; |
| 12 | +import { useSplashScreenReady } from '@/hooks/use-splash-screen-ready'; |
| 13 | +import { useEffect, useRef } from 'react'; |
| 14 | +import { Animated, View } from 'react-native'; |
| 15 | + |
| 16 | +void SplashScreen.preventAutoHideAsync().catch((err) => { |
| 17 | + Sentry.captureException(err); |
| 18 | +}); |
12 | 19 |
|
13 | 20 | const queryClient = new QueryClient(); |
14 | 21 |
|
| 22 | +function AppLayout() { |
| 23 | + const { isAppReady, setLayoutReady } = useSplashScreenReady(); |
| 24 | + |
| 25 | + const opacity = useRef(new Animated.Value(0)); |
| 26 | + |
| 27 | + useEffect(() => { |
| 28 | + if (isAppReady) { |
| 29 | + Animated.timing(opacity.current, { |
| 30 | + toValue: 1, |
| 31 | + duration: 350, |
| 32 | + useNativeDriver: true, |
| 33 | + }).start(); |
| 34 | + } |
| 35 | + }, [isAppReady]); |
| 36 | + |
| 37 | + return ( |
| 38 | + <View className="flex-1" onLayout={() => setLayoutReady(true)} accessibilityLabel="app-root-view"> |
| 39 | + {isAppReady && ( |
| 40 | + <Animated.View style={{ flex: 1, opacity: opacity.current }}> |
| 41 | + <Navigation /> |
| 42 | + <StatusBar style="auto" /> |
| 43 | + <PortalHost /> |
| 44 | + </Animated.View> |
| 45 | + )} |
| 46 | + </View> |
| 47 | + ); |
| 48 | +} |
| 49 | + |
| 50 | +function Navigation() { |
| 51 | + return ( |
| 52 | + <Stack> |
| 53 | + <Stack.Screen name="(auth)" options={{ headerShown: false }} /> |
| 54 | + <Stack.Screen name="(tabs)" options={{ headerShown: false }} /> |
| 55 | + <Stack.Screen name="+not-found" /> |
| 56 | + </Stack> |
| 57 | + ); |
| 58 | +} |
| 59 | + |
15 | 60 | export default function RootLayout() { |
16 | | - const colorScheme = useColorScheme(); |
| 61 | + const { theme } = useAppTheme(); |
17 | 62 |
|
18 | 63 | return ( |
19 | 64 | <QueryClientProvider client={queryClient}> |
20 | 65 | <AuthProvider> |
21 | | - <ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}> |
22 | | - <Stack> |
23 | | - <Stack.Screen name="(auth)" options={{ headerShown: false }} /> |
24 | | - <Stack.Screen name="(tabs)" options={{ headerShown: false }} /> |
25 | | - <Stack.Screen name="+not-found" /> |
26 | | - </Stack> |
27 | | - <StatusBar style="auto" /> |
28 | | - <PortalHost /> |
| 66 | + <ThemeProvider value={theme === 'dark' ? DarkTheme : DefaultTheme}> |
| 67 | + <AppLayout /> |
29 | 68 | </ThemeProvider> |
30 | 69 | </AuthProvider> |
31 | 70 | </QueryClientProvider> |
32 | 71 | ); |
33 | 72 | } |
34 | | - |
35 | | -const styles = StyleSheet.create({ |
36 | | - header: { |
37 | | - backgroundColor: '#000', |
38 | | - }, |
39 | | -}); |
40 | | - |
41 | | -export const screenOptions = { |
42 | | - headerStyle: styles.header, |
43 | | - headerTintColor: '#fff', |
44 | | - headerTitleStyle: { fontSize: 20, fontWeight: 'bold' as 'bold' }, |
45 | | - headerTitleAlign: 'center' as 'center', |
46 | | -}; |
|
0 commit comments