forked from NMF-earth/nmf-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
112 lines (101 loc) · 3.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
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
import React, { useEffect, useState } from "react";
import * as Font from "expo-font";
import { FormattedProvider } from "react-native-globalize";
import { locale as localeExpo } from "expo-localization";
import { includes } from "ramda";
import { StyleSheet, View } from "react-native";
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
import Constants from "expo-constants";
import * as Sentry from "sentry-expo";
import { Provider } from "react-redux";
import AppNavigator from "./app/navigation/Navigator/AppNavigator";
import store from "./app/redux/store";
import SplashScreen from "./app/screens/Splash";
import { LocalizationContext } from "./app/utils";
const supportedLanguages = ["en", "fr", "de", "sv"];
const secret =
require("./secret.ts").default || require("./secret.example.ts").default;
/* TODO: change secret.dsn to Constants.manifest.extra.sentryPublicDsn */
Sentry.init({
dsn: secret.dsn,
enableInExpoDevelopment: false,
debug: true
});
/* TODO: set Constants.manifest.revisionId with expo */
Sentry.setRelease(Constants.manifest.revisionId);
interface Props {
skipLoadingScreen: boolean;
}
interface State {
locale: string;
language: string;
setLanguage: (language: string) => void;
setLocale: (locale: string) => void;
isLoadingComplete: boolean;
}
const App = () => {
let lang = localeExpo.substring(0, 2);
if (!includes(lang, supportedLanguages)) {
lang = "en";
}
const [ready, setReady] = useState(false);
const [splashAnimation, setSplashAnimation] = useState(false); // to track splashScreen animation
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-BoldItalic": require("./assets/fonts/Inter-BoldItalic.ttf"),
"Inter-ExtraBold": require("./assets/fonts/Inter-ExtraBold.ttf"),
"Inter-ExtraBoldItalic": require("./assets/fonts/Inter-ExtraBoldItalic.ttf"),
"Inter-ExtraLight-BETA": require("./assets/fonts/Inter-ExtraLight-BETA.ttf"),
"Inter-ExtraLightItalic-BETA": require("./assets/fonts/Inter-ExtraLightItalic-BETA.ttf"),
"Inter-Italic": require("./assets/fonts/Inter-Italic.ttf"),
"Inter-Light-BETA": require("./assets/fonts/Inter-Light-BETA.ttf"),
"Inter-LightItalic-BETA": require("./assets/fonts/Inter-LightItalic-BETA.ttf"),
"Inter-Medium": require("./assets/fonts/Inter-Medium.ttf"),
"Inter-MediumItalic": require("./assets/fonts/Inter-MediumItalic.ttf"),
"Inter-Regular": require("./assets/fonts/Inter-Regular.ttf"),
"Inter-SemiBold": require("./assets/fonts/Inter-SemiBold.ttf"),
"Inter-SemiBoldItalic": require("./assets/fonts/Inter-SemiBoldItalic.ttf"),
"Inter-Thin-BETA": require("./assets/fonts/Inter-Thin-BETA.ttf"),
"Inter-ThinItalic-BETA": require("./assets/fonts/Inter-ThinItalic-BETA.ttf")
})
])
.then(() => {
setReady(true);
})
.catch(error => Sentry.captureException(error));
}, []);
// callback to get splashScreen animation completion
const screenAnimationComplete = animation => {
setSplashAnimation(animation);
};
return (
<>
{ready && splashAnimation ? (
<Provider store={store}>
<FormattedProvider locale={language || "en"}>
<LocalizationContext.Provider
value={{
locale: locale || "en-US",
setLocale: setLocale,
language: language || "en",
setLanguage: setLanguage
}}
>
<AppNavigator />
</LocalizationContext.Provider>
</FormattedProvider>
</Provider>
) : (
<SplashScreen screenAnimationComplete={screenAnimationComplete} />
)}
</>
);
};
export default App;