Skip to content

Commit 2bd0106

Browse files
SamChou19815meta-codesync[bot]
authored andcommitted
Replace React.ElementConfig with React.ComponentProps in react-native (#58931)
Summary: Pull Request resolved: #58931 The goal is to align the react types names with TS. Changelog: [Internal] ___ Differential Revision: D123880261 fbshipit-source-id: f9dc4cbc1a3c0f155f26d4335466a3958e265c63
1 parent c2da175 commit 2bd0106

12 files changed

Lines changed: 23 additions & 26 deletions

File tree

‎packages/react-native/Libraries/Animated/components/AnimatedImage.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @format
99
*/
1010

11+
import type {ImageProps} from '../../Image/ImageProps';
1112
import type {AnimatedComponentType} from '../createAnimatedComponent';
1213

1314
import Image from '../../Image/Image';
@@ -18,6 +19,6 @@ export default createAnimatedComponent<
1819
$FlowFixMe,
1920
React.ElementRef<typeof Image>,
2021
>(Image as $FlowFixMe) as AnimatedComponentType<
21-
React.ElementConfig<typeof Image>,
22+
ImageProps,
2223
React.ElementRef<typeof Image>,
2324
>;

‎packages/react-native/Libraries/Animated/components/AnimatedScrollView.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const AnimatedScrollViewWithInvertedRefreshControl =
8080
...props
8181
}: {
8282
ref?: React.RefSetter<AnimatedScrollViewInstance>,
83-
...React.ElementConfig<typeof ScrollView>,
83+
...React.ComponentProps<typeof ScrollView>,
8484
// $FlowFixMe[unclear-type] Same Flow type as `refreshControl` in ScrollView
8585
refreshControl: React.MixedElement,
8686
}) {

‎packages/react-native/Libraries/Animated/createAnimatedComponent.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import {useMemo} from 'react';
3030
type Nullable = void | null;
3131
type Primitive = string | number | boolean | symbol | void;
3232
type Builtin = (...ReadonlyArray<empty>) => unknown | Date | Error | RegExp;
33+
type ComponentProps<T> =
34+
T extends React.ComponentType<infer Props> ? Props : empty;
3335

3436
export type WithAnimatedValue<out T> = T extends Builtin | Nullable
3537
? T
@@ -98,7 +100,7 @@ export default function createAnimatedComponent<
98100
>(
99101
Component: TInstance,
100102
): AnimatedComponentType<
101-
Readonly<React.ElementConfig<TInstance>>,
103+
Readonly<ComponentProps<TInstance>>,
102104
React.ElementRef<TInstance>,
103105
> {
104106
return unstable_createAnimatedComponentWithAllowlist(Component, null);

‎packages/react-native/Libraries/Components/Pressable/Pressable.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ function Pressable({
270270
ariaLive === 'off' ? 'none' : (ariaLive ?? props.accessibilityLiveRegion);
271271

272272
const accessibilityLabel = ariaLabel ?? props.accessibilityLabel;
273-
const restPropsWithDefaults: React.ElementConfig<typeof View> = {
273+
const restPropsWithDefaults: React.ComponentProps<typeof View> = {
274274
...restProps,
275275
...android_rippleConfig?.viewProps,
276276
accessible: accessible !== false,

‎packages/react-native/Libraries/Components/TextInput/TextInput.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ const autoCompleteWebToTextContentTypeMap = {
898898
*/
899899
const TextInput: component(
900900
ref?: React.RefSetter<TextInputInstance>,
901-
...props: React.ElementConfig<typeof InternalTextInput>
901+
...props: React.ComponentProps<typeof InternalTextInput>
902902
) = function TextInput({
903903
ref: forwardedRef,
904904
allowFontScaling = true,
@@ -916,7 +916,7 @@ const TextInput: component(
916916
...restProps
917917
}: {
918918
ref?: React.RefSetter<TextInputInstance>,
919-
...React.ElementConfig<typeof InternalTextInput>,
919+
...React.ComponentProps<typeof InternalTextInput>,
920920
}) {
921921
return (
922922
<InternalTextInput

‎packages/react-native/ReactNativeApi.d.ts‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<3ce9599aceb36dd1f09ded3db3332daa>>
7+
* @generated SignedSource<<83faf91fab56f9b954a3bb7cfdef59e1>>
88
*
99
* This file was generated by scripts/js-api/build-types/index.js.
1010
*/
@@ -24,10 +24,7 @@
2424
import * as React from "react"
2525
declare const $$AnimatedFlatList: typeof AnimatedFlatList_default
2626
declare const $$AnimatedImage: AnimatedComponentType<
27-
React.JSX.LibraryManagedAttributes<
28-
typeof Image,
29-
React.ComponentProps<typeof Image>
30-
>,
27+
ImageProps,
3128
React.ComponentRef<typeof Image>
3229
>
3330
declare const $$AnimatedImplementation: {
@@ -1748,6 +1745,8 @@ declare type ColorListenerCallback = (value: ColorValue) => unknown
17481745
declare type ColorSchemeName = "dark" | "light"
17491746
declare type ColorSchemeOverride = "auto" | "dark" | "light" | "unspecified"
17501747
declare type ColorValue = ____ColorValue_Internal
1748+
declare type ComponentProps<T> =
1749+
T extends React.ComponentType<infer Props> ? Props : never
17511750
declare type ComponentProvider = () => React.ComponentType<any>
17521751
declare type ComponentProviderInstrumentationHook = (
17531752
component_: ComponentProvider,
@@ -1799,12 +1798,7 @@ declare function createAnimatedComponent_default<
17991798
>(
18001799
Component: TInstance,
18011800
): AnimatedComponentType<
1802-
Readonly<
1803-
React.JSX.LibraryManagedAttributes<
1804-
TInstance,
1805-
React.ComponentProps<TInstance>
1806-
>
1807-
>,
1801+
Readonly<ComponentProps<TInstance>>,
18081802
React.ComponentRef<TInstance>
18091803
>
18101804
declare function createLayoutAnimation(
@@ -5771,7 +5765,7 @@ export {
57715765
AlertOptions, // 8a116d2a
57725766
AlertType, // 5ab91217
57735767
AndroidKeyboardEvent, // e03becc8
5774-
Animated, // 990adcb6
5768+
Animated, // ed4648e6
57755769
AppConfig, // 35c0ca70
57765770
AppRegistry, // edec2a30
57775771
AppState, // 12012be5

‎packages/rn-tester/js/components/RNTPressableRow.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import * as React from 'react';
1414
import {useContext} from 'react';
1515
import {Pressable, StyleSheet, Text, View} from 'react-native';
1616

17-
type ViewStyleProp = React.ElementConfig<typeof View>['style'];
17+
type ViewStyleProp = React.ComponentProps<typeof View>['style'];
1818
type Props = {
1919
accessibilityLabel?: ?string,
2020
testID?: ?string,

‎packages/rn-tester/js/examples/Animated/utils/ToggleNativeDriver.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import * as React from 'react';
1313
import {useContext} from 'react';
1414
import {StyleSheet, Switch, Text, View} from 'react-native';
1515

16-
type ViewStyleProp = React.ElementConfig<typeof View>['style'];
16+
type ViewStyleProp = React.ComponentProps<typeof View>['style'];
1717

1818
type Props = {
1919
value: boolean,
20-
onValueChange: React.ElementConfig<typeof Switch>['onValueChange'],
20+
onValueChange: React.ComponentProps<typeof Switch>['onValueChange'],
2121
style?: ?ViewStyleProp,
2222
};
2323

‎packages/rn-tester/js/examples/FlatList/BaseFlatListExample.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const Item = ({item, separators}: ListRenderItemInfo<string>) => {
6060
};
6161

6262
type Props = Readonly<{
63-
exampleProps: Partial<React.ElementConfig<typeof FlatList>>,
63+
exampleProps: Partial<React.ComponentProps<typeof FlatList>>,
6464
exampleTestID?: ?string,
6565
onTest?: ?() => void,
6666
testLabel?: ?string,

‎packages/rn-tester/js/examples/SectionList/SectionListBaseExample.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const Item = ({item, section, separators}) => {
6666

6767
type Props = Readonly<{
6868
// $FlowFixMe[unclear-type]
69-
exampleProps: Partial<React.ElementConfig<typeof SectionList<any>>>,
69+
exampleProps: Partial<React.ComponentProps<typeof SectionList<any>>>,
7070
exampleTestID?: ?string,
7171
onTest?: ?() => void,
7272
testLabel?: ?string,

0 commit comments

Comments
 (0)