-
Notifications
You must be signed in to change notification settings - Fork 34
/
SpinningIcon.js
46 lines (33 loc) · 991 Bytes
/
SpinningIcon.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
import React, { Component } from 'react';
import { Animated, Easing } from 'react-native';
import Icon from './Icon';
class SpinningIcon extends Component {
spinValue = new Animated.Value(0);
componentDidMount(){
this.spin();
};
spin = () => {
this.spinValue.setValue(0);
Animated.timing(
this.spinValue,
{
toValue: 1,
duration: 1000,
easing: Easing.linear,
useNativeDriver: true
}
).start(() => this.spin());
};
render() {
const { style, children } = this.props;
const rotate = this.spinValue.interpolate({inputRange: [0, 1], outputRange: ['0deg', '360deg']});
return(
<Animated.View style={{transform: [{rotate}]}}>
<Icon style={style}>
{children}
</Icon>
</Animated.View>
)
}
}
export default SpinningIcon;