Skip to content

Commit 074a2fa

Browse files
logandanielsfacebook-github-bot
authored andcommitted
Update measurements for Footer in VirtualizedList when the footer's onLayout is called
Summary: When any list cell that may contain nested VirtualizedLists is laid out, it's possible that the offset of any child lists relative to the outermost list has changed. We need to tell these children to re-measure themselves relative to that outermost list, so that their viewability calculations are correct. We already do this for regular list cells -- we just need to extend that logic to any child lists that may live in the ListFooterComponent. Changelog: [General] [Fixed] - Fix viewability calculations for nested VirtualizedLists inside of a parent list's FooterComponent Differential Revision: D20310961 fbshipit-source-id: 4bfcfb95c87329f2ee337d5499e5c7162ba692e8
1 parent acbf9e1 commit 074a2fa

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

Libraries/Lists/VirtualizedList.js

+19-10
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
11331133
);
11341134
cells.push(
11351135
<VirtualizedCellWrapper
1136-
cellKey={this._getCellKey() + '-footer'}
1136+
cellKey={this._getFooterCellKey()}
11371137
key="$footer">
11381138
<View
11391139
onLayout={this._onLayoutFooter}
@@ -1362,15 +1362,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
13621362
this._frames[cellKey].inLayout = true;
13631363
}
13641364

1365-
const childListKeys = this._cellKeysToChildListKeys.get(cellKey);
1366-
if (childListKeys) {
1367-
for (let childKey of childListKeys) {
1368-
const childList = this._nestedChildLists.get(childKey);
1369-
childList &&
1370-
childList.ref &&
1371-
childList.ref.measureLayoutRelativeToContainingList();
1372-
}
1373-
}
1365+
this._triggerRemeasureForChildListsInCell(cellKey);
13741366

13751367
this._computeBlankness();
13761368
this._updateViewableItems(this.props.data);
@@ -1383,6 +1375,18 @@ class VirtualizedList extends React.PureComponent<Props, State> {
13831375
}
13841376
};
13851377

1378+
_triggerRemeasureForChildListsInCell(cellKey: string): void {
1379+
const childListKeys = this._cellKeysToChildListKeys.get(cellKey);
1380+
if (childListKeys) {
1381+
for (let childKey of childListKeys) {
1382+
const childList = this._nestedChildLists.get(childKey);
1383+
childList &&
1384+
childList.ref &&
1385+
childList.ref.measureLayoutRelativeToContainingList();
1386+
}
1387+
}
1388+
}
1389+
13861390
measureLayoutRelativeToContainingList(): void {
13871391
// TODO (T35574538): findNodeHandle sometimes crashes with "Unable to find
13881392
// node on an unmounted component" during scrolling
@@ -1443,7 +1447,12 @@ class VirtualizedList extends React.PureComponent<Props, State> {
14431447
this.props.onLayout && this.props.onLayout(e);
14441448
};
14451449

1450+
_getFooterCellKey(): string {
1451+
return this._getCellKey() + '-footer';
1452+
}
1453+
14461454
_onLayoutFooter = e => {
1455+
this._triggerRemeasureForChildListsInCell(this._getFooterCellKey());
14471456
this._footerLength = this._selectLength(e.nativeEvent.layout);
14481457
};
14491458

0 commit comments

Comments
 (0)