Skip to content

Commit 8718512

Browse files
committed
scrollTo only if mounted
1 parent 907326f commit 8718512

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

GiftedListView.js

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -267,21 +267,25 @@ var GiftedListView = React.createClass({
267267
},
268268

269269
_onRefresh(options = {}) {
270-
this._scrollResponder.scrollTo(0);
271-
this.setState({
272-
refreshStatus: 'fetching',
273-
isRefreshing: true,
274-
});
275-
this._setPage(1);
276-
this.props.onFetch(this._getPage(), this._postRefresh, options);
270+
if (this.isMounted()) {
271+
this._scrollResponder.scrollTo(0);
272+
this.setState({
273+
refreshStatus: 'fetching',
274+
isRefreshing: true,
275+
});
276+
this._setPage(1);
277+
this.props.onFetch(this._getPage(), this._postRefresh, options);
278+
}
277279
},
278280

279281
_postRefresh(rows = [], options = {}) {
280-
this._updateRows(rows, options);
281-
if (this.props.refreshable === true && Platform.OS !== 'android') {
282-
// @issue
283-
// if a scrolling is already in progress, this scroll will not be executed
284-
this._scrollResponder.scrollTo(this.props.refreshableViewHeight);
282+
if (this.isMounted()) {
283+
this._updateRows(rows, options);
284+
if (this.props.refreshable === true && Platform.OS !== 'android') {
285+
// @issue
286+
// if a scrolling is already in progress, this scroll will not be executed
287+
this._scrollResponder.scrollTo(this.props.refreshableViewHeight);
288+
}
285289
}
286290
},
287291

@@ -304,21 +308,29 @@ var GiftedListView = React.createClass({
304308
},
305309

306310
_updateRows(rows = [], options = {}) {
307-
this._setRows(rows);
308-
if (this.props.withSections === true) {
309-
this.setState({
310-
dataSource: this.state.dataSource.cloneWithRowsAndSections(rows),
311-
refreshStatus: 'waiting',
312-
isRefreshing: false,
313-
paginationStatus: (options.allLoaded === true ? 'allLoaded' : 'waiting'),
314-
});
311+
if (rows !== null) {
312+
this._setRows(rows);
313+
if (this.props.withSections === true) {
314+
this.setState({
315+
dataSource: this.state.dataSource.cloneWithRowsAndSections(rows),
316+
refreshStatus: 'waiting',
317+
isRefreshing: false,
318+
paginationStatus: (options.allLoaded === true ? 'allLoaded' : 'waiting'),
319+
});
320+
} else {
321+
this.setState({
322+
dataSource: this.state.dataSource.cloneWithRows(rows),
323+
refreshStatus: 'waiting',
324+
isRefreshing: false,
325+
paginationStatus: (options.allLoaded === true ? 'allLoaded' : 'waiting'),
326+
});
327+
}
315328
} else {
316329
this.setState({
317-
dataSource: this.state.dataSource.cloneWithRows(rows),
318330
refreshStatus: 'waiting',
319331
isRefreshing: false,
320332
paginationStatus: (options.allLoaded === true ? 'allLoaded' : 'waiting'),
321-
});
333+
});
322334
}
323335
},
324336

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-gifted-listview",
3-
"version": "0.0.9",
3+
"version": "0.0.10",
44
"description": "A ListView that embed some recurrents features like pull-to-refresh, infinite scrolling and more for Android and iOS React-Native apps",
55
"main": "GiftedListView.js",
66
"scripts": {

0 commit comments

Comments
 (0)