Skip to content

Commit 907326f

Browse files
committed
Merge pull request #9 from realaboo/master
[Androd] Fix incorrectly scroll to top after refresh
2 parents 7b4bfe0 + 47f4ce4 commit 907326f

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

GiftedListView.js

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function MergeRecursive(obj1, obj2) {
3131
var GiftedSpinner = require('react-native-gifted-spinner');
3232

3333
var GiftedListView = React.createClass({
34-
34+
3535
getDefaultProps() {
3636
return {
3737
customStyles: {},
@@ -45,7 +45,7 @@ var GiftedListView = React.createClass({
4545
sectionHeaderView: null,
4646
withSections: false,
4747
onFetch(page, callback, options) { callback([]); },
48-
48+
4949
paginationFetchigView: null,
5050
paginationAllLoadedView: null,
5151
paginationWaitingView: null,
@@ -60,7 +60,7 @@ var GiftedListView = React.createClass({
6060
},
6161
};
6262
},
63-
63+
6464
propTypes: {
6565
customStyles: React.PropTypes.object,
6666
initialListSize: React.PropTypes.number,
@@ -73,7 +73,7 @@ var GiftedListView = React.createClass({
7373
sectionHeaderView: React.PropTypes.func,
7474
withSections: React.PropTypes.bool,
7575
onFetch: React.PropTypes.func,
76-
76+
7777
paginationFetchigView: React.PropTypes.func,
7878
paginationAllLoadedView: React.PropTypes.func,
7979
paginationWaitingView: React.PropTypes.func,
@@ -84,20 +84,20 @@ var GiftedListView = React.createClass({
8484
renderSeparator: React.PropTypes.func,
8585
PullToRefreshViewAndroidProps: React.PropTypes.object,
8686
},
87-
87+
8888
_setY(y) { this._y = y; },
8989
_getY(y) { return this._y; },
9090
_setPage(page) { this._page = page; },
9191
_getPage() { return this._page; },
9292
_setRows(rows) { this._rows = rows; },
9393
_getRows() { return this._rows; },
94-
95-
94+
95+
9696
paginationFetchigView() {
9797
if (this.props.paginationFetchigView) {
9898
return this.props.paginationFetchigView();
9999
}
100-
100+
101101
return (
102102
<View style={[this.defaultStyles.paginationView, this.props.customStyles.paginationView]}>
103103
<GiftedSpinner />
@@ -108,7 +108,7 @@ var GiftedListView = React.createClass({
108108
if (this.props.paginationAllLoadedView) {
109109
return this.props.paginationAllLoadedView();
110110
}
111-
111+
112112
return (
113113
<View style={[this.defaultStyles.paginationView, this.props.customStyles.paginationView]}>
114114
<Text style={[this.defaultStyles.actionsLabel, this.props.customStyles.actionsLabel]}>
@@ -121,9 +121,9 @@ var GiftedListView = React.createClass({
121121
if (this.props.paginationWaitingView) {
122122
return this.props.paginationWaitingView(paginateCallback);
123123
}
124-
124+
125125
return (
126-
<TouchableHighlight
126+
<TouchableHighlight
127127
underlayColor='#c8c7cc'
128128
onPress={paginateCallback}
129129
style={[this.defaultStyles.paginationView, this.props.customStyles.paginationView]}
@@ -157,7 +157,7 @@ var GiftedListView = React.createClass({
157157
if (this.props.refreshableWillRefreshView) {
158158
return this.props.refreshableWillRefreshView();
159159
}
160-
160+
161161
return (
162162
<View>
163163
<View style={[this.defaultStyles.refreshableView, this.props.customStyles.refreshableView]}>
@@ -173,7 +173,7 @@ var GiftedListView = React.createClass({
173173
if (this.props.refreshableWaitingView) {
174174
return this.props.refreshableWaitingView(refreshCallback);
175175
}
176-
176+
177177
return (
178178
<View>
179179
<View style={[this.defaultStyles.refreshableView, this.props.customStyles.refreshableView]}>
@@ -189,14 +189,14 @@ var GiftedListView = React.createClass({
189189
if (this.props.emptyView) {
190190
return this.props.emptyView(refreshCallback);
191191
}
192-
192+
193193
return (
194194
<View style={[this.defaultStyles.defaultView, this.props.customStyles.defaultView]}>
195195
<Text style={[this.defaultStyles.defaultViewTitle, this.props.customStyles.defaultViewTitle]}>
196196
Sorry, there is no content to display
197197
</Text>
198-
199-
<TouchableHighlight
198+
199+
<TouchableHighlight
200200
underlayColor='#c8c7cc'
201201
onPress={refreshCallback}
202202
>
@@ -211,12 +211,12 @@ var GiftedListView = React.createClass({
211211
if (this.props.renderSeparator) {
212212
return this.props.renderSeparator();
213213
}
214-
214+
215215
return (
216216
<View style={[this.defaultStyles.separator, this.props.customStyles.separator]} />
217217
);
218218
},
219-
219+
220220
getInitialState() {
221221

222222
if (this.props.refreshable === true && Platform.OS !== 'android') {
@@ -243,7 +243,7 @@ var GiftedListView = React.createClass({
243243
} else {
244244
ds = new ListView.DataSource({
245245
rowHasChanged: (row1, row2) => row1 !== row2,
246-
});
246+
});
247247
return {
248248
dataSource: ds.cloneWithRows(this._getRows()),
249249
refreshStatus: 'waiting',
@@ -265,7 +265,7 @@ var GiftedListView = React.createClass({
265265
_refresh() {
266266
this._onRefresh({external: true});
267267
},
268-
268+
269269
_onRefresh(options = {}) {
270270
this._scrollResponder.scrollTo(0);
271271
this.setState({
@@ -275,23 +275,23 @@ var GiftedListView = React.createClass({
275275
this._setPage(1);
276276
this.props.onFetch(this._getPage(), this._postRefresh, options);
277277
},
278-
278+
279279
_postRefresh(rows = [], options = {}) {
280280
this._updateRows(rows, options);
281-
if (this.props.refreshable === true) {
281+
if (this.props.refreshable === true && Platform.OS !== 'android') {
282282
// @issue
283283
// if a scrolling is already in progress, this scroll will not be executed
284-
this._scrollResponder.scrollTo(this.props.refreshableViewHeight);
284+
this._scrollResponder.scrollTo(this.props.refreshableViewHeight);
285285
}
286286
},
287-
287+
288288
_onPaginate() {
289289
this.setState({
290290
paginationStatus: 'fetching',
291291
});
292292
this.props.onFetch(this._getPage() + 1, this._postPaginate, {});
293293
},
294-
294+
295295
_postPaginate(rows = [], options = {}) {
296296
this._setPage(this._getPage() + 1);
297297
var mergedRows = null;
@@ -302,7 +302,7 @@ var GiftedListView = React.createClass({
302302
}
303303
this._updateRows(mergedRows, options);
304304
},
305-
305+
306306
_updateRows(rows = [], options = {}) {
307307
this._setRows(rows);
308308
if (this.props.withSections === true) {
@@ -318,10 +318,10 @@ var GiftedListView = React.createClass({
318318
refreshStatus: 'waiting',
319319
isRefreshing: false,
320320
paginationStatus: (options.allLoaded === true ? 'allLoaded' : 'waiting'),
321-
});
321+
});
322322
}
323323
},
324-
324+
325325
_onResponderRelease() {
326326
if (this.props.refreshable === true) {
327327
if (Platform.OS !== 'android') {
@@ -331,12 +331,12 @@ var GiftedListView = React.createClass({
331331
}
332332
}
333333
},
334-
334+
335335
_onScroll(e) {
336336
this._setY(e.nativeEvent.contentOffset.y);
337337
if (this.props.refreshable === true) {
338338
if (Platform.OS !== 'android') {
339-
if (this._getY() < this.props.refreshableViewHeight - this.props.refreshableDistance
339+
if (this._getY() < this.props.refreshableViewHeight - this.props.refreshableDistance
340340
&& this.state.refreshStatus === 'waiting'
341341
&& this._scrollResponder.scrollResponderHandleScrollShouldSetResponder() === true
342342
) {
@@ -348,7 +348,7 @@ var GiftedListView = React.createClass({
348348
}
349349
}
350350
},
351-
351+
352352
_renderRefreshView() {
353353
switch (this.state.refreshStatus) {
354354
case 'fetching':
@@ -361,7 +361,7 @@ var GiftedListView = React.createClass({
361361
return this.refreshableWaitingView(this._onRefresh);
362362
}
363363
},
364-
364+
365365
_renderPaginationView() {
366366
if ((this.state.paginationStatus === 'fetching' && this.props.pagination === true) || (this.state.paginationStatus === 'firstLoad' && this.props.firstLoader === true)) {
367367
return this.paginationFetchigView();
@@ -383,16 +383,16 @@ var GiftedListView = React.createClass({
383383
return {top: 0, bottom: 0, left: 0, right: 0};
384384
}
385385
},
386-
386+
387387
_calculateContentOffset() {
388388
if (this.props.refreshable === true && Platform.OS !== 'android') {
389389
return {x: 0, y: this.props.refreshableViewHeight};
390390
} else {
391391
return {x: 0, y: 0};
392392
}
393393
},
394-
395-
394+
395+
396396
renderListView(style = {}) {
397397
return (
398398
<ListView
@@ -403,23 +403,23 @@ var GiftedListView = React.createClass({
403403

404404
renderHeader={this.props.refreshable === true && Platform.OS !== 'android' ? this._renderRefreshView : this.headerView}
405405
renderFooter={this._renderPaginationView}
406-
406+
407407
onScroll={this.props.refreshable === true && Platform.OS !== 'android' ? this._onScroll : null}
408408
onResponderRelease={this.props.refreshable === true && Platform.OS !== 'android' ? this._onResponderRelease : null}
409409

410410
scrollEventThrottle={200}
411-
411+
412412
contentInset={this._calculateContentInset()}
413413
contentOffset={this._calculateContentOffset()}
414-
414+
415415
automaticallyAdjustContentInsets={false}
416416
scrollEnabled={true}
417417
canCancelContentTouches={true}
418-
418+
419419
renderSeparator={this.renderSeparator}
420-
420+
421421
{...this.props}
422-
422+
423423
style={[this.props.style, style]}
424424
/>
425425
);
@@ -433,7 +433,7 @@ var GiftedListView = React.createClass({
433433
onRefresh={this._onRefresh}
434434

435435
{...this.props.PullToRefreshViewAndroidProps}
436-
436+
437437
style={[this.props.PullToRefreshViewAndroidProps.style, {flex: 1}]}
438438
>
439439
{this.renderListView({flex: 1})}
@@ -443,7 +443,7 @@ var GiftedListView = React.createClass({
443443
return this.renderListView();
444444
}
445445
},
446-
446+
447447
defaultStyles: {
448448
separator: {
449449
height: 1,

0 commit comments

Comments
 (0)