1
+ import React , { Component } from 'react' ;
2
+ import { StyleSheet , View , Text , Animated , Easing , Dimensions , Image , TouchableWithoutFeedback } from 'react-native' ;
3
+ import MJRefresh from 'react-native-mjrefresh' ;
4
+ import LottieView from 'lottie-react-native'
5
+ export default class LottieRefreshControl extends Component {
6
+ state = {
7
+ scale : new Animated . Value ( 0.1 )
8
+ }
9
+ _onRefresh = ( ) => {
10
+ let { onRefresh} = this . props ;
11
+ onRefresh && onRefresh ( ) ;
12
+ this . lottieView . play ( this . state . scale . __getValue ( ) )
13
+ }
14
+ _onPulling = ( event ) => {
15
+ let { percent} = event . nativeEvent ;
16
+ if ( percent <= 1 ) {
17
+ this . state . scale . setValue ( event . nativeEvent . percent ) ;
18
+ }
19
+ }
20
+ finishRefresh = ( ) => {
21
+ this . _mjrefresh && this . _mjrefresh . finishRefresh ( ) ;
22
+ this . lottieView . reset ( ) ;
23
+ }
24
+ beginRefresh = ( ) => {
25
+ this . _mjrefresh && this . _mjrefresh . beginRefresh ( ) ;
26
+ }
27
+ render ( ) {
28
+ return (
29
+ < MJRefresh
30
+ ref = { ref => this . _mjrefresh = ref }
31
+ onRefresh = { this . _onRefresh }
32
+ onPulling = { this . _onPulling }
33
+ // style={{backgroundColor:'transparent'}}
34
+ >
35
+ < View style = { {
36
+ height : 100 ,
37
+ flexDirection : 'row' ,
38
+ alignItems : 'center' ,
39
+ justifyContent : 'center' ,
40
+ } } >
41
+ < Animated . View style = { { height :100 , justifyContent :'center' , alignItems :'center' , transform : [ {
42
+ scale :this . state . scale . interpolate ( {
43
+ inputRange : [ 0 , 1 , 2 ] ,
44
+ outputRange : [ 0.1 , 1 , 1 ] ,
45
+ } )
46
+ } ] } } >
47
+ < LottieView speed = { 2 } ref = { obj => this . lottieView = obj } style = { { width :100 , height :100 } } hardwareAccelerationAndroid progress = { this . state . scale } source = { require ( './cycle_animation.json' ) } />
48
+ </ Animated . View >
49
+ </ View >
50
+ </ MJRefresh >
51
+ )
52
+ }
53
+ }
0 commit comments