Skip to content

Fix pull to refresh logic #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion lib/ControlledRefreshableListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const LISTVIEW_REF = 'listview'

var ControlledRefreshableListView = React.createClass({
propTypes: {
resolveScroll: PropTypes.func.isRequired,
onRefresh: PropTypes.func.isRequired,
isRefreshing: PropTypes.bool.isRequired,
refreshDescription: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
Expand All @@ -37,7 +38,16 @@ var ControlledRefreshableListView = React.createClass({
handleScroll(e) {
var scrollY = e.nativeEvent.contentInset.top + e.nativeEvent.contentOffset.y

if (!(this.props.ignoreInertialScroll && this.isTouching)) {
if (scrollY == 0 && this.scrollingUp && !this.isTouching) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 41-48 tells me when the user stops pulling and the scroll goes back to 0. Only then I set isRefreshing to false. Lines 46-48 were necesary because if I update the list while user is pulling, scroll position is set to 0 and then gets back to last position.

this.scrollingUp = false;
if (this.props.resolveScroll) {
this.props.resolveScroll();
}
} else if (scrollY < 0 && scrollY > -this.props.minPulldownDistance && !this.scrollingUp) {
this.scrollingUp = true;
}

if (!this.props.ignoreInertialScroll || this.isTouching) {
if (scrollY < -this.props.minPulldownDistance) {
if (!this.props.isRefreshing) {
if (this.props.onRefresh) {
Expand Down
9 changes: 9 additions & 0 deletions lib/RefreshableListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ var RefreshableListView = React.createClass({
refreshingIndictatorComponent: RefreshingIndicator,
}
},
_resolveScroll() {
if (this.resolveScroll) {
this.resolveScroll();
}
},
getInitialState() {
return {
isRefreshing: false,
Expand All @@ -49,6 +54,9 @@ var RefreshableListView = React.createClass({
Promise.all([
loadingDataPromise,
new Promise((resolve) => this.setState({isRefreshing: true}, resolve)),
new Promise((resolve) => {
this.resolveScroll = resolve;
}),
delay(this.props.minDisplayTime),
])
.then(() => delay(this.props.minBetweenTime))
Expand All @@ -71,6 +79,7 @@ var RefreshableListView = React.createClass({
ref={LISTVIEW_REF}
onRefresh={this.handleRefresh}
isRefreshing={this.state.isRefreshing}
resolveScroll={this._resolveScroll}
/>
)
},
Expand Down