-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppFn.tsx
136 lines (120 loc) · 4.21 KB
/
AppFn.tsx
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
import * as SplashScreen from 'expo-splash-screen'
import * as React from 'react'
import { Platform, StatusBar, StyleSheet, View } from 'react-native'
// import { analytics as Analytics } from '@src/services/firebase'
import * as Font from 'expo-font'
import { NavigationContainer } from '@react-navigation/native'
import {
CardStyleInterpolators,
createStackNavigator,
HeaderStyleInterpolators,
} from '@react-navigation/stack'
// import Purchases from 'react-native-purchases'
import { headerTheme } from '@src/navigation/headerStuff'
import linking from '@src/navigation/linking'
import { AppStackParamList } from '@src/navigation/navigation.types'
import AccessGame from '@src/screens/access-game'
import GameRoom from '@src/screens/game-room'
import Home from '@src/screens/home'
import Settings from '@src/screens/settings'
import Tutorial from '@src/screens/tutorial'
import * as Sentry from '@src/services/sentry'
import { loadProfile, PapersContextProvider } from '@src/store/PapersContext'
import { Profile } from '@src/store/PapersContext.types'
import { animations } from '@src/theme'
const Stack = createStackNavigator<AppStackParamList>()
export default function AppFn() {
const [initialProfile, setInitialProfile] = React.useState<Maybe<Profile>>(null)
const [isLoadingComplete, setLoadingComplete] = React.useState(false)
React.useEffect(() => {
StatusBar.setHidden(true, 'none')
async function loadResourcesAndDataAsync() {
try {
// https://github.com/expo/expo/issues/10816
await SplashScreen.preventAutoHideAsync()
} catch (e) {
Sentry.captureException(e, { tags: { pp_page: 'AppFn_0' } })
}
try {
const profile = await loadProfile()
setInitialProfile(profile)
await Font.loadAsync({
'Karla-Regular': require('./assets/fonts/Karla-Regular.ttf'),
'Karla-Bold': require('./assets/fonts/Karla-Bold.ttf'),
'YoungSerif-Regular': require('./assets/fonts/YoungSerif-Regular.ttf'),
})
} catch (e) {
Sentry.captureException(e, { tags: { pp_page: 'AppFn_1' } })
} finally {
setLoadingComplete(true)
await SplashScreen.hideAsync()
}
}
loadResourcesAndDataAsync()
}, [])
React.useEffect(() => {
if (Platform.OS !== 'web') {
// Purchases.setDebugLogsEnabled(__DEV__)
// Purchases.setup(REVENUECAT_PUBLIC_SDK_KEY)
}
}, [])
if (!isLoadingComplete) {
return null
}
return initialProfile ? (
<PapersContextProvider initialProfile={initialProfile}>
<View style={Styles.container}>
{Platform.OS === 'ios' && <StatusBar barStyle="dark-content" />}
<NavigationContainer linking={linking}>
<Stack.Navigator
initialRouteName={initialProfile.gameId ? 'room' : 'home'}
screenOptions={{
gestureEnabled: false,
...headerTheme(),
cardStyleInterpolator: animations.fadeCard,
}}
>
<Stack.Screen name="home" component={Home} options={{ title: '' }} />
<Stack.Screen
name="access-game"
component={AccessGame}
options={{
title: '',
}}
/>
<Stack.Screen
name="room"
component={GameRoom}
options={{
headerShown: false,
}}
/>
<Stack.Screen
name="settings"
component={Settings}
options={{
title: '',
cardStyleInterpolator: CardStyleInterpolators.forVerticalIOS,
headerStyleInterpolator: HeaderStyleInterpolators.forFade,
}}
/>
<Stack.Screen
name="tutorial"
component={Tutorial}
options={{
title: '',
cardStyleInterpolator: CardStyleInterpolators.forVerticalIOS,
headerStyleInterpolator: HeaderStyleInterpolators.forFade,
}}
/>
</Stack.Navigator>
</NavigationContainer>
</View>
</PapersContextProvider>
) : null
}
const Styles = StyleSheet.create({
container: {
flex: 1,
},
})