Skip to content
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

Tap to retry #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
48 changes: 43 additions & 5 deletions GiftedListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var GiftedListView = React.createClass({
paginationFetchingView: null,
paginationAllLoadedView: null,
paginationWaitingView: null,
paginationErrorView: null,
emptyView: null,
renderSeparator: null,
rowHasChanged:null,
Expand Down Expand Up @@ -81,6 +82,7 @@ var GiftedListView = React.createClass({
paginationFetchingView: React.PropTypes.func,
paginationAllLoadedView: React.PropTypes.func,
paginationWaitingView: React.PropTypes.func,
paginationErrorView: React.PropTypes.func,
emptyView: React.PropTypes.func,
renderSeparator: React.PropTypes.func,

Expand Down Expand Up @@ -118,6 +120,23 @@ var GiftedListView = React.createClass({
</View>
);
},

paginationErrorView(errorCallback) {
if (this.props.paginationErrorView) {
return this.props.paginationErrorView(errorCallback);
}
return (
<View style={[this.defaultStyles.paginationView, this.props.customStyles.paginationView]}>
<TouchableHighlight onPress={errorCallback}>
<View>
<Text style={[this.defaultStyles.actionsLabel, this.props.customStyles.actionsLabel]}>
Tap to retry
</Text>
</View>
</TouchableHighlight>
</View>
);
},
paginationWaitingView(paginateCallback) {
if (this.props.paginationWaitingView) {
return this.props.paginationWaitingView(paginateCallback);
Expand Down Expand Up @@ -235,12 +254,23 @@ var GiftedListView = React.createClass({
this.setState({
paginationStatus: 'fetching',
});
this.props.onFetch(this._getPage() + 1, this._postPaginate, {});
this._setPage(this._getPage() + 1);
this.props.onFetch(this._getPage(), this._postPaginate, {});
}
},

_onRetry() {
if(this.state.paginationStatus==='allLoaded'){
return null
}else {
this.setState({
paginationStatus: 'fetching',
});
this.props.onFetch(this._getPage(), this._postPaginate, {});
}
},

_postPaginate(rows = [], options = {}) {
this._setPage(this._getPage() + 1);
var mergedRows = null;
if (this.props.withSections === true) {
mergedRows = MergeRecursive(this._getRows(), rows);
Expand All @@ -258,23 +288,29 @@ var GiftedListView = React.createClass({
_updateRows(rows = [], options = {}) {
if (rows !== null) {
this._setRows(rows);
let paginationStatus = "waiting";
if(options.allLoaded){
paginationStatus = "allLoaded";
}else if(options.isError){
paginationStatus = "error";
}
if (this.props.withSections === true) {
this.setState({
dataSource: this.state.dataSource.cloneWithRowsAndSections(rows),
isRefreshing: false,
paginationStatus: (options.allLoaded === true ? 'allLoaded' : 'waiting'),
paginationStatus,
});
} else {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(rows),
isRefreshing: false,
paginationStatus: (options.allLoaded === true ? 'allLoaded' : 'waiting'),
paginationStatus,
});
}
} else {
this.setState({
isRefreshing: false,
paginationStatus: (options.allLoaded === true ? 'allLoaded' : 'waiting'),
paginationStatus,
});
}
},
Expand All @@ -286,6 +322,8 @@ var GiftedListView = React.createClass({
return this.paginationWaitingView(this._onPaginate);
} else if (this.state.paginationStatus === 'allLoaded' && this.props.pagination === true) {
return this.paginationAllLoadedView();
} else if (this.state.paginationStatus === 'error' && this.props.pagination === true) {
return this.paginationErrorView(this._onRetry);
} else if (this._getRows().length === 0) {
return this.emptyView(this._onRefresh);
} else {
Expand Down