Skip to content

Commit c884257

Browse files
Nick LefeverSaadnajmi
authored andcommitted
[fabric][a11y] Enable accessibility property assignments for View
Summary: Paper was rendering text as AXStaticText. This diff updates the `RCTParagraphComponentView` to propagate the same role in Fabric for text. This change will allow to select UI elements based on the text contents. Test Plan: Use the Accessibility Inspector in Zeratul with Fabric enabled. With the changes the text elements are presented in the a11y hierarchy with AXStaticText: {F1162808272} Reviewers: shawndempsey, chpurrer, #rn-desktop Reviewed By: chpurrer Differential Revision: https://phabricator.intern.facebook.com/D51736932 Tasks: T170938725 Tags: uikit-diff
1 parent 5962636 commit c884257

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ NS_ASSUME_NONNULL_BEGIN
5656
* transparent in favour of some subview.
5757
* Defaults to `self`.
5858
*/
59-
@property (nonatomic, strong, nullable, readonly) NSObject *accessibilityElement;
59+
@property (nonatomic, strong, nullable, readonly) RCTPlatformView *accessibilityElement; // [macOS]
6060

6161
/**
6262
* Insets used when hit testing inside this view.

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#import <React/RCTCursor.h> // [macOS]
2020
#import <React/RCTLinearGradient.h>
2121
#import <React/RCTLocalizedString.h>
22+
#import <React/UIView+React.h> // [macOS]
2223
#import <react/featureflags/ReactNativeFeatureFlags.h>
2324
#import <react/renderer/components/view/ViewComponentDescriptor.h>
2425
#import <react/renderer/components/view/ViewEventEmitter.h>
@@ -384,10 +385,13 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
384385
self.nativeId = RCTNSStringFromStringNilIfEmpty(newViewProps.nativeId);
385386
}
386387

387-
#if !TARGET_OS_OSX // [macOS]
388388
// `accessible`
389389
if (oldViewProps.accessible != newViewProps.accessible) {
390+
#if !TARGET_OS_OSX // [macOS]
390391
self.accessibilityElement.isAccessibilityElement = newViewProps.accessible;
392+
#else // [macOS
393+
self.accessibilityElement.accessibilityElement = newViewProps.accessible;
394+
#endif // macOS]
391395
}
392396

393397
// `accessibilityLabel`
@@ -403,9 +407,14 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
403407

404408
// `accessibilityHint`
405409
if (oldViewProps.accessibilityHint != newViewProps.accessibilityHint) {
410+
#if !TARGET_OS_OSX // [macOS]
406411
self.accessibilityElement.accessibilityHint = RCTNSStringFromStringNilIfEmpty(newViewProps.accessibilityHint);
412+
#else // [macOS
413+
self.accessibilityElement.accessibilityHelp = RCTNSStringFromStringNilIfEmpty(newViewProps.accessibilityHint);
414+
#endif // macOS]
407415
}
408416

417+
#if !TARGET_OS_OSX // [macOS]
409418
// `accessibilityViewIsModal`
410419
if (oldViewProps.accessibilityViewIsModal != newViewProps.accessibilityViewIsModal) {
411420
self.accessibilityElement.accessibilityViewIsModal = newViewProps.accessibilityViewIsModal;
@@ -458,6 +467,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
458467
if (oldViewProps.accessibilityIgnoresInvertColors != newViewProps.accessibilityIgnoresInvertColors) {
459468
self.accessibilityIgnoresInvertColors = newViewProps.accessibilityIgnoresInvertColors;
460469
}
470+
#endif // [macOS]
461471

462472
// `accessibilityValue`
463473
if (oldViewProps.accessibilityValue != newViewProps.accessibilityValue) {
@@ -476,8 +486,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
476486
self.accessibilityElement.accessibilityValue = nil;
477487
}
478488
}
479-
#endif // [macOS]
480-
489+
481490
// `testId`
482491
if (oldViewProps.testId != newViewProps.testId) {
483492
SEL setAccessibilityIdentifierSelector = @selector(setAccessibilityIdentifier:);
@@ -1303,7 +1312,7 @@ - (void)clearExistingBackgroundImageLayers
13031312

13041313
#pragma mark - Accessibility
13051314

1306-
- (NSObject *)accessibilityElement
1315+
- (RCTPlatformView *)accessibilityElement
13071316
{
13081317
return self;
13091318
}

0 commit comments

Comments
 (0)