Skip to content

Commit ed39d63

Browse files
jeongshinfacebook-github-bot
authored andcommitted
Fix/animated lists types (#36292)
Summary: I was working on `Animated.FlatList` and found some types missing as below ![Screen Shot 2023-02-25 at 4 32 43 PM](https://user-images.githubusercontent.com/64301935/221345457-74252131-5207-4e17-ad96-92221a915305.png) also `Animated.SectionList` ![Screen Shot 2023-02-25 at 4 31 34 PM](https://user-images.githubusercontent.com/64301935/221345679-07ba862b-708e-400e-ac14-7d2156fcc1e8.png) So I refactored type definition for `Animated.FlatList` and `Animated.SectionList` using `abstract class`. ## Changelog [GENERAL] [FIXED] - add missing FlatList types for Animated FlatList [GENERAL] [FIXED] - add missing SectionList types for Animated SectionList <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> Pull Request resolved: #36292 Test Plan: Ran `yarn test-typescript` and `yarn test-typescript-offline` with no errors. Reviewed By: lunaleaps Differential Revision: D43673884 Pulled By: NickGerleman fbshipit-source-id: 7ccab5997fa2f22226fb0e106672cee98e568ba4
1 parent d4b228b commit ed39d63

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

Libraries/Animated/Animated.d.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ import type * as React from 'react';
1111
import {ScrollView} from '../Components/ScrollView/ScrollView';
1212
import {View} from '../Components/View/View';
1313
import {Image} from '../Image/Image';
14-
import {FlatListProps} from '../Lists/FlatList';
15-
import {DefaultSectionT, SectionListProps} from '../Lists/SectionList';
14+
import {FlatListComponent, FlatListProps} from '../Lists/FlatList';
15+
import {
16+
DefaultSectionT,
17+
SectionListComponent,
18+
SectionListProps,
19+
} from '../Lists/SectionList';
1620
import {ColorValue} from '../StyleSheet/StyleSheet';
1721
import {Text} from '../Text/Text';
1822
import {NativeSyntheticEvent} from '../Types/CoreEventTypes';
@@ -598,13 +602,18 @@ export namespace Animated {
598602
/**
599603
* FlatList and SectionList infer generic Type defined under their `data` and `section` props.
600604
*/
601-
export class FlatList<ItemT = any> extends React.Component<
605+
606+
export class FlatList<ItemT = any> extends FlatListComponent<
607+
ItemT,
602608
AnimatedProps<FlatListProps<ItemT>>
603609
> {}
610+
604611
export class SectionList<
605612
ItemT = any,
606613
SectionT = DefaultSectionT,
607-
> extends React.Component<AnimatedProps<SectionListProps<ItemT, SectionT>>> {}
614+
> extends SectionListComponent<
615+
AnimatedProps<SectionListProps<ItemT, SectionT>>
616+
> {}
608617
}
609618

610619
// We need to alias these views so we can reference them in the Animated

Libraries/Lists/FlatList.d.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,10 @@ export interface FlatListProps<ItemT> extends VirtualizedListProps<ItemT> {
166166
fadingEdgeLength?: number | undefined;
167167
}
168168

169-
export class FlatList<ItemT = any> extends React.Component<
170-
FlatListProps<ItemT>
171-
> {
169+
export abstract class FlatListComponent<
170+
ItemT,
171+
Props,
172+
> extends React.Component<Props> {
172173
/**
173174
* Scrolls to the end of the content. May be janky without `getItemLayout` prop.
174175
*/
@@ -236,3 +237,8 @@ export class FlatList<ItemT = any> extends React.Component<
236237
// TODO: use `unknown` instead of `any` for Typescript >= 3.0
237238
setNativeProps: (props: {[key: string]: any}) => void;
238239
}
240+
241+
export class FlatList<ItemT = any> extends FlatListComponent<
242+
ItemT,
243+
FlatListProps<ItemT>
244+
> {}

Libraries/Lists/SectionList.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,9 @@ export interface SectionListScrollParams {
210210
viewPosition?: number | undefined;
211211
}
212212

213-
export class SectionList<
214-
ItemT = any,
215-
SectionT = DefaultSectionT,
216-
> extends React.Component<SectionListProps<ItemT, SectionT>> {
213+
export abstract class SectionListComponent<
214+
Props,
215+
> extends React.Component<Props> {
217216
/**
218217
* Scrolls to the item at the specified sectionIndex and itemIndex (within the section)
219218
* positioned in the viewable area such that viewPosition 0 places it at the top
@@ -246,6 +245,11 @@ export class SectionList<
246245
getScrollableNode(): NodeHandle | undefined;
247246
}
248247

248+
export class SectionList<
249+
ItemT = any,
250+
SectionT = DefaultSectionT,
251+
> extends SectionListComponent<SectionListProps<ItemT, SectionT>> {}
252+
249253
/* This definition is deprecated because it extends the wrong base type */
250254
export interface SectionListStatic<ItemT, SectionT = DefaultSectionT>
251255
extends React.ComponentClass<SectionListProps<ItemT, SectionT>> {

0 commit comments

Comments
 (0)