Skip to content

Commit

Permalink
Update measurements for Footer in VirtualizedList when the footer's o…
Browse files Browse the repository at this point in the history
…nLayout 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
  • Loading branch information
logandaniels authored and facebook-github-bot committed Mar 6, 2020
1 parent acbf9e1 commit 074a2fa
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
);
cells.push(
<VirtualizedCellWrapper
cellKey={this._getCellKey() + '-footer'}
cellKey={this._getFooterCellKey()}
key="$footer">
<View
onLayout={this._onLayoutFooter}
Expand Down Expand Up @@ -1362,15 +1362,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
this._frames[cellKey].inLayout = true;
}

const childListKeys = this._cellKeysToChildListKeys.get(cellKey);
if (childListKeys) {
for (let childKey of childListKeys) {
const childList = this._nestedChildLists.get(childKey);
childList &&
childList.ref &&
childList.ref.measureLayoutRelativeToContainingList();
}
}
this._triggerRemeasureForChildListsInCell(cellKey);

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

_triggerRemeasureForChildListsInCell(cellKey: string): void {
const childListKeys = this._cellKeysToChildListKeys.get(cellKey);
if (childListKeys) {
for (let childKey of childListKeys) {
const childList = this._nestedChildLists.get(childKey);
childList &&
childList.ref &&
childList.ref.measureLayoutRelativeToContainingList();
}
}
}

measureLayoutRelativeToContainingList(): void {
// TODO (T35574538): findNodeHandle sometimes crashes with "Unable to find
// node on an unmounted component" during scrolling
Expand Down Expand Up @@ -1443,7 +1447,12 @@ class VirtualizedList extends React.PureComponent<Props, State> {
this.props.onLayout && this.props.onLayout(e);
};

_getFooterCellKey(): string {
return this._getCellKey() + '-footer';
}

_onLayoutFooter = e => {
this._triggerRemeasureForChildListsInCell(this._getFooterCellKey());
this._footerLength = this._selectLength(e.nativeEvent.layout);
};

Expand Down

0 comments on commit 074a2fa

Please sign in to comment.