-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
102 lines (92 loc) · 3.34 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
import React, { useState, useEffect } from "react";
import { StyleSheet, Text, View } from "react-native";
import * as Font from "expo-font";
import { AppLoading } from "expo";
import StartScreen from "./screens/StartScreen";
import SignupScreen from "./screens/SignupScreen";
import LoginScreen from "./screens/LoginScreen";
import HomeScreen from "./screens/HomeScreen";
import pages from "./constants/Pages";
import FriendScreen from "./screens/FriendScreen";
import LibraryScreen from "./screens/LibraryScreen";
import FavScreen from "./screens/FavScreen";
import UnderConstruction from "./screens/UnderConstruction";
import colors from "./constants/Colors";
export default function App() {
const [loaded, setLoaded] = useState(false);
const [currPage, setCurrPage] = useState(pages.startPage);
const handleLoadError = error => {
console.warn(error);
};
/**
* * Switching function
* This is the main mechanism for switching pages.
* To add a new page to switch to, just add a key string of your choice.
* Could be anything you want, as long is the if statement below regarding
* currPage also scans for that specific key string.
*/
const handleSwitchPages = keyString => {
setCurrPage(keyString);
};
const handleLoadComplete = () => {
setLoaded(true);
};
// Load all fonts before app loads
async function loadAsyncResources() {
await Promise.all([
Font.loadAsync({
"montserrat-thin": require("./assets/fonts/Montserrat-Thin.ttf"),
"montserrat-light": require("./assets/fonts/Montserrat-Light.ttf"),
"montserrat-regular": require("./assets/fonts/Montserrat-Regular.ttf"),
"montserrat-medium": require("./assets/fonts/Montserrat-Medium.ttf"),
"montserrat-bold": require("./assets/fonts/Montserrat-Bold.ttf")
})
]);
}
/**
* This content variable will change according to which page user is on.
* Use different key strings to manage the pages.
*/
let content = <StartScreen switchHandler={handleSwitchPages} />;
/**
* If statement controlling page display. It's gonna get big.
*/
if (currPage === pages.startPage) {
content = <StartScreen switchHandler={handleSwitchPages} />;
} else if (currPage === pages.signupPage) {
content = <SignupScreen switchHandler={handleSwitchPages} />;
} else if (currPage === pages.loginPage) {
content = <LoginScreen switchHandler={handleSwitchPages} />;
} else if (currPage === pages.homePage) {
content = <HomeScreen switchHandler={handleSwitchPages} />;
} else if (currPage === pages.friendsPage) {
content = (
<UnderConstruction switchHandler={handleSwitchPages} active="friends" />
);
} else if (currPage === pages.libPage) {
content = <LibraryScreen switchHandler={handleSwitchPages} />;
} else if (currPage === pages.favPage) {
content = (
<UnderConstruction switchHandler={handleSwitchPages} active="fav" />
);
}
if (loaded) {
// If all content is finished loading
return <View style={styles.screen}>{content}</View>;
} else {
// AppLoading component loads all resouces first
return (
<AppLoading
startAsync={loadAsyncResources}
onError={handleLoadError}
onFinish={handleLoadComplete}
/>
);
}
}
const styles = StyleSheet.create({
screen: {
flex: 1,
backgroundColor: colors.allBackground
}
});