Skip to content

Commit ba9b1db

Browse files
committed
Merge branch 'main' into fix/rntester-tests
2 parents d06f46b + 4c732b4 commit ba9b1db

50 files changed

Lines changed: 1114 additions & 143 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.flowconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,4 @@ untyped-import
9898
untyped-type-import
9999

100100
[version]
101-
^0.290.0
101+
^0.291.0

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"eslint-plugin-relay": "^1.8.3",
8787
"fb-dotslash": "0.5.8",
8888
"flow-api-translator": "0.32.0",
89-
"flow-bin": "^0.290.0",
89+
"flow-bin": "^0.291.0",
9090
"glob": "^7.1.1",
9191
"hermes-eslint": "0.32.0",
9292
"hermes-transform": "0.32.0",

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

packages/react-native/Libraries/Text/Text.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
4545
ref: forwardedRef,
4646
accessible,
4747
accessibilityLabel,
48+
accessibilityRole,
4849
accessibilityState,
4950
allowFontScaling,
5051
'aria-busy': ariaBusy,
@@ -71,6 +72,7 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
7172
onResponderTerminationRequest,
7273
onStartShouldSetResponder,
7374
pressRetentionOffset,
75+
role,
7476
selectable,
7577
selectionColor,
7678
suppressHighlighting,
@@ -149,6 +151,17 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
149151
onStartShouldSetResponder != null) &&
150152
_disabled !== true;
151153

154+
const shouldUseLinkRole =
155+
ReactNativeFeatureFlags.shouldUseLinkRoleForPressableText() &&
156+
isPressable &&
157+
accessibilityRole == null &&
158+
role == null;
159+
160+
const _accessibilityRole =
161+
accessibilityRole ?? (shouldUseLinkRole ? 'link' : undefined);
162+
163+
const _role = shouldUseLinkRole ? undefined : role;
164+
152165
// TODO: Move this processing to the view configuration.
153166
const _selectionColor =
154167
selectionColor != null ? processColor(selectionColor) : undefined;
@@ -206,6 +219,9 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
206219
if (_accessibilityLabel !== undefined) {
207220
processedProps.accessibilityLabel = _accessibilityLabel;
208221
}
222+
if (_accessibilityRole !== undefined) {
223+
processedProps.accessibilityRole = _accessibilityRole;
224+
}
209225
if (_accessibilityState !== undefined) {
210226
processedProps.accessibilityState = _accessibilityState;
211227
}
@@ -224,6 +240,9 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
224240
if (_selectionColor !== undefined) {
225241
processedProps.selectionColor = _selectionColor;
226242
}
243+
if (_role !== undefined) {
244+
processedProps.role = _role;
245+
}
227246

228247
let textPressabilityProps: ?TextPressabilityProps;
229248
if (isPressable) {
@@ -317,6 +336,7 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
317336
accessibilityElementsHidden,
318337
importantForAccessibility,
319338
accessibilityLabel,
339+
accessibilityRole,
320340
accessibilityState,
321341
allowFontScaling,
322342
'aria-busy': ariaBusy,
@@ -343,6 +363,7 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
343363
onResponderTerminationRequest,
344364
onStartShouldSetResponder,
345365
pressRetentionOffset,
366+
role,
346367
selectable,
347368
selectionColor,
348369
suppressHighlighting,
@@ -398,6 +419,17 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
398419
onStartShouldSetResponder != null) &&
399420
_disabled !== true;
400421

422+
const shouldUseLinkRole =
423+
ReactNativeFeatureFlags.shouldUseLinkRoleForPressableText() &&
424+
isPressable &&
425+
accessibilityRole == null &&
426+
role == null;
427+
428+
const _accessibilityRole =
429+
accessibilityRole ?? (shouldUseLinkRole ? 'link' : undefined);
430+
431+
const _role = shouldUseLinkRole ? undefined : role;
432+
401433
// TODO: Move this processing to the view configuration.
402434
const _selectionColor =
403435
selectionColor != null ? processColor(selectionColor) : undefined;
@@ -462,6 +494,7 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
462494
...restProps,
463495
accessibilityElementsHidden: _accessibilityElementsHidden,
464496
accessibilityLabel: _accessibilityLabel,
497+
accessibilityRole: _accessibilityRole,
465498
accessibilityState: _accessibilityState,
466499
importantForAccessibility: _importantForAccessibility,
467500
nativeID: _nativeID,
@@ -470,6 +503,7 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
470503
selectionColor: _selectionColor,
471504
style: _style,
472505
disabled: disabled,
506+
role: _role,
473507
children,
474508
}}
475509
textPressabilityProps={{
@@ -495,6 +529,7 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
495529
{...restProps}
496530
accessibilityElementsHidden={_accessibilityElementsHidden}
497531
accessibilityLabel={_accessibilityLabel}
532+
accessibilityRole={_accessibilityRole}
498533
accessibilityState={_accessibilityState}
499534
importantForAccessibility={_importantForAccessibility}
500535
nativeID={_nativeID}
@@ -503,7 +538,8 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
503538
selectable={_selectable}
504539
selectionColor={_selectionColor}
505540
style={_style}
506-
disabled={disabled}>
541+
disabled={disabled}
542+
role={_role}>
507543
{children}
508544
</NativeVirtualText>
509545
);
@@ -538,6 +574,7 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
538574
...restProps,
539575
accessibilityElementsHidden: _accessibilityElementsHidden,
540576
accessibilityLabel: _accessibilityLabel,
577+
accessibilityRole: _accessibilityRole,
541578
accessibilityState: _accessibilityState,
542579
accessible: _accessible,
543580
allowFontScaling: allowFontScaling !== false,
@@ -549,6 +586,7 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
549586
selectable: _selectable,
550587
selectionColor: _selectionColor,
551588
style: _style,
589+
role: _role,
552590
children,
553591
}}
554592
textPressabilityProps={{
@@ -573,6 +611,7 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
573611
{...restProps}
574612
accessibilityElementsHidden={_accessibilityElementsHidden}
575613
accessibilityLabel={_accessibilityLabel}
614+
accessibilityRole={_accessibilityRole}
576615
accessibilityState={_accessibilityState}
577616
accessible={_accessible}
578617
allowFontScaling={allowFontScaling !== false}
@@ -584,7 +623,8 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
584623
ref={forwardedRef}
585624
selectable={_selectable}
586625
selectionColor={_selectionColor}
587-
style={_style}>
626+
style={_style}
627+
role={_role}>
588628
{children}
589629
</NativeText>
590630
);

0 commit comments

Comments
 (0)