-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathHuaWeiRefreshControl.js
93 lines (92 loc) · 3.01 KB
/
HuaWeiRefreshControl.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* 类似华为手机的下拉刷新
*/
import React, {Component} from 'react';
import {
StyleSheet,
View,
Text,
Animated,
Easing
} from 'react-native';
import PropTypes from 'prop-types';
import {SmartRefreshControl, AnyHeader} from 'react-native-smartrefreshlayout';
import Icon from 'react-native-vector-icons/Ionicons';
import {SkypeIndicator} from 'react-native-indicators';
const AnimatedIcon = Animated.createAnimatedComponent(Icon);
export default class HuaWeiRefreshControl extends Component {
state = {
text: '下拉刷新',
rotate: new Animated.Value(0),
refreshing: false
}
_onPullDownToRefresh = () => {
this.setState({
text: '下拉刷新',
refreshing: false
})
Animated.timing(this.state.rotate, {
toValue: 0,
duration: 197,
useNativeDriver: true,
easing: Easing.linear()
}).start()
}
_onReleased = () => {
this.setState({
refreshing: true,
text: '正在刷新'
});
}
_onReleaseToRefresh = () => {
this.setState({
text: '释放刷新'
})
Animated.timing(this.state.rotate, {
toValue: 1,
duration: 197,
useNativeDriver: true,
easing: Easing.linear()
}).start()
}
_onRefresh = () => {
let {onRefresh} = this.props;
onRefresh && onRefresh();
}
finishRefresh=(params)=>{
this._refreshc && this._refreshc.finishRefresh(params)
}
render() {
return (
<SmartRefreshControl primaryColor='#ffcc03'
style={{flex:1}}
ref={ref => this._refreshc = ref}
children={this.props.children}
onRefresh={this._onRefresh}
onPullDownToRefresh={this._onPullDownToRefresh}
onHeaderReleased={this._onReleased}
onReleaseToRefresh={this._onReleaseToRefresh}
headerHeight={100}
HeaderComponent={
<AnyHeader style={{
height: 100,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
}}>
{this.state.refreshing ? <SkypeIndicator style={{flex: 0}} size={24} color={'#2783cf'}/> :
<AnimatedIcon style={{
transform: [{
rotate: this.state.rotate.interpolate({
inputRange: [0, 1],
outputRange: ['180deg', '0deg']
})
}]
}} name="md-arrow-up" color="#2783cf" size={24}/>}
<Text style={{marginLeft: 15}}>{this.state.text}</Text>
</AnyHeader>
}
/>
)
}
}