diff --git a/Libraries/Components/View/ViewAccessibility.js b/Libraries/Components/View/ViewAccessibility.js index 28e10b8dda8d0a..f0e411051783ee 100644 --- a/Libraries/Components/View/ViewAccessibility.js +++ b/Libraries/Components/View/ViewAccessibility.js @@ -80,6 +80,7 @@ module.exports = { 'radiobutton_checked', 'radiobutton_unchecked', ], + // This must be kept in sync with the AccessibilityRolesMask in RCTViewManager.m AccessibilityRoles: [ 'none', 'button', @@ -93,5 +94,6 @@ module.exports = { 'header', 'summary', ], + // This must be kept in sync with the AccessibilityStatesMask in RCTViewManager.m AccessibilityStates: ['selected', 'disabled'], }; diff --git a/React/Views/RCTViewManager.m b/React/Views/RCTViewManager.m index 420f47d494fbac..c69264806bbcad 100644 --- a/React/Views/RCTViewManager.m +++ b/React/Views/RCTViewManager.m @@ -151,12 +151,22 @@ - (RCTShadowView *)shadowView RCT_CUSTOM_VIEW_PROPERTY(accessibilityRole, UIAccessibilityTraits, RCTView) { - view.reactAccessibilityElement.accessibilityTraits |= json ? [RCTConvert UIAccessibilityTraits:json] : defaultView.accessibilityTraits; + // This mask must be kept in sync with the AccessibilityRoles enum defined in ViewAccessibility.js + const UIAccessibilityTraits AccessibilityRolesMask = UIAccessibilityTraitNone | UIAccessibilityTraitButton | UIAccessibilityTraitLink | UIAccessibilityTraitSearchField | UIAccessibilityTraitImage | UIAccessibilityTraitKeyboardKey | UIAccessibilityTraitStaticText | UIAccessibilityTraitAdjustable | UIAccessibilityTraitHeader | UIAccessibilityTraitSummaryElement; + + UIAccessibilityTraits newTraits = json ? [RCTConvert UIAccessibilityTraits:json] : defaultView.accessibilityTraits; + UIAccessibilityTraits maskedTraits = newTraits & AccessibilityRolesMask; + view.reactAccessibilityElement.accessibilityTraits = (view.reactAccessibilityElement.accessibilityTraits & ~AccessibilityRolesMask) | maskedTraits; } RCT_CUSTOM_VIEW_PROPERTY(accessibilityStates, UIAccessibilityTraits, RCTView) { - view.reactAccessibilityElement.accessibilityTraits |= json ? [RCTConvert UIAccessibilityTraits:json] : defaultView.accessibilityTraits; + // This mask must be kept in sync with the AccessibilityStates enum defined in ViewAccessibility.js + const UIAccessibilityTraits AccessibilityStatesMask = UIAccessibilityTraitNotEnabled | UIAccessibilityTraitSelected; + + UIAccessibilityTraits newTraits = json ? [RCTConvert UIAccessibilityTraits:json] : defaultView.accessibilityTraits; + UIAccessibilityTraits maskedTraits = newTraits & AccessibilityStatesMask; + view.reactAccessibilityElement.accessibilityTraits = (view.reactAccessibilityElement.accessibilityTraits & ~AccessibilityStatesMask) | maskedTraits; } RCT_CUSTOM_VIEW_PROPERTY(pointerEvents, RCTPointerEvents, RCTView)