Skip to content

Commit 4271a9c

Browse files
committed
Forward port away from deprecated React.ElementRef to React.ComponentRef
- Note Typescript has this chance, Flow does not have ComponentRef type, so this is typescript-only and Flow did not need a similar change
1 parent 43f464b commit 4271a9c

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

packages/react-native-codegen/src/parsers/typescript/components/__test_fixtures__/fixtures.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,17 +1062,17 @@ export interface ModuleProps extends ViewProps {
10621062
type NativeType = HostComponent<ModuleProps>;
10631063
10641064
interface NativeCommands {
1065-
readonly handleRootTag: (viewRef: React.ElementRef<NativeType>, rootTag: RootTag) => void;
1066-
readonly hotspotUpdate: (viewRef: React.ElementRef<NativeType>, x: Int32, y: Int32) => void;
1065+
readonly handleRootTag: (viewRef: React.ComponentRef<NativeType>, rootTag: RootTag) => void;
1066+
readonly hotspotUpdate: (viewRef: React.ComponentRef<NativeType>, x: Int32, y: Int32) => void;
10671067
scrollTo(
1068-
viewRef: React.ElementRef<NativeType>,
1068+
viewRef: React.ComponentRef<NativeType>,
10691069
x: Float,
10701070
y: Int32,
10711071
z: Double,
10721072
animated: boolean,
10731073
): void;
10741074
readonly arrayArgs: (
1075-
viewRef: React.ElementRef<NativeType>,
1075+
viewRef: React.ComponentRef<NativeType>,
10761076
booleanArray: ReadOnlyArray<boolean>,
10771077
stringArray: ReadOnlyArray<string>,
10781078
floatArray: ReadOnlyArray<Float>,
@@ -1122,12 +1122,12 @@ export interface ModuleProps extends ViewProps {
11221122
type NativeType = HostComponent<ModuleProps>;
11231123
11241124
export type ScrollTo = (
1125-
viewRef: React.ElementRef<NativeType>,
1125+
viewRef: React.ComponentRef<NativeType>,
11261126
y: Int,
11271127
animated: Boolean,
11281128
) => Void;
11291129
export type AddOverlays = (
1130-
viewRef: React.ElementRef<NativeType>,
1130+
viewRef: React.ComponentRef<NativeType>,
11311131
overlayColorsReadOnly: ReadOnlyArray<string>,
11321132
overlayColorsArray: Array<string>,
11331133
overlayColorsArrayAnnotation: string[],
@@ -1193,7 +1193,7 @@ export interface ModuleNativeState {
11931193
11941194
type NativeType = HostComponent<ModuleProps>;
11951195
1196-
export type ScrollTo = (viewRef: React.ElementRef<NativeType>, y: Int, animated: Boolean) => Void;
1196+
export type ScrollTo = (viewRef: React.ComponentRef<NativeType>, y: Int, animated: Boolean) => Void;
11971197
11981198
interface NativeCommands {
11991199
readonly scrollTo: ScrollTo;
@@ -2184,17 +2184,17 @@ export interface ModuleProps extends ViewProps {
21842184
type NativeType = HostComponent<ModuleProps>;
21852185
21862186
interface NativeCommands {
2187-
readonly handleRootTag: (viewRef: React.ElementRef<NativeType>, rootTag: RootTag) => void;
2188-
readonly hotspotUpdate: (viewRef: React.ElementRef<NativeType>, x: CodegenTypes.Int32, y: CodegenTypes.Int32) => void;
2187+
readonly handleRootTag: (viewRef: React.ComponentRef<NativeType>, rootTag: RootTag) => void;
2188+
readonly hotspotUpdate: (viewRef: React.ComponentRef<NativeType>, x: CodegenTypes.Int32, y: CodegenTypes.Int32) => void;
21892189
scrollTo(
2190-
viewRef: React.ElementRef<NativeType>,
2190+
viewRef: React.ComponentRef<NativeType>,
21912191
x: CodegenTypes.Float,
21922192
y: CodegenTypes.Int32,
21932193
z: CodegenTypes.Double,
21942194
animated: boolean,
21952195
): void;
21962196
readonly arrayArgs: (
2197-
viewRef: React.ElementRef<NativeType>,
2197+
viewRef: React.ComponentRef<NativeType>,
21982198
booleanArray: ReadOnlyArray<boolean>,
21992199
stringArray: ReadOnlyArray<string>,
22002200
floatArray: ReadOnlyArray<CodegenTypes.Float>,
@@ -2243,12 +2243,12 @@ export interface ModuleProps extends ViewProps {
22432243
type NativeType = HostComponent<ModuleProps>;
22442244
22452245
export type ScrollTo = (
2246-
viewRef: React.ElementRef<NativeType>,
2246+
viewRef: React.ComponentRef<NativeType>,
22472247
y: Int,
22482248
animated: Boolean,
22492249
) => Void;
22502250
export type AddOverlays = (
2251-
viewRef: React.ElementRef<NativeType>,
2251+
viewRef: React.ComponentRef<NativeType>,
22522252
overlayColorsReadOnly: ReadOnlyArray<string>,
22532253
overlayColorsArray: Array<string>,
22542254
overlayColorsArrayAnnotation: string[],
@@ -2310,7 +2310,7 @@ export interface ModuleNativeState {
23102310
23112311
type NativeType = HostComponent<ModuleProps>;
23122312
2313-
export type ScrollTo = (viewRef: React.ElementRef<NativeType>, y: Int, animated: Boolean) => Void;
2313+
export type ScrollTo = (viewRef: React.ComponentRef<NativeType>, y: Int, animated: Boolean) => Void;
23142314
23152315
interface NativeCommands {
23162316
readonly scrollTo: ScrollTo;

packages/react-native-codegen/src/parsers/typescript/components/__tests__/__snapshots__/typescript-component-parser-test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ exports[`RN Codegen TypeScript Parser Fails with error message COMMANDS_DEFINED_
66

77
exports[`RN Codegen TypeScript Parser Fails with error message COMMANDS_DEFINED_WITH_MISMATCHED_METHOD_NAMES 1`] = `"codegenNativeCommands expected the same supportedCommands specified in the NativeCommands interface: hotspotUpdate, scrollTo"`;
88

9-
exports[`RN Codegen TypeScript Parser Fails with error message COMMANDS_DEFINED_WITH_NULLABLE_REF 1`] = `"The first argument of method hotspotUpdate must be of type React.ElementRef<>"`;
9+
exports[`RN Codegen TypeScript Parser Fails with error message COMMANDS_DEFINED_WITH_NULLABLE_REF 1`] = `"The first argument of method hotspotUpdate must be of type React.ElementRef<> or React.ComponentRef<>"`;
1010

1111
exports[`RN Codegen TypeScript Parser Fails with error message COMMANDS_DEFINED_WITHOUT_METHOD_NAMES 1`] = `"codegenNativeCommands must be passed options including the supported commands"`;
1212

13-
exports[`RN Codegen TypeScript Parser Fails with error message COMMANDS_DEFINED_WITHOUT_REF 1`] = `"The first argument of method hotspotUpdate must be of type React.ElementRef<>"`;
13+
exports[`RN Codegen TypeScript Parser Fails with error message COMMANDS_DEFINED_WITHOUT_REF 1`] = `"The first argument of method hotspotUpdate must be of type React.ElementRef<> or React.ComponentRef<>"`;
1414

1515
exports[`RN Codegen TypeScript Parser Fails with error message NON_OPTIONAL_KEY_WITH_DEFAULT_VALUE 1`] = `"key required_key_with_default must be optional if used with WithDefault<> annotation"`;
1616

packages/react-native-codegen/src/parsers/typescript/components/commands.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ function buildCommandSchemaInternal(
3838
firstParam.typeAnnotation != null &&
3939
firstParam.typeAnnotation.type === 'TSTypeReference' &&
4040
firstParam.typeAnnotation.typeName.left?.name === 'React' &&
41-
firstParam.typeAnnotation.typeName.right?.name === 'ElementRef'
41+
(firstParam.typeAnnotation.typeName.right?.name === 'ElementRef' ||
42+
firstParam.typeAnnotation.typeName.right?.name === 'ComponentRef')
4243
)
4344
) {
4445
throw new Error(
45-
`The first argument of method ${name} must be of type React.ElementRef<>`,
46+
`The first argument of method ${name} must be of type React.ElementRef<> or React.ComponentRef<>`,
4647
);
4748
}
4849

0 commit comments

Comments
 (0)