@@ -16,6 +16,7 @@ const ScrollView = require('../Components/ScrollView/ScrollView');
16
16
const StyleSheet = require ( '../StyleSheet/StyleSheet' ) ;
17
17
const View = require ( '../Components/View/View' ) ;
18
18
const ViewabilityHelper = require ( './ViewabilityHelper' ) ;
19
+ import VirtualizedListInjection from './VirtualizedListInjection' ;
19
20
20
21
const flattenStyle = require ( '../StyleSheet/flattenStyle' ) ;
21
22
const infoLog = require ( '../Utilities/infoLog' ) ;
@@ -221,6 +222,7 @@ type OptionalProps = {|
221
222
* within half the visible length of the list.
222
223
*/
223
224
onEndReachedThreshold ?: ?number ,
225
+ onLayout ?: ?( e : LayoutEvent ) => void ,
224
226
/**
225
227
* If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make
226
228
* sure to also set the `refreshing` prop correctly.
@@ -810,27 +812,45 @@ class VirtualizedList extends React.PureComponent<Props, State> {
810
812
if ( stickyIndicesFromProps . has ( ii + stickyOffset ) ) {
811
813
stickyHeaderIndices . push ( cells . length ) ;
812
814
}
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
+ }
834
854
prevCellKey = key ;
835
855
}
836
856
}
@@ -1269,7 +1289,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1269
1289
}
1270
1290
} ;
1271
1291
1272
- _onCellLayout ( e , cellKey , index ) {
1292
+ _onCellLayout = ( e , cellKey , index ) : void => {
1273
1293
const layout = e . nativeEvent . layout ;
1274
1294
const next = {
1275
1295
offset : this . _selectOffset ( layout ) ,
@@ -1302,7 +1322,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1302
1322
1303
1323
this._computeBlankness();
1304
1324
this._updateViewableItems(this.props.data);
1305
- }
1325
+ } ;
1306
1326
1307
1327
_onCellUnmount = ( cellKey : string ) => {
1308
1328
const curr = this . _frames [ cellKey ] ;
@@ -1893,7 +1913,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1893
1913
}
1894
1914
}
1895
1915
1896
- type CellRendererProps = {
1916
+ type CellRendererBaseProps = {
1897
1917
CellRendererComponent ?: ?React . ComponentType < any > ,
1898
1918
ItemSeparatorComponent : ?React . ComponentType <
1899
1919
any | { highlighted : boolean , leadingItem : ?Item } ,
@@ -1992,6 +2012,15 @@ class CellRenderer extends React.Component<
1992
2012
this . props . onUnmount ( this . props . cellKey ) ;
1993
2013
}
1994
2014
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
+
1995
2024
_renderElement ( renderItem , ListItemComponent , item , index ) {
1996
2025
if ( renderItem && ListItemComponent ) {
1997
2026
console . warn (
@@ -2037,9 +2066,25 @@ class CellRenderer extends React.Component<
2037
2066
item ,
2038
2067
index ,
2039
2068
inversionStyle ,
2040
- parentProps ,
2041
2069
} = 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
+
2043
2088
const element = this . _renderElement (
2044
2089
renderItem ,
2045
2090
ListItemComponent ,
0 commit comments