Skip to content

Commit 13ac1a9

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Align FlatList types with OSS (#49713)
Summary: Pull Request resolved: #49713 Changelog: [Internal] Reviewed By: huntie Differential Revision: D70317013 fbshipit-source-id: f131cb204135a2a41aa7d3bafe13fc7b44446036
1 parent 569c01e commit 13ac1a9

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

packages/react-native/Libraries/Lists/FlatList.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,18 @@ function isArrayLike(data: mixed): boolean {
176176
return typeof Object(data).length === 'number';
177177
}
178178

179-
type FlatListProps<ItemT> = {
179+
type FlatListBaseProps<ItemT> = {
180180
...RequiredProps<ItemT>,
181181
...OptionalProps<ItemT>,
182182
};
183183

184184
type VirtualizedListProps = React.ElementConfig<typeof VirtualizedList>;
185185

186-
export type Props<ItemT> = {
186+
export type FlatListProps<ItemT> = {
187187
...$Diff<
188188
VirtualizedListProps,
189189
{
190+
data: $PropertyType<VirtualizedListProps, 'data'>,
190191
getItem: $PropertyType<VirtualizedListProps, 'getItem'>,
191192
getItemCount: $PropertyType<VirtualizedListProps, 'getItemCount'>,
192193
getItemLayout: $PropertyType<VirtualizedListProps, 'getItemLayout'>,
@@ -195,7 +196,7 @@ export type Props<ItemT> = {
195196
...
196197
},
197198
>,
198-
...FlatListProps<ItemT>,
199+
...FlatListBaseProps<ItemT>,
199200
...
200201
};
201202

@@ -307,7 +308,7 @@ export type Props<ItemT> = {
307308
*
308309
* Also inherits [ScrollView Props](docs/scrollview.html#props), unless it is nested in another FlatList of same orientation.
309310
*/
310-
class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
311+
class FlatList<ItemT = any> extends React.PureComponent<FlatListProps<ItemT>> {
311312
/**
312313
* Scrolls to the end of the content. May be janky without `getItemLayout` prop.
313314
*/
@@ -422,7 +423,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
422423
}
423424
}
424425

425-
constructor(props: Props<ItemT>) {
426+
constructor(props: FlatListProps<ItemT>) {
426427
super(props);
427428
this._checkProps(this.props);
428429
if (this.props.viewabilityConfigCallbackPairs) {
@@ -456,7 +457,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
456457
}
457458

458459
// $FlowFixMe[missing-local-annot]
459-
componentDidUpdate(prevProps: Props<ItemT>) {
460+
componentDidUpdate(prevProps: FlatListProps<ItemT>) {
460461
invariant(
461462
prevProps.numColumns === this.props.numColumns,
462463
'Changing numColumns on the fly is not supported. Change the key prop on FlatList when ' +
@@ -488,7 +489,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
488489
};
489490

490491
// $FlowFixMe[missing-local-annot]
491-
_checkProps(props: Props<ItemT>) {
492+
_checkProps(props: FlatListProps<ItemT>) {
492493
const {
493494
// $FlowFixMe[prop-missing] this prop doesn't exist, is only used for an invariant
494495
getItem,

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5205,15 +5205,16 @@ type OptionalProps<ItemT> = {
52055205
fadingEdgeLength?: ?number,
52065206
strictMode?: boolean,
52075207
};
5208-
type FlatListProps<ItemT> = {
5208+
type FlatListBaseProps<ItemT> = {
52095209
...RequiredProps<ItemT>,
52105210
...OptionalProps<ItemT>,
52115211
};
52125212
type VirtualizedListProps = React.ElementConfig<typeof VirtualizedList>;
5213-
export type Props<ItemT> = {
5213+
export type FlatListProps<ItemT> = {
52145214
...$Diff<
52155215
VirtualizedListProps,
52165216
{
5217+
data: $PropertyType<VirtualizedListProps, \\"data\\">,
52175218
getItem: $PropertyType<VirtualizedListProps, \\"getItem\\">,
52185219
getItemCount: $PropertyType<VirtualizedListProps, \\"getItemCount\\">,
52195220
getItemLayout: $PropertyType<VirtualizedListProps, \\"getItemLayout\\">,
@@ -5222,10 +5223,12 @@ export type Props<ItemT> = {
52225223
...
52235224
},
52245225
>,
5225-
...FlatListProps<ItemT>,
5226+
...FlatListBaseProps<ItemT>,
52265227
...
52275228
};
5228-
declare class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
5229+
declare class FlatList<ItemT = any>
5230+
extends React.PureComponent<FlatListProps<ItemT>>
5231+
{
52295232
scrollToEnd(params?: ?{ animated?: ?boolean, ... }): void;
52305233
scrollToIndex(params: {
52315234
animated?: ?boolean,
@@ -5250,8 +5253,8 @@ declare class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
52505253
| ?React.ElementRef<ScrollViewNativeComponent>;
52515254
getScrollableNode(): any;
52525255
setNativeProps(props: { [string]: mixed, ... }): void;
5253-
constructor(props: Props<ItemT>): void;
5254-
componentDidUpdate(prevProps: Props<ItemT>): void;
5256+
constructor(props: FlatListProps<ItemT>): void;
5257+
componentDidUpdate(prevProps: FlatListProps<ItemT>): void;
52555258
render(): React.Node;
52565259
}
52575260
declare export default typeof FlatList;

scripts/build/build-types/buildTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const ENTRY_POINTS = [
5454
'packages/react-native/Libraries/EventEmitter/RCTDeviceEventEmitter.js',
5555
'packages/react-native/Libraries/EventEmitter/RCTNativeAppEventEmitter.js',
5656
'packages/react-native/Libraries/LayoutAnimation/LayoutAnimation.js',
57+
'packages/react-native/Libraries/Lists/FlatList.js',
5758
'packages/react-native/Libraries/LogBox/LogBox.js',
5859
'packages/react-native/Libraries/Performance/Systrace.js',
5960
'packages/react-native/Libraries/ReactNative/AppRegistry.js',

0 commit comments

Comments
 (0)