Skip to content

Commit e94d344

Browse files
michalchudziakkelset
authored andcommitted
Fix behaviour of Header, Footer and Empty List components in VirtualizedList when it's inverted (#24167)
Summary: Fixes #23453 Fixes #21196 Basically, changes made in #21496 currently breaks behavior of `<VirtualizedList />` and any components that are based on it (`<SectionList />, <FlatList />`). This PR solves both issues listed above. Visual confirmation of the resolved issue: **Vertical, not inverted, not empty** ![image](https://user-images.githubusercontent.com/7837457/55076839-b005d700-5096-11e9-91de-090934cb0129.png) **Vertical, not inverted, empty** ![image](https://user-images.githubusercontent.com/7837457/55076971-fb1fea00-5096-11e9-8d73-5a2d86275da8.png) **Vertical, inverted, not empty** ![image](https://user-images.githubusercontent.com/7837457/55077042-23a7e400-5097-11e9-911f-9dad4d48a578.png) **Vertical, inverted, empty** ![image](https://user-images.githubusercontent.com/7837457/55079957-87351000-509d-11e9-8f1c-b7134f1f43f9.png) **Horizontal, not inverted, not empty** ![image](https://user-images.githubusercontent.com/7837457/55077118-44703980-5097-11e9-94e9-e33d4af436ee.png) **Horizontal, not inverted, empty** ![image](https://user-images.githubusercontent.com/7837457/55077150-52be5580-5097-11e9-9d43-7cb4e983167e.png) **Horizontal, inverted, not empty** ![image](https://user-images.githubusercontent.com/7837457/55077183-623d9e80-5097-11e9-9e8a-1b2468c7b3a9.png) **Horizontal, inverted, empty** ![image](https://user-images.githubusercontent.com/7837457/55080033-af247380-509d-11e9-90ae-1ff656d46dd1.png) [General] [Fixed] - Fixed VirtualizedList, SectionList and FlatList behavior on rendering list headers with inverted prop and zero items Pull Request resolved: #24167 Differential Revision: D14642345 Pulled By: cpojer fbshipit-source-id: b530bbbd57f60e53a976ac5db272ea4b2d2b3e99
1 parent 13cb5a9 commit e94d344

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

Libraries/Lists/VirtualizedList.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -885,16 +885,17 @@ class VirtualizedList extends React.PureComponent<Props, State> {
885885
<ListEmptyComponent />
886886
)): any);
887887
cells.push(
888-
React.cloneElement(element, {
889-
key: '$empty',
890-
onLayout: event => {
891-
this._onLayoutEmpty(event);
892-
if (element.props.onLayout) {
893-
element.props.onLayout(event);
894-
}
895-
},
896-
style: [element.props.style, inversionStyle],
897-
}),
888+
<View key="$empty" style={inversionStyle}>
889+
{React.cloneElement(element, {
890+
onLayout: event => {
891+
this._onLayoutEmpty(event);
892+
if (element.props.onLayout) {
893+
element.props.onLayout(event);
894+
}
895+
},
896+
style: element.props.style,
897+
})}
898+
</View>,
898899
);
899900
}
900901
if (ListFooterComponent) {
@@ -937,7 +938,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
937938
: this.props.inverted,
938939
stickyHeaderIndices,
939940
};
940-
if (inversionStyle && itemCount !== 0) {
941+
if (inversionStyle) {
941942
/* $FlowFixMe(>=0.70.0 site=react_native_fb) This comment suppresses an
942943
* error found when Flow v0.70 was deployed. To see the error delete
943944
* this comment and run Flow. */

Libraries/Lists/__tests__/__snapshots__/VirtualizedList-test.js.snap

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,11 @@ exports[`VirtualizedList renders empty list with empty component 1`] = `
668668
>
669669
<header />
670670
</View>
671-
<empty />
671+
<View
672+
style={null}
673+
>
674+
<empty />
675+
</View>
672676
<View
673677
onLayout={[Function]}
674678
>

0 commit comments

Comments
 (0)