Skip to content

Commit fd8a345

Browse files
jorge-cabfacebook-github-bot
authored andcommitted
Add accessibilityRespondsToUserInteraction prop (#50837)
Summary: Pull Request resolved: #50837 This prop can be used to disable user interaction with switch control, voice control or full keyboard access. VoiceOver is not affected by it. https://developer.apple.com/documentation/swiftui/view/accessibilityrespondstouserinteraction(_:) Changelog: [iOS][Added] - Expose iOS's accessibilityRespondsToUserInteraction as a prop Reviewed By: joevilches Differential Revision: D73382060 fbshipit-source-id: c9f3137adc0ea34a58435f7f0438748fbfcc5a18
1 parent 1cfb46b commit fd8a345

File tree

7 files changed

+34
-0
lines changed

7 files changed

+34
-0
lines changed

packages/react-native/Libraries/Components/View/ViewAccessibility.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,14 @@ export interface AccessibilityPropsIOS {
334334
* @platform ios
335335
*/
336336
accessibilityLargeContentTitle?: string | undefined;
337+
338+
/**
339+
* Blocks the user from interacting with the component through keyboard while still allowing
340+
* screen reader to interact with it if this View is still accessible.
341+
*
342+
* @platform ios
343+
*/
344+
accessibilityRespondsToUserInteraction?: boolean | undefined;
337345
}
338346

339347
export type Role =

packages/react-native/Libraries/Components/View/ViewAccessibility.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,14 @@ export type AccessibilityPropsIOS = $ReadOnly<{
320320
* @platform ios
321321
*/
322322
accessibilityLanguage?: ?Stringish,
323+
324+
/**
325+
* Blocks the user from interacting with the component through keyboard while still allowing
326+
* screen reader to interact with it if this View is still accessible.
327+
*
328+
* @platform ios
329+
*/
330+
accessibilityRespondsToUserInteraction?: ?boolean,
323331
}>;
324332

325333
export type AccessibilityProps = $ReadOnly<{

packages/react-native/Libraries/NativeComponent/BaseViewConfig.ios.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ const validAttributesForNonEventProps = {
198198
accessibilityShowsLargeContentViewer: true,
199199
accessibilityLargeContentTitle: true,
200200
experimental_accessibilityOrder: true,
201+
accessibilityRespondsToUserInteraction: true,
201202
testID: true,
202203
backgroundColor: {process: require('../StyleSheet/processColor').default},
203204
backfaceVisibility: true,

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3652,6 +3652,7 @@ export type AccessibilityPropsIOS = $ReadOnly<{
36523652
\\"aria-modal\\"?: ?boolean,
36533653
accessibilityElementsHidden?: ?boolean,
36543654
accessibilityLanguage?: ?Stringish,
3655+
accessibilityRespondsToUserInteraction?: ?boolean,
36553656
}>;
36563657
export type AccessibilityProps = $ReadOnly<{
36573658
...AccessibilityPropsAndroid,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,11 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
440440
}
441441
}
442442

443+
if (oldViewProps.accessibilityRespondsToUserInteraction != newViewProps.accessibilityRespondsToUserInteraction) {
444+
self.accessibilityElement.accessibilityRespondsToUserInteraction =
445+
newViewProps.accessibilityRespondsToUserInteraction;
446+
}
447+
443448
// `testId`
444449
if (oldViewProps.testId != newViewProps.testId) {
445450
SEL setAccessibilityIdentifierSelector = @selector(setAccessibilityIdentifier:);

packages/react-native/ReactCommon/react/renderer/components/view/AccessibilityProps.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ AccessibilityProps::AccessibilityProps(
154154
"accessibilityIgnoresInvertColors",
155155
sourceProps.accessibilityIgnoresInvertColors,
156156
false)),
157+
accessibilityRespondsToUserInteraction(
158+
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
159+
? sourceProps.accessibilityRespondsToUserInteraction
160+
: convertRawProp(
161+
context,
162+
rawProps,
163+
"accessibilityRespondsToUserInteraction",
164+
sourceProps.accessibilityRespondsToUserInteraction,
165+
{})),
157166
onAccessibilityTap(
158167
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
159168
? sourceProps.onAccessibilityTap
@@ -266,6 +275,7 @@ void AccessibilityProps::setProp(
266275
RAW_SET_PROP_SWITCH_CASE_BASIC(accessibilityViewIsModal);
267276
RAW_SET_PROP_SWITCH_CASE_BASIC(accessibilityElementsHidden);
268277
RAW_SET_PROP_SWITCH_CASE_BASIC(accessibilityIgnoresInvertColors);
278+
RAW_SET_PROP_SWITCH_CASE_BASIC(accessibilityRespondsToUserInteraction);
269279
RAW_SET_PROP_SWITCH_CASE_BASIC(onAccessibilityTap);
270280
RAW_SET_PROP_SWITCH_CASE_BASIC(onAccessibilityMagicTap);
271281
RAW_SET_PROP_SWITCH_CASE_BASIC(onAccessibilityEscape);

packages/react-native/ReactCommon/react/renderer/components/view/AccessibilityProps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class AccessibilityProps {
4949
bool accessibilityViewIsModal{false};
5050
bool accessibilityElementsHidden{false};
5151
bool accessibilityIgnoresInvertColors{false};
52+
bool accessibilityRespondsToUserInteraction{};
5253
bool onAccessibilityTap{};
5354
bool onAccessibilityMagicTap{};
5455
bool onAccessibilityEscape{};

0 commit comments

Comments
 (0)