Skip to content

Commit 7e49794

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 bf133b9 commit 7e49794

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
@@ -17,6 +17,7 @@
1717
#import <React/RCTConversions.h>
1818
#import <React/RCTCursor.h> // [macOS]
1919
#import <React/RCTLocalizedString.h>
20+
#import <React/UIView+React.h> // [macOS]
2021
#import <react/featureflags/ReactNativeFeatureFlags.h>
2122
#import <react/renderer/components/view/ViewComponentDescriptor.h>
2223
#import <react/renderer/components/view/ViewEventEmitter.h>
@@ -373,10 +374,13 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
373374
self.nativeId = RCTNSStringFromStringNilIfEmpty(newViewProps.nativeId);
374375
}
375376

376-
#if !TARGET_OS_OSX // [macOS]
377377
// `accessible`
378378
if (oldViewProps.accessible != newViewProps.accessible) {
379+
#if !TARGET_OS_OSX // [macOS]
379380
self.accessibilityElement.isAccessibilityElement = newViewProps.accessible;
381+
#else // [macOS
382+
self.accessibilityElement.accessibilityElement = newViewProps.accessible;
383+
#endif // macOS]
380384
}
381385

382386
// `accessibilityLabel`
@@ -392,9 +396,14 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
392396

393397
// `accessibilityHint`
394398
if (oldViewProps.accessibilityHint != newViewProps.accessibilityHint) {
399+
#if !TARGET_OS_OSX // [macOS]
395400
self.accessibilityElement.accessibilityHint = RCTNSStringFromStringNilIfEmpty(newViewProps.accessibilityHint);
401+
#else // [macOS
402+
self.accessibilityElement.accessibilityHelp = RCTNSStringFromStringNilIfEmpty(newViewProps.accessibilityHint);
403+
#endif // macOS]
396404
}
397405

406+
#if !TARGET_OS_OSX // [macOS]
398407
// `accessibilityViewIsModal`
399408
if (oldViewProps.accessibilityViewIsModal != newViewProps.accessibilityViewIsModal) {
400409
self.accessibilityElement.accessibilityViewIsModal = newViewProps.accessibilityViewIsModal;
@@ -447,6 +456,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
447456
if (oldViewProps.accessibilityIgnoresInvertColors != newViewProps.accessibilityIgnoresInvertColors) {
448457
self.accessibilityIgnoresInvertColors = newViewProps.accessibilityIgnoresInvertColors;
449458
}
459+
#endif // [macOS]
450460

451461
// `accessibilityValue`
452462
if (oldViewProps.accessibilityValue != newViewProps.accessibilityValue) {
@@ -465,8 +475,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
465475
self.accessibilityElement.accessibilityValue = nil;
466476
}
467477
}
468-
#endif // [macOS]
469-
478+
470479
// `testId`
471480
if (oldViewProps.testId != newViewProps.testId) {
472481
SEL setAccessibilityIdentifierSelector = @selector(setAccessibilityIdentifier:);
@@ -1236,7 +1245,7 @@ - (void)clearExistingGradientLayers
12361245

12371246
#pragma mark - Accessibility
12381247

1239-
- (NSObject *)accessibilityElement
1248+
- (RCTPlatformView *)accessibilityElement
12401249
{
12411250
return self;
12421251
}

0 commit comments

Comments
 (0)