-
Notifications
You must be signed in to change notification settings - Fork 320
Expand file tree
/
Copy path_layout.tsx
More file actions
80 lines (72 loc) · 2.63 KB
/
Copy path_layout.tsx
File metadata and controls
80 lines (72 loc) · 2.63 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
import { DarkTheme, Stack, ThemeProvider } from 'expo-router'
import { useEffect, useMemo, useState } from 'react'
import { I18nextProvider } from 'react-i18next'
import { LogBox, Platform, StyleSheet } from 'react-native'
import { GestureHandlerRootView } from 'react-native-gesture-handler'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { waitForEnvironment } from '@/api/environment'
import { i18n } from '@/i18n'
import { addAppleCredentialRevokeListener } from '@/modules/auth/appleAuthentication'
import { waitForAuthStorage } from '@/modules/auth/authStorage'
import { clearLocalAuthentication, hydrateAuth } from '@/modules/auth/sessionStore'
import { MobileOnboardingCoordinator } from '@/modules/onboarding/MobileOnboardingCoordinator'
import { PresentationHost } from '@/presentation'
import { useTheme as useAppTheme } from '@/theme/useTheme'
LogBox.ignoreAllLogs(true)
export default function RootLayout() {
const { palette } = useAppTheme()
const [environmentReady, setEnvironmentReady] = useState(false)
// Nothing may issue a request before the API environment override resolves,
// otherwise the first fetch races against the production default.
useEffect(() => {
void Promise.all([waitForEnvironment(), waitForAuthStorage()]).then(async () => {
setEnvironmentReady(true)
await hydrateAuth()
})
}, [])
useEffect(() => {
if (Platform.OS !== 'ios') {
return
}
const subscription = addAppleCredentialRevokeListener(() => {
void clearLocalAuthentication()
})
return () => subscription.remove()
}, [])
const navigationTheme = useMemo(
() => ({
...DarkTheme,
colors: {
...DarkTheme.colors,
background: palette.bgCanvas,
border: palette.border,
card: palette.bgCanvas,
primary: palette.accent,
text: palette.textPrimary,
},
}),
[palette],
)
return (
<I18nextProvider i18n={i18n}>
<GestureHandlerRootView style={[styles.root, { backgroundColor: palette.bgCanvas }]}>
<SafeAreaProvider>
<ThemeProvider value={navigationTheme}>
{environmentReady ? (
<Stack screenOptions={{ headerShown: false }}>
<Stack.Screen name="index" />
<Stack.Screen name="(tabs)" />
{__DEV__ ? <Stack.Screen name="dev" /> : null}
</Stack>
) : null}
<MobileOnboardingCoordinator />
<PresentationHost />
</ThemeProvider>
</SafeAreaProvider>
</GestureHandlerRootView>
</I18nextProvider>
)
}
const styles = StyleSheet.create({
root: { flex: 1 },
})