-
-
Notifications
You must be signed in to change notification settings - Fork 157
/
App.tsx
126 lines (110 loc) · 3.21 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
import React, { useEffect, useState } from "react";
import { View } from "react-native";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { StatusBar } from "expo-status-bar";
import * as Font from "expo-font";
import { GlobalizeProvider } from "react-native-globalize";
import { locale as localeExpo } from "expo-localization";
import { includes } from "ramda";
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
import ExpoClientConfig from "expo-constants";
import * as Sentry from "sentry-expo";
import { Provider } from "react-redux";
import { enableScreens } from "react-native-screens";
import { LocalizationContext } from "utils";
import StoreReviewChecker from "components/StoreReviewChecker";
import { loadGlobalize } from "./i18";
import AppNavigator from "./app/navigation/Navigator/AppNavigator";
import store from "./app/redux/store";
const supportedLanguages: string[] = [
"en",
"fr",
"de",
"sv",
"da",
"ru",
"pt",
"pl",
"zh",
"ms",
"es",
"it",
"ar",
];
const defaultLanguage = "en";
const defaultLocale = "en-us";
loadGlobalize();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const release = ExpoClientConfig.revisionId || "0.0.0";
if (!__DEV__) {
/* TODO: change secret.dsn to Constants.manifest.extra.sentryPublicDsn */
Sentry.init({
dsn: process.env.SENTRY_DSN,
enableInExpoDevelopment: false,
debug: true,
release,
});
}
const App: React.FC = () => {
enableScreens();
let lang = localeExpo.substring(0, 2);
if (!includes(lang, supportedLanguages)) {
lang = defaultLanguage;
}
const [ready, setReady] = useState(false);
const [language, setLanguage] = useState(lang);
const [locale, setLocale] = useState(localeExpo);
useEffect(() => {
Promise.all([
Font.loadAsync({
...Ionicons.font,
...MaterialCommunityIcons.font,
"Inter-Black": require("./assets/fonts/Inter-Black.ttf"),
"Inter-Bold": require("./assets/fonts/Inter-Bold.ttf"),
"Inter-Light-BETA": require("./assets/fonts/Inter-Light-BETA.ttf"),
"Inter-Medium": require("./assets/fonts/Inter-Medium.ttf"),
}),
])
.then(() => {
setReady(true);
})
.catch((error) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Sentry.captureException(error);
});
}, []);
let body = <View />;
if (ready) {
body = (
<Provider store={store}>
<GlobalizeProvider locale={language || defaultLanguage}>
<LocalizationContext.Provider
value={{
locale: locale || defaultLocale,
setLocale: setLocale,
language: language || defaultLanguage,
setLanguage: setLanguage,
}}
>
{__DEV__ ? (
<AppNavigator />
) : (
<StoreReviewChecker>
<AppNavigator />
</StoreReviewChecker>
)}
</LocalizationContext.Provider>
</GlobalizeProvider>
</Provider>
);
}
return (
<SafeAreaProvider>
<StatusBar style="dark" />
{body}
</SafeAreaProvider>
);
};
export default App;