-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
61 lines (50 loc) · 1.99 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
import { useRef, useState } from 'react';
import { Provider } from 'react-redux';
import { NavigationContainer, useNavigationContainerRef } from '@react-navigation/native';
import * as SplashScreen from 'expo-splash-screen';
import { useFonts } from 'expo-font';
import { store } from 'src/store/store';
import NavigationRoot from 'src/navigation/NavigationRoot';
import { analyticsService } from 'src/services';
// Keep the splash screen visible while we fetch resources
SplashScreen.preventAutoHideAsync();
function App() {
const [canGoBack, setCanGoBack] = useState(false);
const navigationRef = useNavigationContainerRef();
const routeNameRef = useRef<any>();
const [fontsLoaded] = useFonts({
'nunito': require('src/assets/fonts/Nunito-Regular.ttf'),
'nunito-italic': require('src/assets/fonts/Nunito-Italic.ttf'),
'nunito-bold': require('src/assets/fonts/Nunito-Bold.ttf'),
'nunito-extra-bold': require('src/assets/fonts/Nunito-ExtraBold.ttf'),
'nunito-black': require('src/assets/fonts/Nunito-Black.ttf'),
});
if (!fontsLoaded) {
return null;
}
return (
<Provider store={store}>
<NavigationContainer
ref={navigationRef}
onReady={() => {
routeNameRef.current = navigationRef?.getCurrentRoute()?.name;
setCanGoBack(navigationRef.canGoBack());
analyticsService.setScreenName(routeNameRef.current);
}}
onStateChange={() => {
const previousRouteName = routeNameRef.current;
const currentRouteName = navigationRef?.getCurrentRoute()?.name;
if (previousRouteName !== currentRouteName) {
// Save the current route name for later comparison
routeNameRef.current = currentRouteName;
setCanGoBack(navigationRef.canGoBack());
analyticsService.setScreenName(currentRouteName ?? 'undefined');
}
}}
>
<NavigationRoot canGoBack={canGoBack} />
</NavigationContainer>
</Provider>
);
}
export default App;