-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
77 lines (65 loc) · 1.93 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
import React, { useEffect } from 'react';
import * as Analytics from 'expo-firebase-analytics';
import 'react-native-gesture-handler';
import { NavigationContainer, DefaultTheme, NavigationState } from '@react-navigation/native';
import * as SplashScreen from 'expo-splash-screen';
import Colors from './src/utils/colors';
import useFonts from './src/hooks/useFonts';
import AppProvider from './src/hooks';
import { ModalProvider } from './src/hooks/useModal';
import Routes from './src/routes';
import { setNavigator } from './src/utils/navigator';
SplashScreen.preventAutoHideAsync().catch(() => {
// do nothing
});
const theme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
...Colors,
},
};
const getActiveRouteState = (route: NavigationState): NavigationState => {
if (!route.routes || route.routes.length === 0 || route.index >= route.routes.length) {
return route;
}
const childActiveRoute = route.routes[route.index] as NavigationState;
return getActiveRouteState(childActiveRoute);
};
const App = (): JSX.Element => {
const loadingFonts = useFonts();
useEffect(() => {
if (!loadingFonts) {
SplashScreen.hideAsync().catch(() => {
// do nothing
});
}
}, [loadingFonts]);
useEffect(() => {
Analytics.setDebugModeEnabled(true);
}, []);
if (loadingFonts) {
return null;
}
return (
<NavigationContainer
ref={setNavigator}
theme={theme}
onStateChange={(state: NavigationState) => {
const currentScreen = getActiveRouteState(state);
let screenName = currentScreen?.name;
if (currentScreen?.name === 'Root') {
screenName = currentScreen?.state.routeNames[currentScreen?.state.index];
}
Analytics.setCurrentScreen(screenName);
}}
>
<AppProvider>
<ModalProvider>
<Routes />
</ModalProvider>
</AppProvider>
</NavigationContainer>
);
};
export default App;