@@ -14,6 +14,7 @@ const React = require('React');
14
14
const View = require ( 'View' ) ;
15
15
const VirtualizedList = require ( 'VirtualizedList' ) ;
16
16
const ListView = require ( 'ListView' ) ;
17
+ const StyleSheet = require ( 'StyleSheet' ) ;
17
18
18
19
const invariant = require ( 'fbjs/lib/invariant' ) ;
19
20
@@ -421,41 +422,15 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
421
422
}
422
423
}
423
424
424
- setNativeProps ( props : Object ) {
425
+ setNativeProps ( props : { [ string ] : mixed } ) {
425
426
if ( this . _listRef ) {
426
427
this . _listRef . setNativeProps ( props ) ;
427
428
}
428
429
}
429
430
430
- UNSAFE_componentWillMount ( ) {
431
- this . _checkProps ( this . props ) ;
432
- }
433
-
434
- UNSAFE_componentWillReceiveProps(nextProps: Props< ItemT > ) {
435
- invariant (
436
- nextProps . numColumns === this . props . numColumns ,
437
- 'Changing numColumns on the fly is not supported. Change the key prop on FlatList when ' +
438
- 'changing the number of columns to force a fresh render of the component.' ,
439
- ) ;
440
- invariant (
441
- nextProps . onViewableItemsChanged === this . props . onViewableItemsChanged ,
442
- 'Changing onViewableItemsChanged on the fly is not supported' ,
443
- ) ;
444
- invariant (
445
- nextProps . viewabilityConfig === this . props . viewabilityConfig ,
446
- 'Changing viewabilityConfig on the fly is not supported' ,
447
- ) ;
448
- invariant (
449
- nextProps . viewabilityConfigCallbackPairs ===
450
- this . props . viewabilityConfigCallbackPairs ,
451
- 'Changing viewabilityConfigCallbackPairs on the fly is not supported' ,
452
- ) ;
453
-
454
- this . _checkProps ( nextProps ) ;
455
- }
456
-
457
- constructor(props: Props< * > ) {
431
+ constructor ( props : Props < ItemT > ) {
458
432
super ( props ) ;
433
+ this . _checkProps ( this . props ) ;
459
434
if ( this . props . viewabilityConfigCallbackPairs ) {
460
435
this . _virtualizedListPairs = this . props . viewabilityConfigCallbackPairs . map (
461
436
pair => ( {
@@ -478,6 +453,29 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
478
453
}
479
454
}
480
455
456
+ componentDidUpdate ( prevProps : Props < ItemT > ) {
457
+ invariant (
458
+ prevProps . numColumns === this . props . numColumns ,
459
+ 'Changing numColumns on the fly is not supported. Change the key prop on FlatList when ' +
460
+ 'changing the number of columns to force a fresh render of the component.' ,
461
+ ) ;
462
+ invariant (
463
+ prevProps . onViewableItemsChanged === this . props . onViewableItemsChanged ,
464
+ 'Changing onViewableItemsChanged on the fly is not supported' ,
465
+ ) ;
466
+ invariant (
467
+ prevProps . viewabilityConfig === this . props . viewabilityConfig ,
468
+ 'Changing viewabilityConfig on the fly is not supported' ,
469
+ ) ;
470
+ invariant (
471
+ prevProps . viewabilityConfigCallbackPairs ===
472
+ this . props . viewabilityConfigCallbackPairs ,
473
+ 'Changing viewabilityConfigCallbackPairs on the fly is not supported' ,
474
+ ) ;
475
+
476
+ this . _checkProps ( this . props ) ;
477
+ }
478
+
481
479
_hasWarnedLegacy = false;
482
480
_listRef: null | VirtualizedList | ListView | MetroListView;
483
481
_virtualizedListPairs: Array< ViewabilityConfigCallbackPair > = [];
@@ -537,7 +535,9 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
537
535
const ret = [ ] ;
538
536
for ( let kk = 0 ; kk < numColumns ; kk ++ ) {
539
537
const item = data [ index * numColumns + kk ] ;
540
- item && ret . push ( item ) ;
538
+ if ( item != null ) {
539
+ ret . push ( item ) ;
540
+ }
541
541
}
542
542
return ret ;
543
543
} else {
@@ -614,7 +614,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
614
614
'Expected array of items with numColumns > 1' ,
615
615
) ;
616
616
return (
617
- < View style = { [ { flexDirection : ' row' } , columnWrapperStyle ] } >
617
+ < View style = { StyleSheet . compose ( styles . row , columnWrapperStyle ) } >
618
618
{ item . map ( ( it , kk ) => {
619
619
const element = renderItem ( {
620
620
item : it ,
@@ -661,4 +661,8 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
661
661
}
662
662
}
663
663
664
+ const styles = StyleSheet . create ( {
665
+ row : { flexDirection : 'row' } ,
666
+ } ) ;
667
+
664
668
module . exports = FlatList ;
0 commit comments