-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathPullToRefreshView.android.js
More file actions
74 lines (70 loc) · 1.58 KB
/
Copy pathPullToRefreshView.android.js
File metadata and controls
74 lines (70 loc) · 1.58 KB
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 from 'react'
import PropTypes from 'prop-types'
import { View, RefreshControl, ScrollView } from 'react-native'
export default class PTRViewAndroid extends React.Component {
constructor (props) {
super(props)
this.state = {
isLoading: this.props.isLoading
}
}
_delay () {
return new Promise((resolve) => {
setTimeout(resolve, this.props.delay)
})
}
_handleOnRefresh () {
this.setState({ isLoading: true })
return new Promise((resolve) => {
Promise.all([
this.props.onRefresh(resolve),
this._delay()
])
.then(() => {
this._endLoading()
})
})
}
_endLoading () {
this.setState({
isLoading: false
})
}
componentWillReceiveProps(nextProps) {
if (nextProps.isLoading !== this.state.isLoading) {
this.setState({ isLoading: nextProps.isLoading });
}
}
render () {
return (
<ScrollView
{...this.props}
refreshControl={
<RefreshControl
refreshing={this.state.isLoading}
onRefresh={this._handleOnRefresh.bind(this)}
progressViewOffset={this.props.offset}
/>
}
>
{this.props.children}
</ScrollView>
)
}
}
PTRViewAndroid.defaultProps = {
colors: ['#000'],
progressBackgroundColor: '#fff',
offset: 0,
delay: 0,
isLoading: false
}
PTRViewAndroid.propTypes = {
delay: PropTypes.number,
onRefresh: PropTypes.func,
style: PropTypes.object,
children (props, propName, componentName) {
},
isLoading: PropTypes.bool
}