-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFulfillingSquareSpinner.js
66 lines (61 loc) · 1.82 KB
/
FulfillingSquareSpinner.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
/** @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';
export function FulfillingSquareSpinner(props: EpicSpinnersProps): Element<any> {
const { color, animationDuration, size, style, ...restProps } = props;
const containerSize = size * 4;
const [animated] = useAnimated();
const spinnerStyle = StyleSheet.create({
container: {
height: containerSize,
width: containerSize,
position: 'relative',
borderWidth: containerSize * 0.1,
borderColor: color
},
spinnerInner: {
backgroundColor: color,
width: '100%',
opacity: 1
}
});
const animatedStyle = {
container: {
transform: [
{
rotate: animated.interpolate({
inputRange: [0, 1, 2, 4, 5],
outputRange: ['0deg', '180deg', '180deg', '360deg', '360deg']
})
}
]
},
spinnerInner: {
height: animated.interpolate({
inputRange: [0, 1, 2, 4, 5],
outputRange: ['0%', '0%', '100%', '100%', '0%']
})
}
};
useEffect(() => {
Animated.loop(
Animated.timing(animated, {
toValue: 5,
duration: animationDuration,
easing: Easing.ease
})
).start();
}, [animated, animationDuration]);
return (
<View style={style} {...restProps}>
<Animated.View style={[spinnerStyle.container, animatedStyle.container]}>
<Animated.View style={[spinnerStyle.spinnerInner, animatedStyle.spinnerInner]} />
</Animated.View>
</View>
);
}
FulfillingSquareSpinner.defaultProps = EpicSpinnersDefaultProps;