@@ -361,6 +361,14 @@ type State = {
361
361
class VirtualizedList extends React . PureComponent < Props , State > {
362
362
static contextType : typeof VirtualizedListContext = VirtualizedListContext ;
363
363
364
+ pushOrUnshift ( input : Array < any > , item : Item ) {
365
+ if ( this . props . inverted ) {
366
+ input . unshift ( item )
367
+ } else {
368
+ input . push ( item )
369
+ }
370
+ }
371
+
364
372
// scrollToEnd may be janky without getItemLayout prop
365
373
scrollToEnd ( params ?: ?{ animated ?: ?boolean , ...} ) {
366
374
const animated = params ? params . animated : true ;
@@ -707,7 +715,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
707
715
) ;
708
716
} else if ( this . props . onViewableItemsChanged ) {
709
717
const onViewableItemsChanged = this . props . onViewableItemsChanged
710
- this . _viewabilityTuples . push ( {
718
+ this . pushOrUnshift ( this . _viewabilityTuples , {
711
719
viewabilityHelper : new ViewabilityHelper ( this . props . viewabilityConfig ) ,
712
720
onViewableItemsChanged,
713
721
} ) ;
@@ -807,9 +815,9 @@ class VirtualizedList extends React.PureComponent<Props, State> {
807
815
const key = keyExtractor ( item , ii ) ;
808
816
this . _indicesToKeys . set ( ii , key ) ;
809
817
if ( stickyIndicesFromProps . has ( ii + stickyOffset ) ) {
810
- stickyHeaderIndices . push ( cells . length ) ;
818
+ this . pushOrUnshift ( stickyHeaderIndices , cells . length ) ;
811
819
}
812
- cells . push (
820
+ this . pushOrUnshift ( cells ,
813
821
< CellRenderer
814
822
CellRendererComponent = { CellRendererComponent }
815
823
ItemSeparatorComponent = { ii < end ? ItemSeparatorComponent : undefined }
@@ -879,15 +887,15 @@ class VirtualizedList extends React.PureComponent<Props, State> {
879
887
const stickyHeaderIndices = [ ] ;
880
888
if ( ListHeaderComponent ) {
881
889
if ( stickyIndicesFromProps . has ( 0 ) ) {
882
- stickyHeaderIndices . push ( 0 ) ;
890
+ this . pushOrUnshift ( stickyHeaderIndices , 0 ) ;
883
891
}
884
892
const element = React . isValidElement ( ListHeaderComponent ) ? (
885
893
ListHeaderComponent
886
894
) : (
887
895
// $FlowFixMe
888
896
< ListHeaderComponent />
889
897
) ;
890
- cells . push (
898
+ this . pushOrUnshift ( cells ,
891
899
< VirtualizedListCellContextProvider
892
900
cellKey = { this . _getCellKey ( ) + '-header' }
893
901
key = "$header" >
@@ -936,7 +944,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
936
944
stickyBlock . offset -
937
945
initBlock . offset -
938
946
( this . props . initialScrollIndex ? 0 : initBlock . length ) ;
939
- cells . push (
947
+ this . pushOrUnshift ( cells ,
940
948
/* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment
941
949
* suppresses an error found when Flow v0.111 was deployed. To
942
950
* see the error, delete this comment and run Flow. */
@@ -953,7 +961,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
953
961
const trailSpace =
954
962
this . _getFrameMetricsApprox ( first ) . offset -
955
963
( stickyBlock . offset + stickyBlock . length ) ;
956
- cells . push (
964
+ this . pushOrUnshift ( cells ,
957
965
/* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment
958
966
* suppresses an error found when Flow v0.111 was deployed. To
959
967
* see the error, delete this comment and run Flow. */
@@ -969,7 +977,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
969
977
const firstSpace =
970
978
this . _getFrameMetricsApprox ( first ) . offset -
971
979
( initBlock . offset + initBlock . length ) ;
972
- cells . push (
980
+ this . pushOrUnshift ( cells ,
973
981
/* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment
974
982
* suppresses an error found when Flow v0.111 was deployed. To see
975
983
* the error, delete this comment and run Flow. */
@@ -1006,7 +1014,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1006
1014
endFrame . offset +
1007
1015
endFrame . length -
1008
1016
( lastFrame . offset + lastFrame . length ) ;
1009
- cells . push (
1017
+ this . pushOrUnshift ( cells ,
1010
1018
/* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment suppresses
1011
1019
* an error found when Flow v0.111 was deployed. To see the error,
1012
1020
* delete this comment and run Flow. */
@@ -1022,7 +1030,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1022
1030
// $FlowFixMe
1023
1031
< ListEmptyComponent />
1024
1032
)): any);
1025
- cells.push(
1033
+ this.pushOrUnshift(cells,
1026
1034
React.cloneElement(element, {
1027
1035
key : '$empty' ,
1028
1036
onLayout : event => {
@@ -1042,7 +1050,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1042
1050
// $FlowFixMe
1043
1051
< ListFooterComponent />
1044
1052
) ;
1045
- cells . push (
1053
+ this . pushOrUnshift ( cells ,
1046
1054
< VirtualizedListCellContextProvider
1047
1055
cellKey = { this . _getFooterCellKey ( ) }
1048
1056
key = "$footer" >
@@ -1367,7 +1375,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1367
1375
* error found when Flow v0.68 was deployed. To see the error delete this
1368
1376
* comment and run Flow. */
1369
1377
if ( frame . inLayout ) {
1370
- framesInLayout . push ( frame ) ;
1378
+ this . pushOrUnshift ( framesInLayout , frame ) ;
1371
1379
}
1372
1380
}
1373
1381
const windowTop = this._getFrameMetricsApprox(this.state.first).offset;
@@ -1505,6 +1513,11 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1505
1513
} ;
1506
1514
1507
1515
_onScroll = (e: Object) => {
1516
+ var contentOffset = ( this . props . inverted ) ? {
1517
+ x : - e . nativeEvent . contentOffset . x ,
1518
+ y : - e . nativeEvent . contentOffset . y ,
1519
+ } : e . nativeEvent . contentOffset
1520
+
1508
1521
this . _nestedChildLists . forEach ( childList => {
1509
1522
childList . ref && childList . ref . _onScroll ( e ) ;
1510
1523
} ) ;
@@ -1514,7 +1527,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1514
1527
const timestamp = e.timeStamp;
1515
1528
let visibleLength = this._selectLength(e.nativeEvent.layoutMeasurement);
1516
1529
let contentLength = this._selectLength(e.nativeEvent.contentSize);
1517
- let offset = this._selectOffset(e.nativeEvent. contentOffset);
1530
+ let offset = this._selectOffset(contentOffset);
1518
1531
let dOffset = offset - this._scrollMetrics.offset;
1519
1532
1520
1533
if (this._isNestedWithSameOrientation()) {
@@ -2048,10 +2061,10 @@ function describeNestedLists(childList: {
2048
2061
2049
2062
const styles = StyleSheet . create ( {
2050
2063
verticallyInverted : {
2051
- transform : [ { scaleY : - 1 } ] ,
2064
+ flexDirection : 'column-reverse' ,
2052
2065
} ,
2053
2066
horizontallyInverted : {
2054
- transform : [ { scaleX : - 1 } ] ,
2067
+ flexDirection : 'row-reverse' ,
2055
2068
} ,
2056
2069
row : {
2057
2070
flexDirection : 'row' ,
0 commit comments