-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCirclesToRhombusesSpinner.js
85 lines (81 loc) · 2.69 KB
/
CirclesToRhombusesSpinner.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
/** @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, useAnimatedViewsNameGenerator } from '../core/CustomHooks';
import { GenerateAnimatedViews } from '../core/GenerateAnimatedViews';
export function CirclesToRhombusesSpinner(props: EpicSpinnersProps): Element<any> {
const { color, animationDuration, size, style, ...restProps } = props;
const [leftCircle, middleCircle, rightCircle] = useAnimated(3);
const VIEWS = useAnimatedViewsNameGenerator('circle', 3);
const getAnimatedInterpolation = (animated) => {
const squareBorderRadius = size * 0.1;
const circleBorderRadius = size * 0.5;
return {
borderRadius: animated.interpolate({
inputRange: [0, 1.7, 9.35, 10],
outputRange: [squareBorderRadius, circleBorderRadius, circleBorderRadius, squareBorderRadius]
})
};
};
const animationDelay = animationDuration * 0.17;
const spinnerStyle = StyleSheet.create({
container: {
height: size,
width: size,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center'
},
circle: {
height: size,
width: size,
marginHorizontal: size * 0.5,
transform: [{ rotate: '45deg' }],
borderRadius: size * 0.1,
borderWidth: size * 0.2,
borderColor: color,
overflow: 'hidden'
}
});
const animatedStyle = {
circle1: getAnimatedInterpolation(leftCircle),
circle2: getAnimatedInterpolation(middleCircle),
circle3: getAnimatedInterpolation(rightCircle)
};
useEffect(() => {
Animated.stagger(animationDelay, [
Animated.loop(
Animated.timing(leftCircle, {
toValue: 10,
duration: animationDuration,
easing: Easing.linear()
})
),
Animated.loop(
Animated.timing(middleCircle, {
toValue: 10,
duration: animationDuration,
easing: Easing.linear()
})
),
Animated.loop(
Animated.timing(rightCircle, {
toValue: 10,
duration: animationDuration,
easing: Easing.linear()
})
)
]).start();
}, [animationDelay, animationDuration, leftCircle, middleCircle, rightCircle]);
return (
<View style={style} {...restProps}>
<View style={spinnerStyle.container}>
<GenerateAnimatedViews animatedViewsArray={VIEWS} animatedStyle={animatedStyle} style={spinnerStyle.circle} />
</View>
</View>
);
}
CirclesToRhombusesSpinner.defaultProps = EpicSpinnersDefaultProps;