1- import React , { useEffect , useRef } from 'react' ;
21import { Animated , Easing , View } from 'react-native' ;
32
4- const AnimateState = {
5- start : 0 ,
6- end : 360 ,
7- } ;
8-
93const Loader = ( ) => {
10- const value = useRef ( new Animated . Value ( AnimateState . start ) ) . current ;
11- const inputRange = [ AnimateState . start , AnimateState . end ] ;
12- const rotate = value . interpolate ( {
13- inputRange,
14- outputRange : [ 0 + 'deg' , 360 + 'deg' ] ,
4+ const spinValue = new Animated . Value ( 0 ) ;
5+
6+ Animated . loop (
7+ Animated . timing ( spinValue , {
8+ toValue : 1 ,
9+ duration : 1500 ,
10+ easing : Easing . linear ,
11+ useNativeDriver : true ,
12+ } )
13+ ) . start ( ) ;
14+
15+ const spin = spinValue . interpolate ( {
16+ inputRange : [ 0 , 1 ] ,
17+ outputRange : [ '0deg' , '360deg' ] ,
1518 } ) ;
1619
17- useEffect ( ( ) => {
18- startAnimate ( ) ;
19-
20- return ( ) => {
21- stopAnimate ( ) ;
22- } ;
23- } , [ ] ) ;
24-
25- const startAnimate = ( ) => {
26- Animated . loop (
27- Animated . sequence ( [
28- Animated . timing ( value , {
29- toValue : AnimateState . end ,
30- useNativeDriver : false ,
31- duration : 1000 ,
32- easing : Easing . linear ,
33- } ) ,
34- ] )
35- ) . start ( ) ;
36- } ;
37-
38- const stopAnimate = ( ) => value . stopAnimation ( ) ;
39-
4020 return (
4121 < View
4222 style = { {
@@ -51,7 +31,7 @@ const Loader = () => {
5131 < Animated . Image
5232 source = { require ( '../../assets/reload.png' ) }
5333 style = { {
54- transform : [ { rotate } ] ,
34+ transform : [ { rotate : spin } ] ,
5535 justifyContent : 'center' ,
5636 marginTop : 'auto' ,
5737 marginBottom : 'auto' ,
0 commit comments