Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 27 additions & 30 deletions lib/PullToRefreshView.android.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
'use strict'
'use strict';

import React from 'react'
import PropTypes from 'prop-types'
import { View, RefreshControl, ScrollView } from 'react-native'
import React from 'react';
import PropTypes from 'prop-types';
import { View, RefreshControl, ScrollView } from 'react-native';

export default class PTRViewAndroid extends React.Component {
constructor () {
super()
constructor() {
super();
this.state = {
isLoading: false
}
};
}
_delay () {
return new Promise((resolve) => {
setTimeout(resolve, this.props.delay)
})
_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()
})
})
_handleOnRefresh() {
this.setState({ isLoading: true });
return new Promise(resolve => {
Promise.all([this.props.onRefresh(resolve), this._delay()]).then(() => {
this._endLoading();
});
});
}
_endLoading () {
_endLoading() {
this.setState({
isLoading: false
})
});
}
render () {
render() {
return (
<ScrollView
{...this.props}
refreshControl={
<RefreshControl
colors={this.props.colors}
refreshing={this.state.isLoading}
onRefresh={this._handleOnRefresh.bind(this)}
progressViewOffset={this.props.offset}
Expand All @@ -47,7 +44,7 @@ export default class PTRViewAndroid extends React.Component {
>
{this.props.children}
</ScrollView>
)
);
}
}

Expand All @@ -56,12 +53,12 @@ PTRViewAndroid.defaultProps = {
progressBackgroundColor: '#fff',
offset: 0,
delay: 0
}
};

PTRViewAndroid.propTypes = {
delay: PropTypes.number,
onRefresh: PropTypes.func,
style: PropTypes.object,
children (props, propName, componentName) {
}
}
colors: PropTypes.array,
children(props, propName, componentName) {}
};