@@ -24,6 +24,7 @@ export default class SortableList extends Component {
24
24
refreshControl : PropTypes . element ,
25
25
26
26
renderRow : PropTypes . func . isRequired ,
27
+ renderFooter : PropTypes . func ,
27
28
28
29
onChangeOrder : PropTypes . func ,
29
30
onActivateRow : PropTypes . func ,
@@ -47,6 +48,8 @@ export default class SortableList extends Component {
47
48
*/
48
49
_rowsLayouts = [ ] ;
49
50
51
+ _footerLayout = null ;
52
+
50
53
_contentOffset = { x : 0 , y : 0 } ;
51
54
52
55
state = {
@@ -63,7 +66,7 @@ export default class SortableList extends Component {
63
66
} ;
64
67
65
68
componentDidMount ( ) {
66
- this . _onLayoutRows ( ) ;
69
+ this . _onUpdateLayouts ( ) ;
67
70
}
68
71
69
72
componentWillReceiveProps ( nextProps ) {
@@ -91,7 +94,7 @@ export default class SortableList extends Component {
91
94
const { data : prevData } = prevState ;
92
95
93
96
if ( data && prevData && ! shallowEqual ( data , prevData ) ) {
94
- this . _onLayoutRows ( ) ;
97
+ this . _onUpdateLayouts ( ) ;
95
98
}
96
99
}
97
100
@@ -178,6 +181,7 @@ export default class SortableList extends Component {
178
181
< View style = { innerContainerStyle } >
179
182
{ this . _renderRows ( ) }
180
183
</ View >
184
+ { this . _renderFooter ( ) }
181
185
</ ScrollView >
182
186
</ View >
183
187
) ;
@@ -252,9 +256,28 @@ export default class SortableList extends Component {
252
256
} ) ;
253
257
}
254
258
255
- _onLayoutRows ( ) {
256
- Promise . all ( [ ...this . _rowsLayouts ] )
257
- . then ( ( rowsLayouts ) => {
259
+ _renderFooter ( ) {
260
+ if ( ! this . props . renderFooter || this . props . horizontal ) {
261
+ return null ;
262
+ }
263
+
264
+ const { footerLayout} = this . state ;
265
+ let resolveLayout ;
266
+
267
+ if ( ! footerLayout ) {
268
+ this . _footerLayout = new Promise ( ( resolve ) => ( resolveLayout = resolve ) ) ;
269
+ }
270
+
271
+ return (
272
+ < View onLayout = { ! footerLayout ? this . _onLayoutFooter . bind ( this , resolveLayout ) : null } >
273
+ { this . props . renderFooter ( ) }
274
+ </ View >
275
+ ) ;
276
+ }
277
+
278
+ _onUpdateLayouts ( ) {
279
+ Promise . all ( [ this . _footerLayout , ...this . _rowsLayouts ] )
280
+ . then ( ( [ footerLayout , ...rowsLayouts ] ) => {
258
281
// Can get correct container’s layout only after rows’s layouts.
259
282
this . _container . measure ( ( x , y , width , height , pageX , pageY ) => {
260
283
const rowsLayoutsByKey = { } ;
@@ -270,6 +293,7 @@ export default class SortableList extends Component {
270
293
this . setState ( {
271
294
containerLayout : { x, y, width, height, pageX, pageY} ,
272
295
rowsLayouts : rowsLayoutsByKey ,
296
+ footerLayout,
273
297
contentHeight,
274
298
contentWidth,
275
299
} , ( ) => {
@@ -421,25 +445,37 @@ export default class SortableList extends Component {
421
445
this . _startAutoScroll ( {
422
446
direction : 1 ,
423
447
shouldScroll : ( ) => {
424
- const { contentHeight, contentWidth, containerLayout} = this . state ;
448
+ const {
449
+ contentHeight,
450
+ contentWidth,
451
+ containerLayout,
452
+ footerLayout = { height : 0 } ,
453
+ } = this . state ;
425
454
426
455
if ( horizontal ) {
427
456
return this . _contentOffset . x < contentWidth - containerLayout . width
428
457
} else {
429
- return this . _contentOffset . y < contentHeight - containerLayout . height ;
458
+ return this . _contentOffset . y < contentHeight + footerLayout . height - containerLayout . height ;
430
459
}
431
460
} ,
432
461
getScrollStep : ( stepIndex ) => {
433
462
const nextStep = this . _getScrollStep ( stepIndex ) ;
434
- const { contentHeight, contentWidth, containerLayout} = this . state ;
463
+ const {
464
+ contentHeight,
465
+ contentWidth,
466
+ containerLayout,
467
+ footerLayout = { height : 0 } ,
468
+ } = this . state ;
435
469
436
470
if ( horizontal ) {
437
471
return this . _contentOffset . x + nextStep > contentWidth - containerLayout . width
438
472
? contentWidth - containerLayout . width - this . _contentOffset . x
439
473
: nextStep ;
440
474
} else {
441
- return this . _contentOffset . y + nextStep > contentHeight - containerLayout . height
442
- ? contentHeight - containerLayout . height - this . _contentOffset . y
475
+ const scrollHeight = contentHeight + footerLayout . height - containerLayout . height ;
476
+
477
+ return this . _contentOffset . y + nextStep > scrollHeight
478
+ ? scrollHeight - this . _contentOffset . y
443
479
: nextStep ;
444
480
}
445
481
} ,
@@ -483,6 +519,10 @@ export default class SortableList extends Component {
483
519
resolveLayout ( { rowKey, layout} ) ;
484
520
}
485
521
522
+ _onLayoutFooter ( resolveLayout , { nativeEvent : { layout} } ) {
523
+ resolveLayout ( layout ) ;
524
+ }
525
+
486
526
_onActivateRow = ( rowKey , index , e , gestureState , location ) => {
487
527
this . _activeRowLocation = location ;
488
528
0 commit comments