@@ -16,6 +16,7 @@ const ScrollView = require('../Components/ScrollView/ScrollView');
1616const  StyleSheet  =  require ( '../StyleSheet/StyleSheet' ) ; 
1717const  View  =  require ( '../Components/View/View' ) ; 
1818const  ViewabilityHelper  =  require ( './ViewabilityHelper' ) ; 
19+ import  VirtualizedListInjection  from  './VirtualizedListInjection' ; 
1920
2021const  flattenStyle  =  require ( '../StyleSheet/flattenStyle' ) ; 
2122const  infoLog  =  require ( '../Utilities/infoLog' ) ; 
@@ -221,6 +222,7 @@ type OptionalProps = {|
221222   * within half the visible length of the list. 
222223   */ 
223224  onEndReachedThreshold ?: ?number , 
225+   onLayout ?: ?( e : LayoutEvent )  =>  void , 
224226  /** 
225227   * If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make 
226228   * sure to also set the `refreshing` prop correctly. 
@@ -810,27 +812,45 @@ class VirtualizedList extends React.PureComponent<Props, State> {
810812      if  ( stickyIndicesFromProps . has ( ii  +  stickyOffset ) )  { 
811813        stickyHeaderIndices . push ( cells . length ) ; 
812814      } 
813-       cells . push ( 
814-         < CellRenderer 
815-           CellRendererComponent = { CellRendererComponent } 
816-           ItemSeparatorComponent = { ii  <  end  ? ItemSeparatorComponent  : undefined } 
817-           cellKey = { key } 
818-           fillRateHelper = { this . _fillRateHelper } 
819-           horizontal = { horizontal } 
820-           index = { ii } 
821-           inversionStyle = { inversionStyle } 
822-           item = { item } 
823-           key = { key } 
824-           prevCellKey = { prevCellKey } 
825-           onUpdateSeparators = { this . _onUpdateSeparators } 
826-           onLayout = { e  =>  this . _onCellLayout ( e ,  key ,  ii ) } 
827-           onUnmount = { this . _onCellUnmount } 
828-           parentProps = { this . props } 
829-           ref = { ref  =>  { 
830-             this . _cellRefs [ key ]  =  ref ; 
831-           } } 
832-         /> , 
833-       ) ; 
815+       const  cellRendererBaseProps : CellRendererBaseProps  =  { 
816+         CellRendererComponent : CellRendererComponent , 
817+         ItemSeparatorComponent : ii  <  end  ? ItemSeparatorComponent  : undefined , 
818+         cellKey : key , 
819+         fillRateHelper : this . _fillRateHelper , 
820+         horizontal : horizontal , 
821+         index : ii , 
822+         inversionStyle : inversionStyle , 
823+         item : item , 
824+         key : key , 
825+         prevCellKey : prevCellKey , 
826+         onUpdateSeparators : this . _onUpdateSeparators , 
827+         onUnmount : this . _onCellUnmount , 
828+         extraData : extraData , 
829+         ref : ref  =>  { 
830+           this . _cellRefs [ key ]  =  ref ; 
831+         } , 
832+       } ; 
833+       if  ( VirtualizedListInjection . useVLOptimization )  { 
834+         cells . push ( 
835+           < CellRenderer 
836+             { ...cellRendererBaseProps } 
837+             onLayout = { this . _onCellLayout } 
838+             getItemLayout = { getItemLayout } 
839+             renderItem = { renderItem } 
840+             ListItemComponent = { ListItemComponent } 
841+             debug = { debug } 
842+           /> , 
843+         ) ; 
844+       }  else  { 
845+         cells . push ( 
846+           < CellRenderer 
847+             { ...cellRendererBaseProps } 
848+             experimentalVirtualizedListOpt = { false } 
849+             onLayout = { e  =>  this . _onCellLayout ( e ,  key ,  ii ) } 
850+             parentProps = { this . props } 
851+           /> , 
852+         ) ; 
853+       } 
834854      prevCellKey  =  key ; 
835855    } 
836856  } 
@@ -1269,7 +1289,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
12691289    } 
12701290  } ; 
12711291
1272-   _onCellLayout ( e ,  cellKey ,  index )  { 
1292+   _onCellLayout   =   ( e ,  cellKey ,  index ) :  void   =>  { 
12731293    const  layout  =  e . nativeEvent . layout ; 
12741294    const  next  =  { 
12751295      offset : this . _selectOffset ( layout ) , 
@@ -1302,7 +1322,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
13021322
13031323    this._computeBlankness();
13041324    this._updateViewableItems(this.props.data);
1305-   } 
1325+   } ; 
13061326
13071327  _onCellUnmount  =  ( cellKey : string )  =>  { 
13081328    const  curr  =  this . _frames [ cellKey ] ; 
@@ -1893,7 +1913,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
18931913  } 
18941914} 
18951915
1896- type  CellRendererProps  =  { 
1916+ type  CellRendererBaseProps  =  { 
18971917  CellRendererComponent ?: ?React . ComponentType < any > , 
18981918  ItemSeparatorComponent : ?React . ComponentType < 
18991919    any  |  { highlighted : boolean ,  leadingItem : ?Item } , 
@@ -1992,6 +2012,15 @@ class CellRenderer extends React.Component<
19922012    this . props . onUnmount ( this . props . cellKey ) ; 
19932013  } 
19942014
2015+   _onLayout  =  ( e ) : void  =>  { 
2016+     if  ( VirtualizedListInjection . useVLOptimization )  { 
2017+       this . props . onLayout  && 
2018+         this . props . onLayout ( e ,  this . props . cellKey ,  this . props . index ) ; 
2019+     }  else  { 
2020+       this . props . onLayout  &&  this . props . onLayout ( e ) ; 
2021+     } 
2022+   } ; 
2023+ 
19952024  _renderElement ( renderItem ,  ListItemComponent ,  item ,  index )  { 
19962025    if  ( renderItem  &&  ListItemComponent )  { 
19972026      console . warn ( 
@@ -2037,9 +2066,25 @@ class CellRenderer extends React.Component<
20372066      item , 
20382067      index , 
20392068      inversionStyle , 
2040-       parentProps , 
20412069    }  =  this . props ; 
2042-     const  { renderItem ,  getItemLayout ,  ListItemComponent }  =  parentProps ; 
2070+ 
2071+     let  ListItemComponent : $PropertyType < OptionalProps ,  'ListEmptyComponent' > ; 
2072+     let  renderItem : $PropertyType < OptionalProps ,  'renderItem' > ; 
2073+     let  debug : $PropertyType < OptionalProps ,  'debug' > ; 
2074+     let  getItemLayout : $PropertyType < OptionalProps ,  'getItemLayout' > ; 
2075+     if  ( this . props . experimentalVirtualizedListOpt  ===  true )  { 
2076+       ListItemComponent  =  this . props . ListItemComponent ; 
2077+       renderItem  =  this . props . renderItem ; 
2078+       debug  =  this . props . debug ; 
2079+       getItemLayout  =  this . props . getItemLayout ; 
2080+     }  else  { 
2081+       const  parentProps  =  this . props . parentProps ; 
2082+       ListItemComponent  =  parentProps . ListItemComponent ; 
2083+       renderItem  =  parentProps . renderItem ; 
2084+       debug  =  parentProps . debug ; 
2085+       getItemLayout  =  parentProps . getItemLayout ; 
2086+     } 
2087+ 
20432088    const  element  =  this . _renderElement ( 
20442089      renderItem , 
20452090      ListItemComponent , 
0 commit comments