forked from zoontek/react-native-bootsplash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
101 lines (89 loc) · 2.44 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
import React, { useEffect, useRef, useState } from "react";
import { Animated, Dimensions, StyleSheet, Text, View } from "react-native";
import BootSplash from "react-native-bootsplash";
let bootSplashLogo = require("./assets/bootsplash_logo.png");
let fakeApiCallWithoutBadNetwork = (ms) =>
new Promise((resolve) => setTimeout(resolve, ms));
let App = () => {
let [bootSplashIsVisible, setBootSplashIsVisible] = useState(true);
let [bootSplashLogoIsLoaded, setBootSplashLogoIsLoaded] = useState(false);
let opacity = useRef(new Animated.Value(1));
let translateY = useRef(new Animated.Value(0));
let init = async () => {
// You can uncomment this line to add a delay on app startup
// await fakeApiCallWithoutBadNetwork(3000);
await BootSplash.hide();
Animated.stagger(250, [
Animated.spring(translateY.current, {
useNativeDriver: true,
toValue: -50,
}),
Animated.spring(translateY.current, {
useNativeDriver: true,
toValue: Dimensions.get("window").height,
}),
]).start();
Animated.timing(opacity.current, {
useNativeDriver: true,
toValue: 0,
duration: 150,
delay: 350,
}).start(() => {
setBootSplashIsVisible(false);
});
};
useEffect(() => {
bootSplashLogoIsLoaded && init();
}, [bootSplashLogoIsLoaded]);
return (
<View style={styles.container}>
<Text style={styles.text}>Hello, Dave.</Text>
{bootSplashIsVisible && (
<Animated.View
style={[
StyleSheet.absoluteFill,
styles.bootsplash,
{ opacity: opacity.current },
]}
>
<Animated.Image
source={bootSplashLogo}
fadeDuration={0}
onLoadEnd={() => setBootSplashLogoIsLoaded(true)}
style={[
styles.logo,
{ transform: [{ translateY: translateY.current }] },
]}
/>
</Animated.View>
)}
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF",
},
text: {
fontSize: 24,
fontWeight: "700",
margin: 20,
lineHeight: 30,
color: "#333",
textAlign: "center",
},
bootsplash: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF",
},
logo: {
height: 100,
width: 100,
},
});
export default App;