Nested virtualized lists should receive recordInteration events

Summary:
Right now when an interaction is recorded on a parent VirtualizedList, the interaction isn't passed on to its children. That means that if `waitForInteraction` is set to true for a child list's viewability helper, it will never trigger a VPV.

This change adds forwarding of these events inside `onBeginScrollDrag`. It also forwards the interaction state of the parent list at register time, in case a child list is rendered mid-scroll.

Reviewed By: sahrens

Differential Revision: D6822091

fbshipit-source-id: dfe300e42722d4285f65787ab2c1368f050c5577
This commit is contained in:
Logan Daniels 2018-01-29 11:46:53 -08:00 committed by Facebook Github Bot
parent ecaca80d42
commit ae2d5b1e68
1 changed files with 12 additions and 0 deletions

View File

@ -375,6 +375,9 @@ class VirtualizedList extends React.PureComponent<Props, State> {
} }
recordInteraction() { recordInteraction() {
this._nestedChildLists.forEach(childList => {
childList.ref && childList.ref.recordInteraction();
});
this._viewabilityTuples.forEach(t => { this._viewabilityTuples.forEach(t => {
t.viewabilityHelper.recordInteraction(); t.viewabilityHelper.recordInteraction();
}); });
@ -512,6 +515,10 @@ class VirtualizedList extends React.PureComponent<Props, State> {
state: null, state: null,
}); });
if (this._hasInteracted) {
childList.ref.recordInteraction();
}
return existingChildData && existingChildData.state; return existingChildData && existingChildData.state;
}; };
@ -941,6 +948,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
_frames = {}; _frames = {};
_footerLength = 0; _footerLength = 0;
_hasDataChangedSinceEndReached = true; _hasDataChangedSinceEndReached = true;
_hasInteracted = false;
_hasMore = false; _hasMore = false;
_hasWarned = {}; _hasWarned = {};
_highestMeasuredFrameIndex = 0; _highestMeasuredFrameIndex = 0;
@ -1334,9 +1342,13 @@ class VirtualizedList extends React.PureComponent<Props, State> {
} }
_onScrollBeginDrag = (e): void => { _onScrollBeginDrag = (e): void => {
this._nestedChildLists.forEach(childList => {
childList.ref && childList.ref._onScrollBeginDrag(e);
});
this._viewabilityTuples.forEach(tuple => { this._viewabilityTuples.forEach(tuple => {
tuple.viewabilityHelper.recordInteraction(); tuple.viewabilityHelper.recordInteraction();
}); });
this._hasInteracted = true;
this.props.onScrollBeginDrag && this.props.onScrollBeginDrag(e); this.props.onScrollBeginDrag && this.props.onScrollBeginDrag(e);
}; };