-
Notifications
You must be signed in to change notification settings - Fork 956
/
Copy pathapp.tsx
128 lines (115 loc) · 4.52 KB
/
app.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
/* eslint-disable import/first */
/**
* Welcome to the main entry point of the app. In this file, we'll
* be kicking off our app.
*
* Most of this file is boilerplate and you shouldn't need to modify
* it very often. But take some time to look through and understand
* what is going on here.
*
* The app navigation resides in app/app/navigators, so head over there
* if you're interested in adding screens and navigators.
*/
if (__DEV__) {
// Load Reactotron configuration in development. We don't want to
// include this in our production bundle, so we are using `if (__DEV__)`
// to only execute this in development.
require("./devtools/ReactotronConfig.ts")
}
import "app/i18n"
import "app/utils/ignoreWarnings"
import { useFonts } from "expo-font"
import React from "react"
import { initialWindowMetrics, SafeAreaProvider } from "react-native-safe-area-context"
import * as Linking from "expo-linking"
import { useInitialRootStore } from "app/stores/mobxStateTree"
import { AppNavigator, useNavigationPersistence } from "app/navigators"
import { ErrorBoundary } from "app/screens/ErrorScreen/ErrorBoundary"
import * as storage from "app/utils/storage"
import { customFontsToLoad } from "app/theme"
import Config from "app/config"
import { GestureHandlerRootView } from "react-native-gesture-handler"
import { StatusBar, ViewStyle } from "react-native"
import { store } from "app/stores/redux"
import { Provider as ReduxProvider } from "react-redux"
import { ApolloProvider } from "@apollo/client"
import { client as apolloClient } from "app/stores/apollo"
export const NAVIGATION_PERSISTENCE_KEY = "NAVIGATION_STATE"
StatusBar.setBarStyle("light-content")
// Web linking configuration
const prefix = Linking.createURL("/")
const config = {
screens: {
Login: {
path: "",
},
Welcome: "welcome",
Demo: {
screens: {
DemoShowroom: {
path: "showroom/:queryIndex?/:itemIndex?",
},
DemoDebug: "debug",
DemoPodcastList: "podcast",
DemoCommunity: "community",
},
},
},
}
interface AppProps {
hideSplashScreen: () => Promise<boolean>
}
/**
* This is the root component of our app.
*/
function App(props: AppProps) {
const { hideSplashScreen } = props
const {
initialNavigationState,
onNavigationStateChange,
isRestored: isNavigationStateRestored,
} = useNavigationPersistence(storage, NAVIGATION_PERSISTENCE_KEY)
const [areFontsLoaded] = useFonts(customFontsToLoad)
const { rehydrated } = useInitialRootStore(() => {
// This runs after the root store has been initialized and rehydrated.
// If your initialization scripts run very fast, it's good to show the splash screen for just a bit longer to prevent flicker.
// Slightly delaying splash screen hiding for better UX; can be customized or removed as needed,
// Note: (vanilla Android) The splash-screen will not appear if you launch your app via the terminal or Android Studio. Kill the app and launch it normally by tapping on the launcher icon. https://stackoverflow.com/a/69831106
// Note: (vanilla iOS) You might notice the splash-screen logo change size. This happens in debug/development mode. Try building the app for release.
setTimeout(hideSplashScreen, 500)
})
// Before we show the app, we have to wait for our state to be ready.
// In the meantime, don't render anything. This will be the background
// color set in native by rootView's background color.
// In iOS: application:didFinishLaunchingWithOptions:
// In Android: https://stackoverflow.com/a/45838109/204044
// You can replace with your own loading component if you wish.
if (!rehydrated || !isNavigationStateRestored || !areFontsLoaded) return null
const linking = {
prefixes: [prefix],
config,
}
// otherwise, we're ready to render the app
return (
<ReduxProvider store={store}>
<ApolloProvider client={apolloClient}>
<SafeAreaProvider initialMetrics={initialWindowMetrics}>
<ErrorBoundary catchErrors={Config.catchErrors}>
<GestureHandlerRootView style={$container}>
<AppNavigator
linking={linking}
initialState={initialNavigationState}
onStateChange={onNavigationStateChange}
/>
</GestureHandlerRootView>
</ErrorBoundary>
</SafeAreaProvider>
</ApolloProvider>
</ReduxProvider>
)
}
// eslint-disable-next-line reactotron/no-tron-in-production
export default __DEV__ ? console.tron.overlay(App) : App
const $container: ViewStyle = {
flex: 1,
}