-
Notifications
You must be signed in to change notification settings - Fork 4
/
App.js
78 lines (76 loc) · 2.69 KB
/
App.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
import React, { useState, useEffect } from "react";
import { NavigationContainer } from "@react-navigation/native";
import { AppLoading } from "expo";
import navigationTheme from "./app/navigation/navigationTheme";
import AppNavigator from "./app/navigation/AppNavigator";
import OfflineNotice from "./app/components/OfflineNotice";
import AuthNavigator from "./app/navigation/AuthNavigator";
import AuthContext from "./app/auth/context";
import authStorage from "./app/auth/storage";
import { navigationRef } from "./app/navigation/rootNavigation";
import languageSupport from "./app/utility/languageSupport";
import { AsyncStorage } from "react-native";
import { Provider as PaperProvider } from "react-native-paper";
import auth from "./app/api/auth";
import { ThemeProvider } from "styled-components";
import { ToastProvider } from "react-native-styled-toast";
import CameraScreen from "./app/screens/Chat/CameraScreen";
languageSupport.init();
export default function App() {
//return <BarChart data={[10, 20, 30, 40, 50]} height={200} />;
const [user, setUser] = useState();
const [isReady, setIsReady] = useState(false);
const [theme, setTheme] = useState("light");
const setLastTheme = async () => {
let lastTheme = await AsyncStorage.getItem("theme");
if (!lastTheme) lastTheme = "light";
setTheme(lastTheme);
};
useEffect(() => {
setLastTheme();
return () => {
auth.userLeftApp();
};
}, []);
const saveTheme = (new_theme) => {
setTheme(new_theme);
AsyncStorage.setItem("theme", new_theme);
};
const restoreUser = async () => {
const user = await authStorage.getUser();
if (user) setUser(user);
};
// return <ValidateEmailScreen />;
if (!isReady)
return (
<AppLoading startAsync={restoreUser} onFinish={() => setIsReady(true)} />
);
return (
<ThemeProvider theme={navigationTheme[theme]}>
<AuthContext.Provider
value={{ user, setUser, setTheme: saveTheme, theme }}
>
<PaperProvider theme={navigationTheme[theme]}>
<ToastProvider position="BOTTOM" offset={40}>
<OfflineNotice />
<NavigationContainer
ref={navigationRef}
theme={navigationTheme[theme]}
linking={{
config: {
screens: {
login: "login/",
listingDetail: "listings/:id",
},
},
prefixes: ["sellIt://", "http://sellIt.com"],
}}
>
{user ? <AppNavigator /> : <AuthNavigator />}
</NavigationContainer>
</ToastProvider>
</PaperProvider>
</AuthContext.Provider>
</ThemeProvider>
);
}