Skip to content

Commit d07ec82

Browse files
committed
UPDATE Example
1 parent cec459d commit d07ec82

File tree

2 files changed

+102
-68
lines changed

2 files changed

+102
-68
lines changed

Example/App.js

Lines changed: 9 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ import {
1414
Animated,
1515
Easing
1616
} from 'react-native';
17-
import {SmartRefreshControl, AnyHeader} from 'react-native-smartrefreshlayout';
18-
import Icon from 'react-native-vector-icons/Ionicons'
19-
import {DotIndicator,SkypeIndicator} from 'react-native-indicators';
20-
const AnimatedIcon = Animated.createAnimatedComponent(Icon)
17+
import HuaWeiRefreshControl from './HuaWeiRefreshControl'
2118
const instructions = Platform.select({
2219
ios: 'Press Cmd+R to reload,\n' +
2320
'Cmd+D or shake for dev menu',
@@ -42,75 +39,19 @@ Date.prototype.Format = function (fmt) { // author: meizz
4239
}
4340
type Props = {};
4441
export default class App extends Component<Props> {
45-
state = {
46-
text:'下拉刷新',
47-
rotate:new Animated.Value(0),
48-
refreshing:false
42+
_onRefresh=()=>{
43+
setTimeout(()=>{
44+
this._hw && this._hw.finishRefresh()
45+
},1000)
4946
}
50-
5147
render() {
5248
return (
5349
<ScrollView
50+
style={{flex:1}}
5451
refreshControl={
55-
<SmartRefreshControl
56-
ref={ref=>this._refreshc = ref}
57-
onRefresh={()=>{
58-
console.log('onRefresh'+((new Date()).Format("yyyy-MM-dd hh:mm:ss.S")))
59-
60-
setTimeout(()=>{
61-
this._refreshc && this._refreshc.finishRefresh();
62-
},1000)
63-
}}
64-
onPullDownToRefresh={()=>{
65-
this.setState({
66-
text:'下拉刷新',
67-
refreshing:false
68-
})
69-
Animated.timing(this.state.rotate,{
70-
toValue:0,
71-
duration:197,
72-
useNativeDriver:true,
73-
easing:Easing.linear()
74-
}).start()
75-
}
76-
}
77-
onHeaderReleased={(e)=>{
78-
console.log('onHeaderReleased'+((new Date()).Format("yyyy-MM-dd hh:mm:ss.S")))
79-
this.setState({
80-
refreshing:true,
81-
text:'正在刷新'
82-
});
83-
}}
84-
onReleaseToRefresh={()=>{
85-
this.setState({
86-
text:'释放刷新'
87-
})
88-
Animated.timing(this.state.rotate,{
89-
toValue:1,
90-
duration:197,
91-
useNativeDriver:true,
92-
easing:Easing.linear()
93-
}).start()
94-
}}
95-
headerHeight={100}
96-
HeaderComponent={
97-
<AnyHeader style={{
98-
height: 100,
99-
flexDirection: 'row',
100-
alignItems: 'center',
101-
justifyContent: 'center',
102-
}}>
103-
{this.state.refreshing?<SkypeIndicator style={{flex:0}} size={24} color={'#2783cf'}/>:<AnimatedIcon style={{
104-
transform:[{
105-
rotate:this.state.rotate.interpolate({
106-
inputRange:[0,1],
107-
outputRange:['180deg','0deg']
108-
})
109-
}]
110-
}} name="md-arrow-up" color="#2783cf" size={24}/>}
111-
<Text style={{marginLeft:15}}>{this.state.text}</Text>
112-
</AnyHeader>
113-
}
52+
<HuaWeiRefreshControl
53+
ref={ref=>this._hw = ref}
54+
onRefresh={this._onRefresh}
11455
/>
11556
}
11657
>

Example/HuaWeiRefreshControl.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* 类似华为手机的下拉刷新
3+
*/
4+
import React, {Component} from 'react';
5+
import {
6+
StyleSheet,
7+
View,
8+
Text,
9+
Animated,
10+
Easing
11+
} from 'react-native';
12+
import PropTypes from 'prop-types';
13+
import {SmartRefreshControl, AnyHeader} from 'react-native-smartrefreshlayout';
14+
import Icon from 'react-native-vector-icons/Ionicons';
15+
import {SkypeIndicator} from 'react-native-indicators';
16+
17+
const AnimatedIcon = Animated.createAnimatedComponent(Icon);
18+
export default class HuaWeiRefreshControl extends Component {
19+
state = {
20+
text: '下拉刷新',
21+
rotate: new Animated.Value(0),
22+
refreshing: false
23+
}
24+
_onPullDownToRefresh = () => {
25+
this.setState({
26+
text: '下拉刷新',
27+
refreshing: false
28+
})
29+
Animated.timing(this.state.rotate, {
30+
toValue: 0,
31+
duration: 197,
32+
useNativeDriver: true,
33+
easing: Easing.linear()
34+
}).start()
35+
}
36+
_onReleased = () => {
37+
this.setState({
38+
refreshing: true,
39+
text: '正在刷新'
40+
});
41+
}
42+
_onReleaseToRefresh = () => {
43+
this.setState({
44+
text: '释放刷新'
45+
})
46+
Animated.timing(this.state.rotate, {
47+
toValue: 1,
48+
duration: 197,
49+
useNativeDriver: true,
50+
easing: Easing.linear()
51+
}).start()
52+
}
53+
_onRefresh = () => {
54+
let {onRefresh} = this.props;
55+
onRefresh && onRefresh();
56+
}
57+
finishRefresh=(params)=>{
58+
this._refreshc && this._refreshc.finishRefresh(params)
59+
}
60+
render() {
61+
return (
62+
<SmartRefreshControl
63+
style={{flex:1}}
64+
ref={ref => this._refreshc = ref}
65+
children={this.props.children}
66+
onRefresh={this._onRefresh}
67+
onPullDownToRefresh={this._onPullDownToRefresh}
68+
onHeaderReleased={this._onReleased}
69+
onReleaseToRefresh={this._onReleaseToRefresh}
70+
headerHeight={100}
71+
HeaderComponent={
72+
<AnyHeader style={{
73+
height: 100,
74+
flexDirection: 'row',
75+
alignItems: 'center',
76+
justifyContent: 'center',
77+
}}>
78+
{this.state.refreshing ? <SkypeIndicator style={{flex: 0}} size={24} color={'#2783cf'}/> :
79+
<AnimatedIcon style={{
80+
transform: [{
81+
rotate: this.state.rotate.interpolate({
82+
inputRange: [0, 1],
83+
outputRange: ['180deg', '0deg']
84+
})
85+
}]
86+
}} name="md-arrow-up" color="#2783cf" size={24}/>}
87+
<Text style={{marginLeft: 15}}>{this.state.text}</Text>
88+
</AnyHeader>
89+
}
90+
/>
91+
)
92+
}
93+
}

0 commit comments

Comments
 (0)