-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
158 lines (143 loc) · 4.1 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
150
151
152
153
154
155
156
157
158
import { AppLoading, SplashScreen, Updates } from "expo";
import { Asset } from "expo-asset";
import Constants from "expo-constants";
import React from "react";
import { Animated, Button, StyleSheet, Text, View } from "react-native";
import { createDrawerNavigator } from "@react-navigation/drawer";
import { NavigationContainer } from "@react-navigation/native";
// Instruct SplashScreen not to hide yet, we want to do this manually
SplashScreen.preventAutoHide();
function HomeScreen({ navigation }) {
return (
<View
style={{
flex: 1,
backgroundColor: "#212121",
alignItems: "center",
justifyContent: "center",
}}
>
<Text
style={{
color: "#fff",
fontSize: 30,
marginBottom: 15,
fontWeight: "bold",
}}
>
Mangalab.
</Text>
<Button title="Run Again" onPress={() => Updates.reload()} />
<Button onPress={navigation.openDrawer} title="Open navigation drawer" />
<Button
onPress={() => navigation.navigate("Notifications")}
title="Go to notifications"
/>
</View>
);
}
function NotificationsScreen({ navigation }) {
return (
<View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
<Button onPress={navigation.openDrawer} title="Open navigation drawer" />
<Button onPress={() => navigation.goBack()} title="Go back home" />
</View>
);
}
const Drawer = createDrawerNavigator();
export default function App() {
return (
<AnimatedAppLoader image={{ uri: Constants.manifest.splash.image }}>
<MainScreen />
</AnimatedAppLoader>
);
}
function AnimatedAppLoader({ children, image }) {
const [isSplashReady, setSplashReady] = React.useState(false);
const startAsync = React.useMemo(
// If you use a local image with require(...), use `Asset.fromModule`
() => () => Asset.fromURI(image).downloadAsync(),
[image]
);
const onFinish = React.useMemo(() => setSplashReady(true), []);
if (!isSplashReady) {
return (
<AppLoading
startAsync={startAsync}
onError={console.error}
onFinish={onFinish}
/>
);
}
return <AnimatedSplashScreen image={image}>{children}</AnimatedSplashScreen>;
}
function AnimatedSplashScreen({ children, image }) {
const animation = React.useMemo(() => new Animated.Value(1), []);
const [isAppReady, setAppReady] = React.useState(false);
const [isSplashAnimationComplete, setAnimationComplete] = React.useState(
false
);
React.useEffect(() => {
if (isAppReady) {
Animated.timing(animation, {
toValue: 0,
duration: 200,
useNativeDriver: true,
}).start(() => setAnimationComplete(true));
}
}, [isAppReady]);
const onImageLoaded = React.useMemo(() => async () => {
SplashScreen.hide();
try {
// Load stuff
await Promise.all([]);
} catch (e) {
// handle errors
} finally {
setAppReady(true);
}
});
return (
<View style={{ flex: 1 }}>
{isAppReady && children}
{!isSplashAnimationComplete && (
<Animated.View
pointerEvents="none"
style={[
StyleSheet.absoluteFill,
{
backgroundColor: Constants.manifest.splash.backgroundColor,
opacity: animation,
},
]}
>
<Animated.Image
style={{
width: "100%",
height: "100%",
resizeMode: Constants.manifest.splash.resizeMode || "contain",
transform: [
{
scale: animation,
},
],
}}
source={image}
onLoadEnd={onImageLoaded}
fadeDuration={0}
/>
</Animated.View>
)}
</View>
);
}
function MainScreen() {
return (
<NavigationContainer>
<Drawer.Navigator initialRouteName="Home">
<Drawer.Screen name="Home" component={HomeScreen} />
<Drawer.Screen name="Notifications" component={NotificationsScreen} />
</Drawer.Navigator>
</NavigationContainer>
);
}