forked from pinballmap/pbm-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
103 lines (91 loc) · 2.95 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
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";
Sentry.init({
dsn: "https://057bae9b04f2410db6e4f1bd8d3eff2c@o1352308.ingest.sentry.io/6633526",
debug: false,
});
SplashScreen.preventAutoHideAsync();
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("defaultThemeOverride").then(
(defaultThemeOverride) =>
defaultTheme !== "dark" &&
defaultThemeOverride &&
setSelectedTheme("dark"),
);
retrieveItem("darkThemeOverride").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);