-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadingScreen.js
77 lines (63 loc) · 2.06 KB
/
LoadingScreen.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
import React, { useContext, useState, useEffect } from 'react';
import { View, Text, StyleSheet, Image, Animated, Easing } from 'react-native';
import { AppContext } from './AppContext';
import PlanetsImage from './assets/images/planets/PlanetsImage';
const LoadingScreen = (props) => {
const appContext = useContext(AppContext);
const [spinAnim] = useState(new Animated.Value(0));
const styles = StyleSheet.create({
loading: {
flex: 1,
justifyContent: "center",
alignItems: "center"
},
image: {
width: 50,
height: 50
},
imageSaturn : {
width : 120,
height : 50
},
text: {
fontFamily : "A-Space Regular Demo",
fontSize : 14,
marginTop : 50,
color: '#FFF'
}
});
useEffect(() => {
//Animation that will spin an element on mount time
Animated.loop(Animated.timing(
spinAnim,
{
toValue: 1,
duration: 3000,
easing: Easing.linear,
useNativeDriver: true
}
)).start();
}, []);
/**
* Create an element with the previous animation attached to it to return the complete element.
*/
const createSpinner = () => {
let isSaturn = appContext.selectedPlanet.planetName === 'Saturn' ? styles.imageSaturn : null;
const spin = spinAnim.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '360deg']
});
return (
<Animated.View style={{ transform: [{ rotate: spin }] }}>
<Image style={[styles.image, isSaturn]} source={PlanetsImage[appContext.selectedPlanet.planetName]} />
</Animated.View>
);
}
return (
<View style={styles.loading}>
{createSpinner()}
<Text style={styles.text}>{appContext.translation.texts.loading}</Text>
</View>
);
}
export default LoadingScreen;