-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
88 lines (75 loc) · 2.3 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
import 'react-native-gesture-handler';
import '@theme/unistyles';
import '@locales';
import '@helpers/toast';
import React, {useEffect, useRef} from 'react';
import {useColorScheme} from 'react-native';
import {
NavigationContainer,
useNavigationContainerRef,
} from '@react-navigation/native';
import {useTranslation} from 'react-i18next';
import {SystemBars} from 'react-native-bars';
import {enableFreeze, enableScreens} from 'react-native-screens';
import {UnistylesRuntime} from 'react-native-unistyles';
import {logScreenView} from '@helpers/analytics';
import {linking} from '@helpers/linking';
import {AppContextProvider} from '@hooks/context';
import Stack, {RootStackParamsList} from '@navigations/Stack';
import {useAppStore} from '@store/app';
import {isSystemTheme} from '@utils/theme';
enableScreens(true);
enableFreeze(true);
function Main() {
const {
i18n: {language, changeLanguage},
} = useTranslation();
/* Ref */
const routeNameRef = useRef<string>();
const navigationRef = useNavigationContainerRef<RootStackParamsList>();
/* State */
const app = useAppStore();
/* Theme */
const systemTheme = useColorScheme();
useEffect(() => {
if (language !== app.language) {
changeLanguage(app.language);
}
if (isSystemTheme(app.theme)) {
UnistylesRuntime.setTheme(systemTheme || 'light');
} else {
UnistylesRuntime.setTheme(app.theme);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [app.language, app.theme]);
return (
<NavigationContainer
ref={navigationRef}
linking={linking}
onReady={() => {
routeNameRef.current = navigationRef.getCurrentRoute()?.name;
}}
onStateChange={() => {
const previousRouteName = routeNameRef.current;
const currentRouteName = navigationRef.getCurrentRoute()?.name;
if (previousRouteName !== currentRouteName) {
logScreenView({
screen_name: currentRouteName,
screen_class: currentRouteName,
});
}
routeNameRef.current = currentRouteName;
}}>
<Stack />
</NavigationContainer>
);
}
function App(): React.JSX.Element {
return (
<AppContextProvider>
<SystemBars barStyle="dark-content" animated />
<Main />
</AppContextProvider>
);
}
export default App;