@@ -14,6 +14,7 @@ const React = require('React');
1414const View = require ( 'View' ) ;
1515const VirtualizedList = require ( 'VirtualizedList' ) ;
1616const ListView = require ( 'ListView' ) ;
17+ const StyleSheet = require ( 'StyleSheet' ) ;
1718
1819const invariant = require ( 'fbjs/lib/invariant' ) ;
1920
@@ -421,41 +422,15 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
421422 }
422423 }
423424
424- setNativeProps ( props : Object ) {
425+ setNativeProps ( props : { [ string ] : mixed } ) {
425426 if ( this . _listRef ) {
426427 this . _listRef . setNativeProps ( props ) ;
427428 }
428429 }
429430
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 > ) {
458432 super ( props ) ;
433+ this . _checkProps ( this . props ) ;
459434 if ( this . props . viewabilityConfigCallbackPairs ) {
460435 this . _virtualizedListPairs = this . props . viewabilityConfigCallbackPairs . map (
461436 pair => ( {
@@ -478,6 +453,29 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
478453 }
479454 }
480455
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+
481479 _hasWarnedLegacy = false;
482480 _listRef: null | VirtualizedList | ListView | MetroListView;
483481 _virtualizedListPairs: Array< ViewabilityConfigCallbackPair > = [];
@@ -537,7 +535,9 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
537535 const ret = [ ] ;
538536 for ( let kk = 0 ; kk < numColumns ; kk ++ ) {
539537 const item = data [ index * numColumns + kk ] ;
540- item && ret . push ( item ) ;
538+ if ( item != null ) {
539+ ret . push ( item ) ;
540+ }
541541 }
542542 return ret ;
543543 } else {
@@ -614,7 +614,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
614614 'Expected array of items with numColumns > 1' ,
615615 ) ;
616616 return (
617- < View style = { [ { flexDirection : ' row' } , columnWrapperStyle ] } >
617+ < View style = { StyleSheet . compose ( styles . row , columnWrapperStyle ) } >
618618 { item . map ( ( it , kk ) => {
619619 const element = renderItem ( {
620620 item : it ,
@@ -661,4 +661,8 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
661661 }
662662}
663663
664+ const styles = StyleSheet . create ( {
665+ row : { flexDirection : 'row' } ,
666+ } ) ;
667+
664668module . exports = FlatList ;
0 commit comments