-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathApp.tsx
More file actions
148 lines (136 loc) · 3.87 KB
/
Copy pathApp.tsx
File metadata and controls
148 lines (136 loc) · 3.87 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import {
Lato_100Thin,
Lato_100Thin_Italic,
Lato_300Light,
Lato_300Light_Italic,
Lato_400Regular,
Lato_400Regular_Italic,
Lato_700Bold,
Lato_700Bold_Italic,
Lato_900Black,
Lato_900Black_Italic,
} from "@expo-google-fonts/lato";
import {
Martel_200ExtraLight,
Martel_300Light,
Martel_400Regular,
Martel_600SemiBold,
Martel_700Bold,
Martel_800ExtraBold,
Martel_900Black,
useFonts,
} from "@expo-google-fonts/martel";
import {
Spectral_600SemiBold_Italic,
Spectral_300Light,
} from "@expo-google-fonts/spectral";
import { ThemeProvider } from "@shopify/restyle";
import Amplify from "aws-amplify";
import { AmplifyTheme, withAuthenticator } from "aws-amplify-react-native";
import AppLoading from "expo-app-loading";
import * as SplashScreen from "expo-splash-screen";
import { StatusBar } from "expo-status-bar";
import React, { useContext, useEffect, useState } from "react";
import { LogBox } from "react-native";
import config from "./aws-exports";
import useCachedResources from "./src/hooks/useCachedResources";
import RootStackNavigator from "./src/navigation";
import ConfirmSignUp from "./src/navigation/Authentication/ConfirmSignup";
import ForgotPassword from "./src/navigation/Authentication/ForgotPassword";
import SignIn from "./src/navigation/Authentication/SignIn";
import SignUp from "./src/navigation/Authentication/SignUp";
import { AuthContextProvider } from "./src/stores/AuthContext";
import { DataContextProvider } from "./src/stores/DataContext";
import { ErrorContextProvider } from "./src/stores/ErrorContext";
import { FavoritesContextProvider } from "./src/stores/FavoritesContext";
import { ThemeContext, ThemeContextProvider } from "./src/stores/ThemeContext";
import { dark, theme } from "./src/theme";
LogBox.ignoreLogs([
"Possible Unhandled Promise Rejection",
"Native splash screen",
]);
Amplify.configure({
...config,
Analytics: {
disabled: true,
},
});
function App() {
const isLoadingComplete = useCachedResources();
SplashScreen.preventAutoHideAsync()
.then((result) =>
console.log(`SplashScreen.preventAutoHideAsync() succeeded: ${result}`)
)
.catch(console.warn);
const { t } = useContext(ThemeContext);
const [darkTheme, setDarkTheme] = useState(true);
const [fontsLoaded] = useFonts({
Martel_400Regular,
Martel_700Bold,
Martel_800ExtraBold,
Lato_400Regular,
Spectral_300Light,
Spectral_600SemiBold_Italic,
});
useEffect(() => {
if (!t) {
setDarkTheme(true);
} else {
switch (t) {
case "light":
setDarkTheme(false);
break;
case "dark":
setDarkTheme(true);
break;
default:
setDarkTheme(true);
}
}
}, [t]);
return !isLoadingComplete || !fontsLoaded ? (
<AppLoading />
) : (
<ThemeProvider theme={darkTheme ? dark : theme}>
<RootStackNavigator />
<StatusBar style={t === "dark" ? "light" : "dark"} />
</ThemeProvider>
);
}
const Root = () => {
return (
<ErrorContextProvider>
<AuthContextProvider>
<FavoritesContextProvider>
<DataContextProvider>
<ThemeContextProvider>
<App />
</ThemeContextProvider>
</DataContextProvider>
</FavoritesContextProvider>
</AuthContextProvider>
</ErrorContextProvider>
);
};
// SafeAreaViewAdded to withAuthenticator.
// See https://github.com/aws-amplify/amplify-js/issues/2951
const CustomAmplifyAuthTheme = Object.assign({}, AmplifyTheme, {
container: {
flex: 1,
flexDirection: "column",
alignItems: "center",
justifyContent: "space-around",
paddingTop: 0,
paddingBottom: 0,
marginBottom: -20,
width: "100%",
backgroundColor: "#17202B",
},
});
export default withAuthenticator(
Root,
false,
[<SignIn />, <SignUp />, <ForgotPassword />, <ConfirmSignUp />],
null,
CustomAmplifyAuthTheme
);