mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Constrain data type in getItemLayout callback (#36237)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36237 This changes the data parameter type for `getItemLayout` from a mutable array (too lenient, even before), to `ArrayLike`, which is now the most constrained subset of data which may be passed to a FlatList. We could do something more exact by adding another generic parameter to FlatList, but that would be likely be noticeably more breaking, since during testing I couldn't manage a pattern that both kept the same minimum number of generic arguments while keeping inference working. Changelog: [General][Breaking] - Constrain data type in `getItemLayout` callback Reviewed By: javache Differential Revision: D43466967 fbshipit-source-id: 7a1ce717e7d5cc96a58b8d3ad9def6cf6250871f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c03de97fb4
commit
febf6b7f33
Vendored
+1
-1
@@ -66,7 +66,7 @@ export interface FlatListProps<ItemT> extends VirtualizedListProps<ItemT> {
|
||||
*/
|
||||
getItemLayout?:
|
||||
| ((
|
||||
data: Array<ItemT> | null | undefined,
|
||||
data: ArrayLike<ItemT> | null | undefined,
|
||||
index: number,
|
||||
) => {length: number; offset: number; index: number})
|
||||
| undefined;
|
||||
|
||||
@@ -91,7 +91,7 @@ type OptionalProps<ItemT> = {|
|
||||
* specify `ItemSeparatorComponent`.
|
||||
*/
|
||||
getItemLayout?: (
|
||||
data: ?Array<ItemT>,
|
||||
data: ?$ArrayLike<ItemT>,
|
||||
index: number,
|
||||
) => {
|
||||
length: number,
|
||||
|
||||
@@ -705,6 +705,21 @@ export class FlatListTest extends React.Component<FlatListProps<number>, {}> {
|
||||
}
|
||||
}
|
||||
|
||||
<FlatList
|
||||
data={[1, 2, 3]}
|
||||
renderItem={null}
|
||||
getItemLayout={(
|
||||
data: ArrayLike<number> | null | undefined,
|
||||
index: number,
|
||||
) => {
|
||||
return {
|
||||
length: data![index] % 2 === 0 ? 10 : 5,
|
||||
offset: 1234,
|
||||
index,
|
||||
};
|
||||
}}
|
||||
/>;
|
||||
|
||||
export class SectionListTest extends React.Component<
|
||||
SectionListProps<string>,
|
||||
{}
|
||||
|
||||
Reference in New Issue
Block a user