-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
54 lines (49 loc) · 1.85 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
import { NavigationContainer } from "@react-navigation/native";
import * as NavigationBar from "expo-navigation-bar";
import { StatusBar as ExpoStatusBar } from "expo-status-bar"; // automatically switches bar style based on theme!
import { useEffect, useState } from "react";
import { Appearance, DeviceEventEmitter } from "react-native";
import { AuthProvider } from "./src/context/AuthContext";
import { FavoritesProvider } from "./src/context/FavoritesContext";
import { ReloadContentProvider } from "./src/context/ReloadContentContext";
import { DarkTheme, DefaultTheme } from "./src/context/ThemeContext";
import { useTheme } from "./src/hooks/useTheme";
import { AppRoutes } from "./src/routes/Router";
export default function App() {
const { getTheme, saveTheme } = useTheme();
const [mode, setMode]: any = useState(() => Appearance.getColorScheme());
const backgroundStyle = {
backgroundColor:
mode === "light" ? DarkTheme.colors.card : DefaultTheme.colors.card,
};
NavigationBar.setBackgroundColorAsync(
mode === "light" ? DarkTheme.colors.card : DefaultTheme.colors.card
);
useEffect(() => {
changeTheme();
}, []);
async function changeTheme() {
const theme = await getTheme();
if (theme !== undefined) setMode(theme);
}
function handler(arg) {
setMode(arg);
saveTheme(arg);
}
DeviceEventEmitter.addListener("changeTheme", handler);
return (
<NavigationContainer theme={mode === "light" ? DarkTheme : DefaultTheme}>
<AuthProvider>
<FavoritesProvider>
<ReloadContentProvider>
<ExpoStatusBar
style={mode === "dark" ? "dark" : "light"}
backgroundColor={backgroundStyle.backgroundColor}
/>
<AppRoutes />
</ReloadContentProvider>
</FavoritesProvider>
</AuthProvider>
</NavigationContainer>
);
}