88 *
99 * @providesModule FlatList
1010 * @flow
11+ * @format
1112 */
1213'use strict' ;
1314
@@ -109,8 +110,10 @@ type OptionalProps<ItemT> = {
109110 * Remember to include separator length (height or width) in your offset calculation if you
110111 * specify `ItemSeparatorComponent`.
111112 */
112- getItemLayout ?: ( data : ?Array < ItemT > , index : number ) =>
113- { length : number , offset : number , index : number } ,
113+ getItemLayout ?: (
114+ data : ?Array < ItemT > ,
115+ index : number ,
116+ ) => { length : number , offset : number , index : number } ,
114117 /**
115118 * If true, renders items next to each other horizontally instead of stacked vertically.
116119 */
@@ -184,7 +187,9 @@ type OptionalProps<ItemT> = {
184187 */
185188 viewabilityConfig ?: ViewabilityConfig ,
186189} ;
187- type Props < ItemT > = RequiredProps < ItemT > & OptionalProps < ItemT > & VirtualizedListProps ;
190+ type Props < ItemT > = RequiredProps < ItemT > &
191+ OptionalProps < ItemT > &
192+ VirtualizedListProps ;
188193
189194const defaultProps = {
190195 ...VirtualizedList . defaultProps ,
@@ -295,7 +300,8 @@ type DefaultProps = typeof defaultProps;
295300 * Alternatively, you can provide a custom `keyExtractor` prop.
296301 *
297302 */
298- class FlatList < ItemT > extends React.PureComponent< DefaultProps , Props < ItemT > , void> {
303+ class FlatList < ItemT >
304+ extends React.PureComponent< DefaultProps , Props < ItemT > , void> {
299305 static defaultProps : DefaultProps = defaultProps ;
300306 props : Props < ItemT > ;
301307 /**
@@ -314,7 +320,10 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
314320 * `getItemLayout` prop.
315321 */
316322 scrollToIndex(params: {
317- animated ?: ?boolean , index : number , viewOffset ? : number , viewPosition ? : number ,
323+ animated ?: ?boolean ,
324+ index : number ,
325+ viewOffset ? : number ,
326+ viewPosition ? : number ,
318327 } ) {
319328 this . _listRef . scrollToIndex ( params ) ;
320329 }
@@ -325,7 +334,11 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
325334 * Note: cannot scroll to locations outside the render window without specifying the
326335 * `getItemLayout` prop.
327336 */
328- scrollToItem(params: { animated ?: ?boolean , item : ItemT , viewPosition ? : number } ) {
337+ scrollToItem(params: {
338+ animated ?: ?boolean ,
339+ item : ItemT ,
340+ viewPosition ? : number ,
341+ } ) {
329342 this . _listRef . scrollToItem ( params ) ;
330343 }
331344
@@ -379,15 +392,17 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
379392 invariant (
380393 nextProps . numColumns === this . props . numColumns ,
381394 'Changing numColumns on the fly is not supported. Change the key prop on FlatList when ' +
382- 'changing the number of columns to force a fresh render of the component.'
395+ 'changing the number of columns to force a fresh render of the component.' ,
383396 ) ;
384397 this . _checkProps ( nextProps ) ;
385398 }
386399
387400 _hasWarnedLegacy = false;
388401 _listRef: VirtualizedList;
389402
390- _captureRef = (ref) => { this . _listRef = ref ; } ;
403+ _captureRef = ref => {
404+ this . _listRef = ref ;
405+ } ;
391406
392407 _checkProps(props: Props< ItemT > ) {
393408 const {
@@ -398,20 +413,29 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
398413 numColumns,
399414 columnWrapperStyle,
400415 } = props ;
401- invariant ( ! getItem && ! getItemCount , 'FlatList does not support custom data formats.' ) ;
416+ invariant (
417+ ! getItem && ! getItemCount ,
418+ 'FlatList does not support custom data formats.' ,
419+ ) ;
402420 if ( numColumns > 1 ) {
403421 invariant ( ! horizontal , 'numColumns does not support horizontal.' ) ;
404422 } else {
405- invariant ( ! columnWrapperStyle , 'columnWrapperStyle not supported for single column lists' ) ;
423+ invariant (
424+ ! columnWrapperStyle ,
425+ 'columnWrapperStyle not supported for single column lists' ,
426+ ) ;
406427 }
407428 if (legacyImplementation) {
408- invariant ( numColumns === 1 , 'Legacy list does not support multiple columns.' ) ;
429+ invariant (
430+ numColumns === 1 ,
431+ 'Legacy list does not support multiple columns.' ,
432+ ) ;
409433 // Warning: may not have full feature parity and is meant more for debugging and performance
410434 // comparison.
411435 if ( ! this . _hasWarnedLegacy ) {
412436 console . warn (
413437 'FlatList: Using legacyImplementation - some features not supported and performance ' +
414- 'may suffer'
438+ 'may suffer' ,
415439 ) ;
416440 this . _hasWarnedLegacy = true ;
417441 }
@@ -442,10 +466,12 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
442466 invariant (
443467 Array . isArray ( items ) ,
444468 'FlatList: Encountered internal consistency error, expected each item to consist of an ' +
445- 'array with 1-%s columns; instead, received a single item.' ,
469+ 'array with 1-%s columns; instead, received a single item.' ,
446470 numColumns ,
447471 ) ;
448- return items . map ( ( it , kk ) => keyExtractor ( it , index * numColumns + kk ) ) . join ( ':' ) ;
472+ return items
473+ . map ( ( it , kk ) => keyExtractor ( it , index * numColumns + kk ) )
474+ . join ( ':' ) ;
449475 } else {
450476 return keyExtractor ( items , index ) ;
451477 }
@@ -460,16 +486,18 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
460486 } ) ;
461487 }
462488
463- _onViewableItemsChanged = ( info ) => {
489+ _onViewableItemsChanged = info => {
464490 const { numColumns, onViewableItemsChanged} = this . props ;
465491 if ( ! onViewableItemsChanged ) {
466492 return ;
467493 }
468494 if ( numColumns > 1 ) {
469495 const changed = [ ] ;
470496 const viewableItems = [ ] ;
471- info . viewableItems . forEach ( ( v ) => this . _pushMultiColumnViewable ( viewableItems , v ) ) ;
472- info . changed . forEach ( ( v ) => this . _pushMultiColumnViewable ( changed , v ) ) ;
497+ info . viewableItems . forEach ( v =>
498+ this . _pushMultiColumnViewable ( viewableItems , v ) ,
499+ ) ;
500+ info . changed . forEach ( v => this . _pushMultiColumnViewable ( changed , v ) ) ;
473501 onViewableItemsChanged ( { viewableItems, changed} ) ;
474502 } else {
475503 onViewableItemsChanged ( info ) ;
@@ -480,7 +508,10 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
480508 const { renderItem, numColumns, columnWrapperStyle} = this . props ;
481509 if ( numColumns > 1 ) {
482510 const { item, index} = info ;
483- invariant ( Array . isArray ( item ) , 'Expected array of items with numColumns > 1' ) ;
511+ invariant (
512+ Array . isArray ( item ) ,
513+ 'Expected array of items with numColumns > 1' ,
514+ ) ;
484515 return (
485516 < View style = { [ { flexDirection : 'row' } , columnWrapperStyle ] } >
486517 { item . map ( ( it , kk ) => {
@@ -500,7 +531,13 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
500531
501532 render ( ) {
502533 if ( this . props . legacyImplementation ) {
503- return < MetroListView { ...this . props } items = { this . props . data } ref = { this . _captureRef } /> ;
534+ return (
535+ < MetroListView
536+ { ...this . props }
537+ items = { this . props . data }
538+ ref = { this . _captureRef }
539+ />
540+ ) ;
504541 } else {
505542 return (
506543 < VirtualizedList
@@ -510,7 +547,9 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
510547 getItemCount = { this . _getItemCount }
511548 keyExtractor = { this . _keyExtractor }
512549 ref = { this . _captureRef }
513- onViewableItemsChanged = { this . props . onViewableItemsChanged && this . _onViewableItemsChanged }
550+ onViewableItemsChanged = {
551+ this . props . onViewableItemsChanged && this . _onViewableItemsChanged
552+ }
514553 />
515554 ) ;
516555 }
0 commit comments