-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFulfillingBouncingCircleSpinner.js
109 lines (104 loc) · 3.12 KB
/
FulfillingBouncingCircleSpinner.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
/** @flow **/
import type { Element } from 'react';
import React, { useEffect } from 'react';
import { Animated, Easing, StyleSheet, View } from 'react-native';
import type { EpicSpinnersProps } from '../core/Typings';
import { EpicSpinnersDefaultProps } from '../core/Typings';
import { useAnimated } from '../core/CustomHooks';
import { GenerateAnimatedViews } from '../core/GenerateAnimatedViews';
export function FulfillingBouncingCircleSpinner(props: EpicSpinnersProps): Element<any> {
const { color, animationDuration, size, style, ...restProps } = props;
const containerSize = size * 5;
const VIEWS = ['circle', 'orbit'];
const [animate] = useAnimated();
const spinnerStyle = StyleSheet.create({
container: {
height: containerSize,
width: containerSize,
position: 'relative'
},
circle: {
height: containerSize,
width: containerSize,
borderColor: color,
borderRadius: containerSize * 0.5,
position: 'relative',
borderWidth: containerSize * 0.1
},
orbit: {
height: containerSize,
width: containerSize,
borderColor: color,
position: 'absolute',
top: 0,
left: 0,
borderRadius: containerSize * 0.5,
borderWidth: containerSize * 0.03
}
});
const animatedStyle = {
container: {
transform: [
{
rotate: animate.interpolate({
inputRange: [0, 9, 10],
outputRange: ['0deg', '360deg', '360deg']
})
}
]
},
orbit: {
transform: [
{
scale: animate.interpolate({
inputRange: [0, 6, 7, 8, 9, 10],
outputRange: [1, 1, 0.8, 1, 0.8, 1]
})
}
]
},
circle: {
transform: [
{
scale: animate.interpolate({
inputRange: [0, 6, 7, 8, 9, 10],
outputRange: [1, 1, 1.4, 1, 1.4, 1]
})
}
],
borderColor: animate.interpolate({
inputRange: [0, 4, 5, 9, 10],
outputRange: ['transparent', 'transparent', color, color, 'transparent']
}),
borderTopColor: animate.interpolate({
inputRange: [0, 10],
outputRange: [color, color]
}),
borderRightColor: animate.interpolate({
inputRange: [0, 1, 2, 9, 10],
outputRange: ['transparent', 'transparent', color, color, 'transparent']
}),
borderBottomColor: animate.interpolate({
inputRange: [0, 2, 3, 9, 10],
outputRange: ['transparent', 'transparent', color, color, 'transparent']
})
}
};
useEffect(() => {
Animated.loop(
Animated.timing(animate, {
toValue: 10,
duration: animationDuration * 4,
easing: Easing.inOut(Easing.ease)
})
).start();
}, [animate, animationDuration]);
return (
<View style={style} {...restProps}>
<Animated.View style={[spinnerStyle.container, animatedStyle.container]}>
<GenerateAnimatedViews animatedViewsArray={VIEWS} animatedStyle={animatedStyle} spinnerStyle={spinnerStyle} />
</Animated.View>
</View>
);
}
FulfillingBouncingCircleSpinner.defaultProps = EpicSpinnersDefaultProps;