mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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 https://github.com/facebook/react-native/commit/b2f871a6fa9c92dd0712055384b9eca6d828e37d). 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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f1d624823f
commit
04e43544b8
@@ -634,10 +634,11 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
||||
_registerAsNestedChild = (childList: {
|
||||
cellKey: string,
|
||||
key: string,
|
||||
ref: VirtualizedList,
|
||||
ref: React.ElementRef<typeof React.Component>,
|
||||
parentDebugInfo: ListDebugInfo,
|
||||
...
|
||||
}): ?ChildListState => {
|
||||
const specificRef = ((childList.ref: any): VirtualizedList);
|
||||
// Register the mapping between this child key and the cellKey for its cell
|
||||
const childListsInCell =
|
||||
this._cellKeysToChildListKeys.get(childList.cellKey) || new Set();
|
||||
@@ -651,19 +652,20 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
||||
'list. You must pass a unique listKey prop to each sibling list.\n\n' +
|
||||
describeNestedLists({
|
||||
...childList,
|
||||
ref: specificRef,
|
||||
// We're called from the child's componentDidMount, so it's safe to
|
||||
// read the child's props here (albeit weird).
|
||||
horizontal: !!childList.ref.props.horizontal,
|
||||
horizontal: !!specificRef.props.horizontal,
|
||||
}),
|
||||
);
|
||||
}
|
||||
this._nestedChildLists.set(childList.key, {
|
||||
ref: childList.ref,
|
||||
ref: specificRef,
|
||||
state: null,
|
||||
});
|
||||
|
||||
if (this._hasInteracted) {
|
||||
childList.ref.recordInteraction();
|
||||
specificRef.recordInteraction();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import type VirtualizedList from './VirtualizedList.js';
|
||||
import * as React from 'react';
|
||||
import {useMemo, useContext} from 'react';
|
||||
|
||||
@@ -50,12 +49,12 @@ type Context = $ReadOnly<{
|
||||
zoomScale: number,
|
||||
},
|
||||
horizontal: ?boolean,
|
||||
getOutermostParentListRef: () => VirtualizedList,
|
||||
getOutermostParentListRef: () => React.ElementRef<typeof React.Component>,
|
||||
getNestedChildState: string => ?ChildListState,
|
||||
registerAsNestedChild: ({
|
||||
cellKey: string,
|
||||
key: string,
|
||||
ref: VirtualizedList,
|
||||
ref: React.ElementRef<typeof React.Component>,
|
||||
parentDebugInfo: ListDebugInfo,
|
||||
}) => ?ChildListState,
|
||||
unregisterAsNestedChild: ({
|
||||
|
||||
Reference in New Issue
Block a user