@@ -6,100 +6,102 @@ import AnimatedCircle from '../animated/AnimatedCircle';
6
6
import { color } from '../const' ;
7
7
8
8
export default class RotationCircleLoader extends React . PureComponent {
9
- static propTypes = {
10
- size : PropTypes . number ,
11
- color : PropTypes . string ,
12
- } ;
9
+ static propTypes = {
10
+ size : PropTypes . number ,
11
+ color : PropTypes . string ,
12
+ } ;
13
13
14
- static defaultProps = {
15
- size : 50 ,
16
- color,
17
- } ;
14
+ static defaultProps = {
15
+ size : 50 ,
16
+ color,
17
+ } ;
18
18
19
- state = {
20
- degree : new Animated . Value ( 0 ) ,
21
- scales : [ new Animated . Value ( 0 ) , new Animated . Value ( 0 ) ] ,
22
- } ;
23
- timers = [ ] ;
19
+ state = {
20
+ degree : new Animated . Value ( 0 ) ,
21
+ scales : [ new Animated . Value ( 0 ) , new Animated . Value ( 0 ) ]
22
+ } ;
23
+ timers = [ ] ;
24
24
25
- componentDidMount ( ) {
26
- this . _animation ( ) ;
27
- this . state . scales . forEach ( ( item , i ) => {
28
- const id = setTimeout ( ( ) => {
29
- this . _animationCircles ( i ) ;
30
- } , i * 500 ) ;
31
- this . timers . push ( id ) ;
32
- } ) ;
33
- }
25
+ componentDidMount ( ) {
26
+ this . _animation ( ) ;
27
+ this . state . scales . forEach ( ( item , i ) => {
28
+ const id = setTimeout ( ( ) => {
29
+ this . _animationCircles ( i )
30
+ } , i * 500 ) ;
31
+ this . timers . push ( id ) ;
32
+ } ) ;
34
33
35
- componentWillUnmount ( ) {
36
- this . unmounted = true ;
37
- this . timers . forEach ( ( id ) => {
38
- clearTimeout ( id ) ;
39
- } ) ;
40
- }
34
+ }
41
35
42
- _animation = ( ) => {
43
- Animated . sequence ( [
44
- Animated . timing ( this . state . degree , {
45
- toValue : 360 ,
46
- duration : 2000 ,
47
- easing : Easing . linear ,
48
- useNativeDriver : false ,
49
- } ) ,
50
- ] ) . start ( ( ) => {
51
- if ( ! this . unmounted ) {
52
- this . state . degree . setValue ( 0 ) ;
53
- this . _animation ( ) ;
54
- }
55
- } ) ;
56
- } ;
36
+ componentWillUnmount ( ) {
37
+ this . unmounted = true ;
38
+ this . timers . forEach ( ( id ) => {
39
+ clearTimeout ( id ) ;
40
+ } ) ;
41
+ }
57
42
58
- _animationCircles = ( i ) => {
59
- Animated . sequence ( [
60
- Animated . timing ( this . state . scales [ i ] , { toValue : 1 , duration : 1000 , useNativeDriver : false } ) ,
61
- Animated . timing ( this . state . scales [ i ] , {
62
- toValue : 0.05 ,
63
- duration : 1000 ,
64
- useNativeDriver : false ,
65
- } ) ,
66
- ] ) . start ( ( ) => {
67
- ! this . unmounted && this . _animationCircles ( i ) ;
68
- } ) ;
69
- } ;
43
+ _animation = ( ) => {
44
+ Animated . sequence ( [
45
+ Animated . timing ( this . state . degree , {
46
+ toValue : 360 ,
47
+ duration : 2000 ,
48
+ easing : Easing . linear ,
49
+ useNativeDriver : false
50
+ } )
51
+ ] ) . start ( ( ) => {
52
+ if ( ! this . unmounted ) {
53
+ this . state . degree . setValue ( 0 ) ;
54
+ this . _animation ( ) ;
55
+ }
56
+ } ) ;
57
+ } ;
70
58
71
- render ( ) {
72
- const { size, color } = this . props ;
73
- const degree = this . state . degree . interpolate ( {
74
- inputRange : [ 0 , 360 ] ,
75
- outputRange : [ '0deg' , '360deg' ] ,
76
- } ) ;
77
- return (
78
- < Animated . View
79
- style = { {
80
- transform : [ { rotate : degree } ] ,
81
- backgroundColor : 'rgba(0,0,0,0)' ,
82
- } }
83
- >
84
- < Surface width = { size } height = { size } >
85
- < Group >
86
- < AnimatedCircle
87
- fill = { color }
88
- radius = { size / 2 }
89
- x = { size / 2 }
90
- y = { size / 4 }
91
- scale = { this . state . scales [ 0 ] }
92
- />
93
- < AnimatedCircle
94
- fill = { color }
95
- radius = { size / 2 }
96
- x = { size / 2 }
97
- y = { ( size / 4 ) * 3 }
98
- scale = { this . state . scales [ 1 ] }
99
- />
100
- </ Group >
101
- </ Surface >
102
- </ Animated . View >
103
- ) ;
104
- }
59
+ _animationCircles = ( i ) => {
60
+ Animated . sequence ( [
61
+ Animated . timing ( this . state . scales [ i ] , { toValue : 1 , duration : 1000 , useNativeDriver : false } ) ,
62
+ Animated . timing ( this . state . scales [ i ] , {
63
+ toValue : 0.05 ,
64
+ duration : 1000 ,
65
+ useNativeDriver : false
66
+ } ) ,
67
+ ] ) . start ( ( ) => {
68
+ ! this . unmounted && this . _animationCircles ( i ) ;
69
+ } ) ;
70
+ } ;
71
+
72
+ render ( ) {
73
+ const { size, color } = this . props ;
74
+ const degree = this . state . degree . interpolate ( {
75
+ inputRange : [ 0 , 360 ] ,
76
+ outputRange : [ '0deg' , '360deg' ]
77
+ } ) ;
78
+ return (
79
+ < Animated . View
80
+ style = { {
81
+ transform : [ { rotate : degree } ] ,
82
+ backgroundColor : 'rgba(0,0,0,0)' ,
83
+ width : size ,
84
+ height : size
85
+ } } >
86
+ < Surface width = { size } height = { size } >
87
+ < Group >
88
+ < AnimatedCircle
89
+ fill = { color }
90
+ radius = { size / 2 }
91
+ x = { size / 2 }
92
+ y = { size / 4 }
93
+ scale = { this . state . scales [ 0 ] }
94
+ />
95
+ < AnimatedCircle
96
+ fill = { color }
97
+ radius = { size / 2 }
98
+ x = { size / 2 }
99
+ y = { size / 4 * 3 }
100
+ scale = { this . state . scales [ 1 ] }
101
+ />
102
+ </ Group >
103
+ </ Surface >
104
+ </ Animated . View >
105
+ ) ;
106
+ }
105
107
}
0 commit comments