@@ -31,7 +31,7 @@ function MergeRecursive(obj1, obj2) {
31
31
var GiftedSpinner = require ( 'react-native-gifted-spinner' ) ;
32
32
33
33
var GiftedListView = React . createClass ( {
34
-
34
+
35
35
getDefaultProps ( ) {
36
36
return {
37
37
customStyles : { } ,
@@ -44,8 +44,9 @@ var GiftedListView = React.createClass({
44
44
headerView : null ,
45
45
sectionHeaderView : null ,
46
46
withSections : false ,
47
+ autoPaginate : false ,
47
48
onFetch ( page , callback , options ) { callback ( [ ] ) ; } ,
48
-
49
+
49
50
paginationFetchigView : null ,
50
51
paginationAllLoadedView : null ,
51
52
paginationWaitingView : null ,
@@ -60,7 +61,7 @@ var GiftedListView = React.createClass({
60
61
} ,
61
62
} ;
62
63
} ,
63
-
64
+
64
65
propTypes : {
65
66
customStyles : React . PropTypes . object ,
66
67
initialListSize : React . PropTypes . number ,
@@ -72,8 +73,9 @@ var GiftedListView = React.createClass({
72
73
headerView : React . PropTypes . func ,
73
74
sectionHeaderView : React . PropTypes . func ,
74
75
withSections : React . PropTypes . bool ,
76
+ autoPaginate : React . PropTypes . bool ,
75
77
onFetch : React . PropTypes . func ,
76
-
78
+
77
79
paginationFetchigView : React . PropTypes . func ,
78
80
paginationAllLoadedView : React . PropTypes . func ,
79
81
paginationWaitingView : React . PropTypes . func ,
@@ -84,20 +86,20 @@ var GiftedListView = React.createClass({
84
86
renderSeparator : React . PropTypes . func ,
85
87
PullToRefreshViewAndroidProps : React . PropTypes . object ,
86
88
} ,
87
-
89
+
88
90
_setY ( y ) { this . _y = y ; } ,
89
91
_getY ( y ) { return this . _y ; } ,
90
92
_setPage ( page ) { this . _page = page ; } ,
91
93
_getPage ( ) { return this . _page ; } ,
92
94
_setRows ( rows ) { this . _rows = rows ; } ,
93
95
_getRows ( ) { return this . _rows ; } ,
94
-
95
-
96
+
97
+
96
98
paginationFetchigView ( ) {
97
99
if ( this . props . paginationFetchigView ) {
98
100
return this . props . paginationFetchigView ( ) ;
99
101
}
100
-
102
+
101
103
return (
102
104
< View style = { [ this . defaultStyles . paginationView , this . props . customStyles . paginationView ] } >
103
105
< GiftedSpinner />
@@ -108,7 +110,7 @@ var GiftedListView = React.createClass({
108
110
if ( this . props . paginationAllLoadedView ) {
109
111
return this . props . paginationAllLoadedView ( ) ;
110
112
}
111
-
113
+
112
114
return (
113
115
< View style = { [ this . defaultStyles . paginationView , this . props . customStyles . paginationView ] } >
114
116
< Text style = { [ this . defaultStyles . actionsLabel , this . props . customStyles . actionsLabel ] } >
@@ -121,9 +123,9 @@ var GiftedListView = React.createClass({
121
123
if ( this . props . paginationWaitingView ) {
122
124
return this . props . paginationWaitingView ( paginateCallback ) ;
123
125
}
124
-
126
+
125
127
return (
126
- < TouchableHighlight
128
+ < TouchableHighlight
127
129
underlayColor = '#c8c7cc'
128
130
onPress = { paginateCallback }
129
131
style = { [ this . defaultStyles . paginationView , this . props . customStyles . paginationView ] }
@@ -157,7 +159,7 @@ var GiftedListView = React.createClass({
157
159
if ( this . props . refreshableWillRefreshView ) {
158
160
return this . props . refreshableWillRefreshView ( ) ;
159
161
}
160
-
162
+
161
163
return (
162
164
< View >
163
165
< View style = { [ this . defaultStyles . refreshableView , this . props . customStyles . refreshableView ] } >
@@ -173,7 +175,7 @@ var GiftedListView = React.createClass({
173
175
if ( this . props . refreshableWaitingView ) {
174
176
return this . props . refreshableWaitingView ( refreshCallback ) ;
175
177
}
176
-
178
+
177
179
return (
178
180
< View >
179
181
< View style = { [ this . defaultStyles . refreshableView , this . props . customStyles . refreshableView ] } >
@@ -189,14 +191,14 @@ var GiftedListView = React.createClass({
189
191
if ( this . props . emptyView ) {
190
192
return this . props . emptyView ( refreshCallback ) ;
191
193
}
192
-
194
+
193
195
return (
194
196
< View style = { [ this . defaultStyles . defaultView , this . props . customStyles . defaultView ] } >
195
197
< Text style = { [ this . defaultStyles . defaultViewTitle , this . props . customStyles . defaultViewTitle ] } >
196
198
Sorry, there is no content to display
197
199
</ Text >
198
-
199
- < TouchableHighlight
200
+
201
+ < TouchableHighlight
200
202
underlayColor = '#c8c7cc'
201
203
onPress = { refreshCallback }
202
204
>
@@ -211,12 +213,20 @@ var GiftedListView = React.createClass({
211
213
if ( this . props . renderSeparator ) {
212
214
return this . props . renderSeparator ( ) ;
213
215
}
214
-
216
+
215
217
return (
216
218
< View style = { [ this . defaultStyles . separator , this . props . customStyles . separator ] } />
217
219
) ;
218
220
} ,
219
-
221
+ onEndReached ( ) {
222
+ if ( this . props . autoPaginate ) {
223
+ this . _onPaginate ( ) ;
224
+ }
225
+ if ( this . props . onEndReached ) {
226
+ this . props . onEndReached ( ) ;
227
+ }
228
+ } ,
229
+
220
230
getInitialState ( ) {
221
231
222
232
if ( this . props . refreshable === true && Platform . OS !== 'android' ) {
@@ -243,7 +253,7 @@ var GiftedListView = React.createClass({
243
253
} else {
244
254
ds = new ListView . DataSource ( {
245
255
rowHasChanged : ( row1 , row2 ) => row1 !== row2 ,
246
- } ) ;
256
+ } ) ;
247
257
return {
248
258
dataSource : ds . cloneWithRows ( this . _getRows ( ) ) ,
249
259
refreshStatus : 'waiting' ,
@@ -265,7 +275,7 @@ var GiftedListView = React.createClass({
265
275
_refresh ( ) {
266
276
this . _onRefresh ( { external : true } ) ;
267
277
} ,
268
-
278
+
269
279
_onRefresh ( options = { } ) {
270
280
this . _scrollResponder . scrollTo ( 0 ) ;
271
281
this . setState ( {
@@ -275,23 +285,26 @@ var GiftedListView = React.createClass({
275
285
this . _setPage ( 1 ) ;
276
286
this . props . onFetch ( this . _getPage ( ) , this . _postRefresh , options ) ;
277
287
} ,
278
-
288
+
279
289
_postRefresh ( rows = [ ] , options = { } ) {
280
290
this . _updateRows ( rows , options ) ;
281
291
if ( this . props . refreshable === true ) {
282
292
// @issue
283
293
// if a scrolling is already in progress, this scroll will not be executed
284
- this . _scrollResponder . scrollTo ( this . props . refreshableViewHeight ) ;
294
+ this . _scrollResponder . scrollTo ( this . props . refreshableViewHeight ) ;
285
295
}
286
296
} ,
287
-
297
+
288
298
_onPaginate ( ) {
289
- this . setState ( {
290
- paginationStatus : 'fetching' ,
291
- } ) ;
292
- this . props . onFetch ( this . _getPage ( ) + 1 , this . _postPaginate , { } ) ;
299
+ if ( this . state . paginationStatus === 'firstLoad'
300
+ || this . state . paginationStatus === 'waiting' ) {
301
+ this . setState ( {
302
+ paginationStatus : 'fetching' ,
303
+ } ) ;
304
+ this . props . onFetch ( this . _getPage ( ) + 1 , this . _postPaginate , { } ) ;
305
+ }
293
306
} ,
294
-
307
+
295
308
_postPaginate ( rows = [ ] , options = { } ) {
296
309
this . _setPage ( this . _getPage ( ) + 1 ) ;
297
310
var mergedRows = null ;
@@ -302,7 +315,7 @@ var GiftedListView = React.createClass({
302
315
}
303
316
this . _updateRows ( mergedRows , options ) ;
304
317
} ,
305
-
318
+
306
319
_updateRows ( rows = [ ] , options = { } ) {
307
320
this . _setRows ( rows ) ;
308
321
if ( this . props . withSections === true ) {
@@ -318,10 +331,10 @@ var GiftedListView = React.createClass({
318
331
refreshStatus : 'waiting' ,
319
332
isRefreshing : false ,
320
333
paginationStatus : ( options . allLoaded === true ? 'allLoaded' : 'waiting' ) ,
321
- } ) ;
334
+ } ) ;
322
335
}
323
336
} ,
324
-
337
+
325
338
_onResponderRelease ( ) {
326
339
if ( this . props . refreshable === true ) {
327
340
if ( Platform . OS !== 'android' ) {
@@ -331,12 +344,12 @@ var GiftedListView = React.createClass({
331
344
}
332
345
}
333
346
} ,
334
-
347
+
335
348
_onScroll ( e ) {
336
349
this . _setY ( e . nativeEvent . contentOffset . y ) ;
337
350
if ( this . props . refreshable === true ) {
338
351
if ( Platform . OS !== 'android' ) {
339
- if ( this . _getY ( ) < this . props . refreshableViewHeight - this . props . refreshableDistance
352
+ if ( this . _getY ( ) < this . props . refreshableViewHeight - this . props . refreshableDistance
340
353
&& this . state . refreshStatus === 'waiting'
341
354
&& this . _scrollResponder . scrollResponderHandleScrollShouldSetResponder ( ) === true
342
355
) {
@@ -348,7 +361,7 @@ var GiftedListView = React.createClass({
348
361
}
349
362
}
350
363
} ,
351
-
364
+
352
365
_renderRefreshView ( ) {
353
366
switch ( this . state . refreshStatus ) {
354
367
case 'fetching' :
@@ -361,7 +374,7 @@ var GiftedListView = React.createClass({
361
374
return this . refreshableWaitingView ( this . _onRefresh ) ;
362
375
}
363
376
} ,
364
-
377
+
365
378
_renderPaginationView ( ) {
366
379
if ( ( this . state . paginationStatus === 'fetching' && this . props . pagination === true ) || ( this . state . paginationStatus === 'firstLoad' && this . props . firstLoader === true ) ) {
367
380
return this . paginationFetchigView ( ) ;
@@ -383,16 +396,16 @@ var GiftedListView = React.createClass({
383
396
return { top : 0 , bottom : 0 , left : 0 , right : 0 } ;
384
397
}
385
398
} ,
386
-
399
+
387
400
_calculateContentOffset ( ) {
388
401
if ( this . props . refreshable === true && Platform . OS !== 'android' ) {
389
402
return { x : 0 , y : this . props . refreshableViewHeight } ;
390
403
} else {
391
404
return { x : 0 , y : 0 } ;
392
405
}
393
406
} ,
394
-
395
-
407
+
408
+
396
409
renderListView ( style = { } ) {
397
410
return (
398
411
< ListView
@@ -403,23 +416,25 @@ var GiftedListView = React.createClass({
403
416
404
417
renderHeader = { this . props . refreshable === true && Platform . OS !== 'android' ? this . _renderRefreshView : this . headerView }
405
418
renderFooter = { this . _renderPaginationView }
406
-
419
+
407
420
onScroll = { this . props . refreshable === true && Platform . OS !== 'android' ? this . _onScroll : null }
408
421
onResponderRelease = { this . props . refreshable === true && Platform . OS !== 'android' ? this . _onResponderRelease : null }
409
422
410
423
scrollEventThrottle = { 200 }
411
-
424
+
412
425
contentInset = { this . _calculateContentInset ( ) }
413
426
contentOffset = { this . _calculateContentOffset ( ) }
414
-
427
+
415
428
automaticallyAdjustContentInsets = { false }
416
429
scrollEnabled = { true }
417
430
canCancelContentTouches = { true }
418
-
431
+
419
432
renderSeparator = { this . renderSeparator }
420
-
433
+
434
+ onEndReached = { this . onEndReached }
435
+
421
436
{ ...this . props }
422
-
437
+
423
438
style = { [ this . props . style , style ] }
424
439
/>
425
440
) ;
@@ -433,7 +448,7 @@ var GiftedListView = React.createClass({
433
448
onRefresh = { this . _onRefresh }
434
449
435
450
{ ...this . props . PullToRefreshViewAndroidProps }
436
-
451
+
437
452
style = { [ this . props . PullToRefreshViewAndroidProps . style , { flex : 1 } ] }
438
453
>
439
454
{ this . renderListView ( { flex : 1 } ) }
@@ -443,7 +458,7 @@ var GiftedListView = React.createClass({
443
458
return this . renderListView ( ) ;
444
459
}
445
460
} ,
446
-
461
+
447
462
defaultStyles : {
448
463
separator : {
449
464
height : 1 ,
0 commit comments