@@ -361,6 +361,14 @@ type State = {
361361class VirtualizedList extends React . PureComponent < Props , State > {
362362 static contextType : typeof VirtualizedListContext = VirtualizedListContext ;
363363
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+
364372 // scrollToEnd may be janky without getItemLayout prop
365373 scrollToEnd ( params ?: ?{ animated ?: ?boolean , ...} ) {
366374 const animated = params ? params . animated : true ;
@@ -707,7 +715,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
707715 ) ;
708716 } else if ( this . props . onViewableItemsChanged ) {
709717 const onViewableItemsChanged = this . props . onViewableItemsChanged
710- this . _viewabilityTuples . push ( {
718+ this . pushOrUnshift ( this . _viewabilityTuples , {
711719 viewabilityHelper : new ViewabilityHelper ( this . props . viewabilityConfig ) ,
712720 onViewableItemsChanged,
713721 } ) ;
@@ -807,9 +815,9 @@ class VirtualizedList extends React.PureComponent<Props, State> {
807815 const key = keyExtractor ( item , ii ) ;
808816 this . _indicesToKeys . set ( ii , key ) ;
809817 if ( stickyIndicesFromProps . has ( ii + stickyOffset ) ) {
810- stickyHeaderIndices . push ( cells . length ) ;
818+ this . pushOrUnshift ( stickyHeaderIndices , cells . length ) ;
811819 }
812- cells . push (
820+ this . pushOrUnshift ( cells ,
813821 < CellRenderer
814822 CellRendererComponent = { CellRendererComponent }
815823 ItemSeparatorComponent = { ii < end ? ItemSeparatorComponent : undefined }
@@ -879,15 +887,15 @@ class VirtualizedList extends React.PureComponent<Props, State> {
879887 const stickyHeaderIndices = [ ] ;
880888 if ( ListHeaderComponent ) {
881889 if ( stickyIndicesFromProps . has ( 0 ) ) {
882- stickyHeaderIndices . push ( 0 ) ;
890+ this . pushOrUnshift ( stickyHeaderIndices , 0 ) ;
883891 }
884892 const element = React . isValidElement ( ListHeaderComponent ) ? (
885893 ListHeaderComponent
886894 ) : (
887895 // $FlowFixMe
888896 < ListHeaderComponent />
889897 ) ;
890- cells . push (
898+ this . pushOrUnshift ( cells ,
891899 < VirtualizedListCellContextProvider
892900 cellKey = { this . _getCellKey ( ) + '-header' }
893901 key = "$header" >
@@ -936,7 +944,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
936944 stickyBlock . offset -
937945 initBlock . offset -
938946 ( this . props . initialScrollIndex ? 0 : initBlock . length ) ;
939- cells . push (
947+ this . pushOrUnshift ( cells ,
940948 /* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment
941949 * suppresses an error found when Flow v0.111 was deployed. To
942950 * see the error, delete this comment and run Flow. */
@@ -953,7 +961,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
953961 const trailSpace =
954962 this . _getFrameMetricsApprox ( first ) . offset -
955963 ( stickyBlock . offset + stickyBlock . length ) ;
956- cells . push (
964+ this . pushOrUnshift ( cells ,
957965 /* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment
958966 * suppresses an error found when Flow v0.111 was deployed. To
959967 * see the error, delete this comment and run Flow. */
@@ -969,7 +977,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
969977 const firstSpace =
970978 this . _getFrameMetricsApprox ( first ) . offset -
971979 ( initBlock . offset + initBlock . length ) ;
972- cells . push (
980+ this . pushOrUnshift ( cells ,
973981 /* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment
974982 * suppresses an error found when Flow v0.111 was deployed. To see
975983 * the error, delete this comment and run Flow. */
@@ -1006,7 +1014,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
10061014 endFrame . offset +
10071015 endFrame . length -
10081016 ( lastFrame . offset + lastFrame . length ) ;
1009- cells . push (
1017+ this . pushOrUnshift ( cells ,
10101018 /* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment suppresses
10111019 * an error found when Flow v0.111 was deployed. To see the error,
10121020 * delete this comment and run Flow. */
@@ -1022,7 +1030,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
10221030 // $FlowFixMe
10231031 < ListEmptyComponent />
10241032 )): any);
1025- cells.push(
1033+ this.pushOrUnshift(cells,
10261034 React.cloneElement(element, {
10271035 key : '$empty' ,
10281036 onLayout : event => {
@@ -1042,7 +1050,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
10421050 // $FlowFixMe
10431051 < ListFooterComponent />
10441052 ) ;
1045- cells . push (
1053+ this . pushOrUnshift ( cells ,
10461054 < VirtualizedListCellContextProvider
10471055 cellKey = { this . _getFooterCellKey ( ) }
10481056 key = "$footer" >
@@ -1367,7 +1375,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
13671375 * error found when Flow v0.68 was deployed. To see the error delete this
13681376 * comment and run Flow. */
13691377 if ( frame . inLayout ) {
1370- framesInLayout . push ( frame ) ;
1378+ this . pushOrUnshift ( framesInLayout , frame ) ;
13711379 }
13721380 }
13731381 const windowTop = this._getFrameMetricsApprox(this.state.first).offset;
@@ -1505,6 +1513,11 @@ class VirtualizedList extends React.PureComponent<Props, State> {
15051513 } ;
15061514
15071515 _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+
15081521 this . _nestedChildLists . forEach ( childList => {
15091522 childList . ref && childList . ref . _onScroll ( e ) ;
15101523 } ) ;
@@ -1514,7 +1527,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
15141527 const timestamp = e.timeStamp;
15151528 let visibleLength = this._selectLength(e.nativeEvent.layoutMeasurement);
15161529 let contentLength = this._selectLength(e.nativeEvent.contentSize);
1517- let offset = this._selectOffset(e.nativeEvent. contentOffset);
1530+ let offset = this._selectOffset(contentOffset);
15181531 let dOffset = offset - this._scrollMetrics.offset;
15191532
15201533 if (this._isNestedWithSameOrientation()) {
@@ -2048,10 +2061,10 @@ function describeNestedLists(childList: {
20482061
20492062const styles = StyleSheet . create ( {
20502063 verticallyInverted : {
2051- transform : [ { scaleY : - 1 } ] ,
2064+ flexDirection : 'column-reverse' ,
20522065 } ,
20532066 horizontallyInverted : {
2054- transform : [ { scaleX : - 1 } ] ,
2067+ flexDirection : 'row-reverse' ,
20552068 } ,
20562069 row : {
20572070 flexDirection : 'row' ,
0 commit comments