-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadingIndicator.js
58 lines (50 loc) · 1.42 KB
/
LoadingIndicator.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
import React, { useCallback, useEffect, useRef } from "react";
import { View, StyleSheet, Animated } from "react-native";
const LoadingSpinner = () => {
const animationValue = useRef(new Animated.Value(0)).current;
const startAnimation = useCallback(() => {
Animated.loop(
Animated.timing(animationValue, {
toValue: 1, // 애니매이션의 100%일때의 값을 추출
duration: 700, // 애니메이션이 진행되는 시간
useNativeDriver: true,
})
).start();
}, [animationValue]);
useEffect(() => {
startAnimation();
}, [startAnimation]);
// inputRange : animationValue의 변화값
// outputRange : 해당 변화값에 대한 매칭되는 deg 값
const RotateData = animationValue.interpolate({
inputRange: [0, 1],
outputRange: ["0deg", "360deg"],
});
return (
<View style={styles.container}>
<Animated.Image
style={{
transform: [{ rotate: RotateData }],
width: 30,
height: 30,
}}
source={{
uri: "https://res.cloudinary.com/df9jsefb9/image/upload/c_scale,h_84,q_auto/v1501869525/assets/idc-loading-t_3x.png",
}}
/>
</View>
);
};
export default LoadingSpinner;
const styles = StyleSheet.create({
container: {
alignItems: "center",
justifyContent: "center",
maxWidth: 40,
maxHeight: 40,
},
spinnerImage: {
maxWidth: 20,
maxHeight: 20,
},
});