-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
112 lines (99 loc) · 3.12 KB
/
index.js
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-native-gesture-handler";
import { registerRootComponent } from "expo";
import React, { useState, useEffect } from "react";
import { Appearance, Platform } from "react-native";
import { retrieveItem } from "./app/config/utils";
import { ThemeContext } from "./app/theme-context";
import { Provider } from "react-redux";
import { NavigationContainer } from "@react-navigation/native";
import { dark, standard } from "./app/utils/themes";
import { StatusBar } from "expo-status-bar";
import store from "./app/store";
import * as SplashScreen from "expo-splash-screen";
import * as ScreenOrientation from "expo-screen-orientation";
import { AppWrapper } from "./app/components";
import MapNavigator from "./app/config/router";
import * as Sentry from "@sentry/react-native";
import * as Device from "expo-device";
import {
KEY_DARK_THEME_OVERRIDE,
KEY_DEFAULT_THEME_OVERRIDE,
} from "./app/utils/constants";
Sentry.init({
dsn: "https://[email protected]/6633526",
debug: false,
});
SplashScreen.preventAutoHideAsync();
SplashScreen.setOptions({
duration: 1000,
fade: true,
});
const defaultTheme = Appearance.getColorScheme();
// https://github.com/facebook/react-native/issues/19410
if (Platform.OS === "android") {
require("intl");
require("intl/locale-data/jsonp/en-US");
}
const App = () => {
const [selectedTheme, setSelectedTheme] = useState(
defaultTheme === "dark" ? "dark" : "",
);
useEffect(() => {
retrieveItem(KEY_DEFAULT_THEME_OVERRIDE).then(
(defaultThemeOverride) =>
defaultTheme !== "dark" &&
defaultThemeOverride &&
setSelectedTheme("dark"),
);
retrieveItem(KEY_DARK_THEME_OVERRIDE).then(
(darkThemeOverride) =>
defaultTheme === "dark" && darkThemeOverride && setSelectedTheme(""),
);
async function lockOrientation() {
if (Device.deviceType.TABLET) {
await ScreenOrientation.lockAsync(
ScreenOrientation.OrientationLock.ALL,
);
} else {
await ScreenOrientation.lockAsync(
ScreenOrientation.OrientationLock.PORTRAIT_UP,
);
}
}
async function prepare() {
await SplashScreen.preventAutoHideAsync();
}
lockOrientation();
prepare();
}, []);
const toggleDefaultTheme = () =>
defaultTheme !== "dark" &&
setSelectedTheme(selectedTheme === "dark" ? "" : "dark");
const toggleDarkTheme = () =>
defaultTheme === "dark" &&
setSelectedTheme(selectedTheme === "dark" ? "" : "dark");
return (
<ThemeContext.Provider
value={{
toggleDefaultTheme,
toggleDarkTheme,
theme: selectedTheme === "dark" ? dark : standard,
}}
>
<Provider store={store}>
<AppWrapper>
<NavigationContainer
theme={selectedTheme === "dark" ? dark : standard}
>
<MapNavigator />
</NavigationContainer>
</AppWrapper>
</Provider>
<StatusBar
style={selectedTheme === "dark" ? "light" : "dark"}
translucent={true}
/>
</ThemeContext.Provider>
);
};
export default registerRootComponent(App);