From ae60ae40746a05bf411f204f5e8afde3d6fa8d97 Mon Sep 17 00:00:00 2001 From: m30do Date: Fri, 8 Sep 2017 14:57:42 -0700 Subject: [PATCH] fix ItemSeparatorComponent position in horizontal and inverted mode Summary: There's a positioning bug in `VirtualizedList` when `ItemSeparatorComponent` is defined for a list in horizontal or inverted mode. And also we face this bug in `FlatList`, because it is using `VirtualizedList` to render lists. This commit will fix the [#15777](https://github.com/facebook/react-native/issues/15777). Before fix: ``` ``` ![image](https://user-images.githubusercontent.com/15084663/30205251-95f14c70-949d-11e7-85e9-7a3304a52818.png) ``` ``` ![image](https://user-images.githubusercontent.com/15084663/30205411-f01d27b4-949d-11e7-991e-00aeae0c01e0.png) I ran this code with all possible values of `horizontal` and `inverted` props in `FlatList` and `VirtualizedList` and the results of each run was as below: After fix bug: ``` ``` ![image](https://user-images.githubusercontent.com/15084663/30205498-323bcf60-949e-11e7-8ba0-465614ea5cf2.png) ``` ``` ![image](https://user-images.githubusercontent.com/15084663/30205543-5274f612-949e-11e7-9660-bbdf8194cd27.png) Closes https://github.com/facebook/react-native/pull/15865 Differential Revision: D5797266 Pulled By: hramos fbshipit-source-id: 7d44fa797dbd9e83eb2bdd7833e9dd9707d9d822 --- Libraries/Lists/VirtualizedList.js | 13 +- .../VirtualizedList-test.js.snap | 113 ++++++++++++------ 2 files changed, 87 insertions(+), 39 deletions(-) diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index 31dd01b59..d2ae8b86b 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -518,6 +518,7 @@ class VirtualizedList extends React.PureComponent { data, getItem, getItemCount, + horizontal, keyExtractor, } = this.props; const stickyOffset = this.props.ListHeaderComponent ? 1 : 0; @@ -537,6 +538,7 @@ class VirtualizedList extends React.PureComponent { ItemSeparatorComponent={ii < end ? ItemSeparatorComponent : undefined} cellKey={key} fillRateHelper={this._fillRateHelper} + horizontal={horizontal} index={ii} inversionStyle={inversionStyle} item={item} @@ -1255,6 +1257,7 @@ class CellRenderer extends React.Component< ItemSeparatorComponent: ?React.ComponentType<*>, cellKey: string, fillRateHelper: FillRateHelper, + horizontal: ?boolean, index: number, inversionStyle: ?StyleObj, item: Item, @@ -1315,6 +1318,7 @@ class CellRenderer extends React.Component< CellRendererComponent, ItemSeparatorComponent, fillRateHelper, + horizontal, item, index, inversionStyle, @@ -1336,9 +1340,14 @@ class CellRenderer extends React.Component< const itemSeparator = ItemSeparatorComponent && ; + const cellStyle = inversionStyle + ? horizontal + ? [{flexDirection: 'row-reverse'}, inversionStyle] + : [{flexDirection: 'column-reverse'}, inversionStyle] + : horizontal ? [{flexDirection: 'row'}, inversionStyle] : inversionStyle; if (!CellRendererComponent) { return ( - + {element} {itemSeparator} @@ -1347,7 +1356,7 @@ class CellRenderer extends React.Component< return ( {element} {itemSeparator} diff --git a/Libraries/Lists/__tests__/__snapshots__/VirtualizedList-test.js.snap b/Libraries/Lists/__tests__/__snapshots__/VirtualizedList-test.js.snap index 191e7f77c..3c683de77 100644 --- a/Libraries/Lists/__tests__/__snapshots__/VirtualizedList-test.js.snap +++ b/Libraries/Lists/__tests__/__snapshots__/VirtualizedList-test.js.snap @@ -124,7 +124,14 @@ exports[`VirtualizedList handles nested lists 1`] = `