Skip to content

Commit 302f3a4

Browse files
j-piaseckireact-native-bot
authored andcommitted
Update types of Animated FlatList and SectionList (#51602)
Summary: Pull Request resolved: #51602 Changelog: [GENERAL][FIXED] - Fixed the generated type definitions for `Animated.FlatList` and `Animated.SectionList` to correctly infer item types. Current definitions for animated list components cast away their generic definitions, preventing the types to be inferred from usage. This diff addresses that. Reviewed By: huntie Differential Revision: D75407762 fbshipit-source-id: c86f20298ded707971c05a78d025a63e82fe2a64
1 parent 5cc63aa commit 302f3a4

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

packages/react-native/Libraries/Animated/AnimatedExports.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const Animated: typeof AnimatedImplementation = Platform.isDisableAnimations
2525
: AnimatedImplementation;
2626

2727
export default {
28-
get FlatList(): AnimatedFlatList {
28+
get FlatList(): AnimatedFlatList<any> {
2929
return require('./components/AnimatedFlatList').default;
3030
},
3131
get Image(): AnimatedImage {
@@ -34,7 +34,7 @@ export default {
3434
get ScrollView(): AnimatedScrollView {
3535
return require('./components/AnimatedScrollView').default;
3636
},
37-
get SectionList(): AnimatedSectionList {
37+
get SectionList(): AnimatedSectionList<any, any> {
3838
return require('./components/AnimatedSectionList').default;
3939
},
4040
get Text(): AnimatedText {

packages/react-native/Libraries/Animated/components/AnimatedFlatList.js

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

11-
import type {AnimatedComponentType} from '../createAnimatedComponent';
11+
import type {AnimatedProps} from '../createAnimatedComponent';
1212

13-
import FlatList from '../../Lists/FlatList';
13+
import FlatList, {type FlatListProps} from '../../Lists/FlatList';
1414
import createAnimatedComponent from '../createAnimatedComponent';
1515
import * as React from 'react';
1616

17-
export default (createAnimatedComponent(FlatList): AnimatedComponentType<
18-
React.ElementConfig<typeof FlatList>,
19-
FlatList<mixed>,
20-
>);
17+
// $FlowExpectedError[unclear-type]
18+
export default (createAnimatedComponent(FlatList): component<ItemT = any>(
19+
ref?: React.RefSetter<FlatList<ItemT>>,
20+
...props: AnimatedProps<FlatListProps<ItemT>>
21+
));

packages/react-native/Libraries/Animated/components/AnimatedSectionList.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88
* @format
99
*/
1010

11-
import type {SectionBase} from '../../Lists/SectionList';
12-
import type {AnimatedComponentType} from '../createAnimatedComponent';
11+
import type {AnimatedProps} from '../createAnimatedComponent';
1312

14-
import SectionList from '../../Lists/SectionList';
13+
import SectionList, {type SectionListProps} from '../../Lists/SectionList';
1514
import createAnimatedComponent from '../createAnimatedComponent';
1615
import * as React from 'react';
1716

18-
export default (createAnimatedComponent(SectionList): AnimatedComponentType<
19-
React.ElementConfig<typeof SectionList>,
17+
// $FlowFixMe
18+
export default (createAnimatedComponent(SectionList): component<
2019
// $FlowExpectedError[unclear-type]
21-
SectionList<any, SectionBase<any>>,
22-
>);
20+
ItemT = any,
21+
// $FlowExpectedError[unclear-type]
22+
SectionT = any,
23+
>(
24+
ref?: React.RefSetter<SectionList<ItemT, SectionT>>,
25+
...props: AnimatedProps<SectionListProps<ItemT, SectionT>>
26+
));

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ declare export class AnimatedEvent {
156156
exports[`public API should not change unintentionally Libraries/Animated/AnimatedExports.js 1`] = `
157157
"declare const Animated: typeof AnimatedImplementation;
158158
declare export default {
159-
get FlatList(): AnimatedFlatList,
159+
get FlatList(): AnimatedFlatList<any>,
160160
get Image(): AnimatedImage,
161161
get ScrollView(): AnimatedScrollView,
162-
get SectionList(): AnimatedSectionList,
162+
get SectionList(): AnimatedSectionList<any, any>,
163163
get Text(): AnimatedText,
164164
get View(): AnimatedView,
165165
...typeof Animated,
@@ -614,10 +614,10 @@ exports[`public API should not change unintentionally Libraries/Animated/bezier.
614614
`;
615615

616616
exports[`public API should not change unintentionally Libraries/Animated/components/AnimatedFlatList.js 1`] = `
617-
"declare export default AnimatedComponentType<
618-
React.ElementConfig<typeof FlatList>,
619-
FlatList<mixed>,
620-
>;
617+
"declare export default component<ItemT = any>(
618+
ref?: React.RefSetter<FlatList<ItemT>>,
619+
...props: AnimatedProps<FlatListProps<ItemT>>
620+
);
621621
"
622622
`;
623623

@@ -641,10 +641,10 @@ declare export default typeof AnimatedScrollView;
641641
`;
642642

643643
exports[`public API should not change unintentionally Libraries/Animated/components/AnimatedSectionList.js 1`] = `
644-
"declare export default AnimatedComponentType<
645-
React.ElementConfig<typeof SectionList>,
646-
SectionList<any, SectionBase<any>>,
647-
>;
644+
"declare export default component<ItemT = any, SectionT = any>(
645+
ref?: React.RefSetter<SectionList<ItemT, SectionT>>,
646+
...props: AnimatedProps<SectionListProps<ItemT, SectionT>>
647+
);
648648
"
649649
`;
650650

0 commit comments

Comments
 (0)