-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
149 lines (137 loc) · 4.65 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
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
149
import CreateAccountScreen from "./screens/CreateAccountScreen";
import CreateNotesScreen from "./screens/CreateNotesScreen";
import HomeScreen from "./screens/HomeScreen";
import LoginScreen from "./screens/LoginScreen";
import VerifyEmailScreen from "./screens/VerifyEmailScreen";
import HomeLoggedInScreen from "./screens/HomeLoggedInScreen";
import AddNoteToCategoryScreen from "./screens/AddNoteToCategoryScreen";
import BackupSettingsScreen from "./screens/BackupSettingsScreen";
import BackupSettingsFrequency from "./screens/BackupSettingsFrequency";
import SettingsScreen from "./screens/SettingsScreen";
import CreateNewPasswordScreen from "./screens/CreateNewPasswordScreen";
import ResetPasswordScreen from "./screens/ResetPasswordScreen";
import PrivacyPolicy from "./screens/PrivacyPolicy";
import NotesScreen from "./screens/NotesScreen";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { DefaultTheme } from "@react-navigation/native";
import { useEffect, useState } from "react";
import { checkIfLoggedIn } from "./settings/settings";
import { useFonts } from "expo-font";
import { initializeDB } from "./db/SchemaScript";
import { Asset } from "expo-asset";
import AppLoading from "expo-app-loading";
initializeDB();
const Stack = createNativeStackNavigator();
const MyTheme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
background: "#fff",
},
};
export default function App() {
const [isLoggedIn, setIsLoggedIn] = useState("loading");
/**
* Indicates if assets have been loaded.
*/
const [isLoaded, setIsLoaded] = useState(false);
/**
* Callback to set login status.
*
* @param {boolean} isLoggedIn login status
*/
const handleCheckLoggedIn = (isLoggedIn) => {
setIsLoggedIn(isLoggedIn);
};
/**
* Check if a user is logged in. Used to render initial
* component. If logged in, HomeLoggedIn screen is
* rendered otherwise the Home screen is rendered.
*/
useEffect(() => {
checkIfLoggedIn(handleCheckLoggedIn);
}, []);
/**
* Load fonts.
*/
const [fontLoaded] = useFonts({
LatoRegular: require("./assets/fonts/Lato-Regular.ttf"),
LatoBold: require("./assets/fonts/Lato-Bold.ttf"),
OverpassBold: require("./assets/fonts/Overpass-SemiBold.ttf"),
Overpass: require("./assets/fonts/Overpass-Regular.ttf"),
});
/**
* Cache assets.
*
* @returns promise that caches assets upon resolve
*/
const cacheResources = async () => {
const images = [
require("./assets/images/notes.png"),
require("./assets/images/notes.png"),
];
const cachedImages = images.map((image) => {
return Asset.fromModule(image).downloadAsync();
});
return Promise.all(cachedImages);
};
/**
* Load resources when mounted.
*/
useEffect(() => {
const loadResources = async () => {
await cacheResources();
setIsLoaded(true);
};
loadResources();
}, []);
/**
* Display splash screen while resources are
* being loaded.
*/
if (!isLoaded || !fontLoaded || isLoggedIn === "loading") {
return <AppLoading />;
}
return (
<NavigationContainer theme={MyTheme}>
<Stack.Navigator
screenOptions={{ headerShown: false }}
initialRouteName={isLoggedIn ? "HomeLoggedIn" : "Home"}
>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{ gestureEnabled: false }}
/>
<Stack.Screen name="CreateAccount" component={CreateAccountScreen} />
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen name="VerifyEmail" component={VerifyEmailScreen} />
<Stack.Screen
name="HomeLoggedIn"
component={HomeLoggedInScreen}
options={{ gestureEnabled: false }}
/>
<Stack.Screen name="CreateNote" component={CreateNotesScreen} />
<Stack.Screen
name="AddToCategory"
component={AddNoteToCategoryScreen}
options={{ gestureEnabled: false }}
/>
<Stack.Screen name="NotesScreen" component={NotesScreen} />
<Stack.Screen name="Backup" component={BackupSettingsScreen} />
<Stack.Screen name="Settings" component={SettingsScreen} />
<Stack.Screen
name="BackupFrequency"
component={BackupSettingsFrequency}
/>
<Stack.Screen name="ResetPassword" component={ResetPasswordScreen} />
<Stack.Screen
name="CreatePassword"
component={CreateNewPasswordScreen}
/>
<Stack.Screen name="Privacy" component={PrivacyPolicy} />
</Stack.Navigator>
</NavigationContainer>
);
}