-
Notifications
You must be signed in to change notification settings - Fork 75
/
PullView.js
74 lines (61 loc) · 2.06 KB
/
PullView.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
'use strict';
import React, { Component } from 'react';
import {
ScrollView,
} from 'react-native';
import Pullable from './Pullable';
/**
支持android&ios可以下拉刷新的PullView组件
Demo:
import {PullView} from 'react-native-pullview';
<PullView onPulling={} onPullOk={} onPullRelease={} isPullEnd={true}
topIndicatorRender={({pulling, pullok, pullrelease}) => {}} topIndicatorHeight={60}
>
Demo2:
topIndicatorRender(pulling, pullok, pullrelease) {
return <View style={{flex: 1, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', height: 60}}>
<ActivityIndicator size="small" color="gray" />
{pulling ? <Text>下拉刷新2...</Text> : null}
{pullok ? <Text>松开刷新2......</Text> : null}
{pullrelease ? <Text>玩命刷新中2......</Text> : null}
</View>;
}
<PullView onPullRelease={this.props.onRefresh} topIndicatorRender={this.topIndicatorRender} topIndicatorHeight={60} >
<Children />
</PullView>
Demo3:
onRefresh() {
this.setState({refreshing: true});
return new Promise((resolve) => {
setTimeout(() => {resolve()}, 9000);
}).then(() => {
this.setState({refreshing: false})
})
// setTimeout(() => {
// this.setState({refreshing: false});
// }, 3000);
}
<PullView refreshControl={} onRefresh={this.onRefresh} refreshing={this.state.refreshing}>
<Children />
</PullView>
*/
export default class extends Pullable {
constructor(props) {
super(props);
this.scrollTo = this.scrollTo.bind(this);
this.scrollToEnd = this.scrollToEnd.bind(this);
}
scrollTo(...args) {
this.scroll.scrollTo(...args);
}
scrollToEnd(args) {
this.scroll.scrollTo(args);
}
getScrollable(refreshControl) {
return (
<ScrollView ref={(c) => {this.scroll = c;}} refreshControl={refreshControl} onScroll={this.onScroll}>
{this.props.children}
</ScrollView>
);
}
}