Skip to content

Commit 04e4354

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Allow VirtualizedListContext to support different component type
Summary: This change is in preparation of adding a separate `VirtualizedList_EXPERIMENTAL` component. Both the original, and experimental lists use `VirtualizedListContext`, which itself references back to the VirtualizedList class type. VirtualizedList private methods are currently included in the type system, and are called in other VirtualizedList code (see b2f871a). This prevents Flow from seeing the two classes are compatible if "private" methods change. My first attempt was to parameterize the context, to allow both `VirtualizedList`, and `VirtualizedList_EXPERIMENTAL` to use the same code without sacrificing type safety or adding further duplication. This added more complexity than it is worth, so I am instead loosening the type on VirtualizedListContext to pass around a more generic handle. Changelog: [Internal][Changed] - Allow VirtualizedListContext to support different component type Reviewed By: javache Differential Revision: D38017086 fbshipit-source-id: 91e8f6ab2591d3ae9b7f9263711b4a39b78f68e0
1 parent f1d6248 commit 04e4354

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Libraries/Lists/VirtualizedList.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,11 @@ class VirtualizedList extends React.PureComponent<Props, State> {
634634
_registerAsNestedChild = (childList: {
635635
cellKey: string,
636636
key: string,
637-
ref: VirtualizedList,
637+
ref: React.ElementRef<typeof React.Component>,
638638
parentDebugInfo: ListDebugInfo,
639639
...
640640
}): ?ChildListState => {
641+
const specificRef = ((childList.ref: any): VirtualizedList);
641642
// Register the mapping between this child key and the cellKey for its cell
642643
const childListsInCell =
643644
this._cellKeysToChildListKeys.get(childList.cellKey) || new Set();
@@ -651,19 +652,20 @@ class VirtualizedList extends React.PureComponent<Props, State> {
651652
'list. You must pass a unique listKey prop to each sibling list.\n\n' +
652653
describeNestedLists({
653654
...childList,
655+
ref: specificRef,
654656
// We're called from the child's componentDidMount, so it's safe to
655657
// read the child's props here (albeit weird).
656-
horizontal: !!childList.ref.props.horizontal,
658+
horizontal: !!specificRef.props.horizontal,
657659
}),
658660
);
659661
}
660662
this._nestedChildLists.set(childList.key, {
661-
ref: childList.ref,
663+
ref: specificRef,
662664
state: null,
663665
});
664666

665667
if (this._hasInteracted) {
666-
childList.ref.recordInteraction();
668+
specificRef.recordInteraction();
667669
}
668670
};
669671

Libraries/Lists/VirtualizedListContext.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* @format
99
*/
1010

11-
import type VirtualizedList from './VirtualizedList.js';
1211
import * as React from 'react';
1312
import {useMemo, useContext} from 'react';
1413

@@ -50,12 +49,12 @@ type Context = $ReadOnly<{
5049
zoomScale: number,
5150
},
5251
horizontal: ?boolean,
53-
getOutermostParentListRef: () => VirtualizedList,
52+
getOutermostParentListRef: () => React.ElementRef<typeof React.Component>,
5453
getNestedChildState: string => ?ChildListState,
5554
registerAsNestedChild: ({
5655
cellKey: string,
5756
key: string,
58-
ref: VirtualizedList,
57+
ref: React.ElementRef<typeof React.Component>,
5958
parentDebugInfo: ListDebugInfo,
6059
}) => ?ChildListState,
6160
unregisterAsNestedChild: ({

0 commit comments

Comments
 (0)