Skip to content

Commit af65324

Browse files
committed
Forward port away from deprecated React.ElementRef to React.ComponentRef
1 parent 43f464b commit af65324

File tree

6 files changed

+38
-36
lines changed

6 files changed

+38
-36
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -948,17 +948,17 @@ export type ModuleProps = $ReadOnly<{|
948948
type NativeType = HostComponent<ModuleProps>;
949949
950950
interface NativeCommands {
951-
+handleRootTag: (viewRef: React.ElementRef<NativeType>, rootTag: RootTag) => void;
952-
+hotspotUpdate: (viewRef: React.ElementRef<NativeType>, x: Int32, y: Int32) => void;
951+
+handleRootTag: (viewRef: React.ComponentRef<NativeType>, rootTag: RootTag) => void;
952+
+hotspotUpdate: (viewRef: React.ComponentRef<NativeType>, x: Int32, y: Int32) => void;
953953
scrollTo(
954-
viewRef: React.ElementRef<NativeType>,
954+
viewRef: React.ComponentRef<NativeType>,
955955
x: Float,
956956
y: Int32,
957957
z: Double,
958958
animated: boolean,
959959
): void;
960960
+arrayArgs: (
961-
viewRef: React.ElementRef<NativeType>,
961+
viewRef: React.ComponentRef<NativeType>,
962962
booleanArray: $ReadOnlyArray<boolean>,
963963
stringArray: $ReadOnlyArray<string>,
964964
floatArray: $ReadOnlyArray<Float>,
@@ -1012,15 +1012,15 @@ export type ModuleProps = $ReadOnly<{|
10121012
type NativeType = HostComponent<ModuleProps>;
10131013
10141014
export type ScrollTo = (
1015-
viewRef: React.ElementRef<NativeType>,
1015+
viewRef: React.ComponentRef<NativeType>,
10161016
y: Int,
10171017
animated: Boolean,
10181018
) => Void;
10191019
10201020
interface NativeCommands {
10211021
+scrollTo: ScrollTo;
10221022
+addOverlays: (
1023-
viewRef: React.ElementRef<NativeType>,
1023+
viewRef: React.ComponentRef<NativeType>,
10241024
overlayColorsReadOnly: $ReadOnlyArray<string>,
10251025
overlayColorsArray: Array<string>,
10261026
overlayColorsArrayAnnotation: string[],
@@ -1081,7 +1081,7 @@ export type ModuleProps = $ReadOnly<{|
10811081
10821082
type NativeType = HostComponent<ModuleProps>;
10831083
1084-
export type ScrollTo = (viewRef: React.ElementRef<NativeType>, y: Int, animated: Boolean) => Void;
1084+
export type ScrollTo = (viewRef: React.ComponentRef<NativeType>, y: Int, animated: Boolean) => Void;
10851085
10861086
interface NativeCommands {
10871087
+scrollTo: ScrollTo;
@@ -1903,17 +1903,17 @@ export type ModuleProps = $ReadOnly<{|
19031903
type NativeType = HostComponent<ModuleProps>;
19041904
19051905
interface NativeCommands {
1906-
+handleRootTag: (viewRef: React.ElementRef<NativeType>, rootTag: RootTag) => void;
1907-
+hotspotUpdate: (viewRef: React.ElementRef<NativeType>, x: CodegenTypes.Int32, y: CodegenTypes.Int32) => void;
1906+
+handleRootTag: (viewRef: React.ComponentRef<NativeType>, rootTag: RootTag) => void;
1907+
+hotspotUpdate: (viewRef: React.ComponentRef<NativeType>, x: CodegenTypes.Int32, y: CodegenTypes.Int32) => void;
19081908
scrollTo(
1909-
viewRef: React.ElementRef<NativeType>,
1909+
viewRef: React.ComponentRef<NativeType>,
19101910
x: CodegenTypes.Float,
19111911
y: CodegenTypes.Int32,
19121912
z: CodegenTypes.Double,
19131913
animated: boolean,
19141914
): void;
19151915
+arrayArgs: (
1916-
viewRef: React.ElementRef<NativeType>,
1916+
viewRef: React.ComponentRef<NativeType>,
19171917
booleanArray: $ReadOnlyArray<boolean>,
19181918
stringArray: $ReadOnlyArray<string>,
19191919
floatArray: $ReadOnlyArray<CodegenTypes.Float>,
@@ -1966,15 +1966,15 @@ export type ModuleProps = $ReadOnly<{|
19661966
type NativeType = HostComponent<ModuleProps>;
19671967
19681968
export type ScrollTo = (
1969-
viewRef: React.ElementRef<NativeType>,
1969+
viewRef: React.ComponentRef<NativeType>,
19701970
y: Int,
19711971
animated: Boolean,
19721972
) => Void;
19731973
19741974
interface NativeCommands {
19751975
+scrollTo: ScrollTo;
19761976
+addOverlays: (
1977-
viewRef: React.ElementRef<NativeType>,
1977+
viewRef: React.ComponentRef<NativeType>,
19781978
overlayColorsReadOnly: $ReadOnlyArray<string>,
19791979
overlayColorsArray: Array<string>,
19801980
overlayColorsArrayAnnotation: string[],
@@ -2031,7 +2031,7 @@ export type ModuleProps = $ReadOnly<{|
20312031
20322032
type NativeType = HostComponent<ModuleProps>;
20332033
2034-
export type ScrollTo = (viewRef: React.ElementRef<NativeType>, y: Int, animated: Boolean) => Void;
2034+
export type ScrollTo = (viewRef: React.ComponentRef<NativeType>, y: Int, animated: Boolean) => Void;
20352035
20362036
interface NativeCommands {
20372037
+scrollTo: ScrollTo;

packages/react-native-codegen/src/parsers/flow/components/__tests__/__snapshots__/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 Flow Parser Fails with error message COMMANDS_DEFINED_MULTIP
66

77
exports[`RN Codegen Flow 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 Flow 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 Flow 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 Flow 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 Flow 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 Flow 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 Flow 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/flow/components/commands.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ function buildCommandSchema(
5454
firstParam.id != null &&
5555
firstParam.id.type === 'QualifiedTypeIdentifier' &&
5656
firstParam.id.qualification.name === 'React' &&
57-
firstParam.id.id.name === 'ElementRef'
57+
(firstParam.id.id.name === 'ElementRef' ||
58+
firstParam.id.id.name === 'ComponentRef')
5859
)
5960
) {
6061
throw new Error(
61-
`The first argument of method ${name} must be of type React.ElementRef<>`,
62+
`The first argument of method ${name} must be of type React.ElementRef<> or React.ComponentRef<>`,
6263
);
6364
}
6465

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)