Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/animated lists types #36292

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions Libraries/Animated/Animated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ import type * as React from 'react';
import {ScrollView} from '../Components/ScrollView/ScrollView';
import {View} from '../Components/View/View';
import {Image} from '../Image/Image';
import {FlatListProps} from '../Lists/FlatList';
import {DefaultSectionT, SectionListProps} from '../Lists/SectionList';
import {FlatListComponent, FlatListProps} from '../Lists/FlatList';
import {
DefaultSectionT,
SectionListComponent,
SectionListProps,
} from '../Lists/SectionList';
import {NodeHandle} from '../ReactNative/RendererProxy';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NodeHandle is not in use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed unused type. thank you.

import {ColorValue} from '../StyleSheet/StyleSheet';
import {Text} from '../Text/Text';
import {NativeSyntheticEvent} from '../Types/CoreEventTypes';
Expand Down Expand Up @@ -598,13 +603,18 @@ export namespace Animated {
/**
* FlatList and SectionList infer generic Type defined under their `data` and `section` props.
*/
export class FlatList<ItemT = any> extends React.Component<

export class FlatList<ItemT = any> extends FlatListComponent<
ItemT,
AnimatedProps<FlatListProps<ItemT>>
> {}

export class SectionList<
ItemT = any,
SectionT = DefaultSectionT,
> extends React.Component<AnimatedProps<SectionListProps<ItemT, SectionT>>> {}
> extends SectionListComponent<
AnimatedProps<SectionListProps<ItemT, SectionT>>
> {}
}

// We need to alias these views so we can reference them in the Animated
Expand Down
12 changes: 9 additions & 3 deletions Libraries/Lists/FlatList.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,10 @@ export interface FlatListProps<ItemT> extends VirtualizedListProps<ItemT> {
fadingEdgeLength?: number | undefined;
}

export class FlatList<ItemT = any> extends React.Component<
FlatListProps<ItemT>
> {
export abstract class FlatListComponent<
ItemT,
Props,
> extends React.Component<Props> {
/**
* Scrolls to the end of the content. May be janky without `getItemLayout` prop.
*/
Expand Down Expand Up @@ -236,3 +237,8 @@ export class FlatList<ItemT = any> extends React.Component<
// TODO: use `unknown` instead of `any` for Typescript >= 3.0
setNativeProps: (props: {[key: string]: any}) => void;
}

export class FlatList<ItemT = any> extends FlatListComponent<
ItemT,
FlatListProps<ItemT>
> {}
12 changes: 8 additions & 4 deletions Libraries/Lists/SectionList.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,9 @@ export interface SectionListScrollParams {
viewPosition?: number | undefined;
}

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

export class SectionList<
ItemT = any,
SectionT = DefaultSectionT,
> extends SectionListComponent<SectionListProps<ItemT, SectionT>> {}

/* This definition is deprecated because it extends the wrong base type */
export interface SectionListStatic<ItemT, SectionT = DefaultSectionT>
extends React.ComponentClass<SectionListProps<ItemT, SectionT>> {
Expand Down