diff --git a/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js b/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js index a388a6d618f4f0..cb663c59ddbc93 100644 --- a/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +++ b/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js @@ -333,11 +333,17 @@ const AccessibilityInfo = { * * See https://reactnative.dev/docs/accessibilityinfo.html#announceforaccessibility */ - announceForAccessibility(announcement: string): void { + announceForAccessibility( + announcement: string, + queue?: boolean = false, + ): void { if (Platform.OS === 'android') { NativeAccessibilityInfoAndroid?.announceForAccessibility(announcement); } else { - NativeAccessibilityManagerIOS?.announceForAccessibility(announcement); + NativeAccessibilityManagerIOS?.announceForAccessibility( + announcement, + queue, + ); } }, diff --git a/Libraries/Components/AccessibilityInfo/NativeAccessibilityManager.js b/Libraries/Components/AccessibilityInfo/NativeAccessibilityManager.js index 9ee2403e372b91..d3db58e2cf274d 100644 --- a/Libraries/Components/AccessibilityInfo/NativeAccessibilityManager.js +++ b/Libraries/Components/AccessibilityInfo/NativeAccessibilityManager.js @@ -51,7 +51,7 @@ export interface Spec extends TurboModule { +accessibilityExtraExtraExtraLarge?: ?number, |}) => void; +setAccessibilityFocus: (reactTag: number) => void; - +announceForAccessibility: (announcement: string) => void; + +announceForAccessibility: (announcement: string, queue: boolean) => void; } export default (TurboModuleRegistry.get('AccessibilityManager'): ?Spec); diff --git a/React/CoreModules/RCTAccessibilityManager.mm b/React/CoreModules/RCTAccessibilityManager.mm index 3d0c7765d059ca..94bd9e610f4ab3 100644 --- a/React/CoreModules/RCTAccessibilityManager.mm +++ b/React/CoreModules/RCTAccessibilityManager.mm @@ -296,9 +296,17 @@ static void setMultipliers( }); } -RCT_EXPORT_METHOD(announceForAccessibility : (NSString *)announcement) +RCT_EXPORT_METHOD(announceForAccessibility : (NSString *)announcement queue : (BOOL)queue) { - UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, announcement); + if (@available(iOS 11.0, *)) { + NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:@(queue) + forKey:UIAccessibilitySpeechAttributeQueueAnnouncement]; + NSAttributedString *announcementWithAttrs = [[NSAttributedString alloc] initWithString:announcement + attributes:attrsDictionary]; + UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, announcementWithAttrs); + } else { + UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, announcement); + } } RCT_EXPORT_METHOD(getMultiplier : (RCTResponseSenderBlock)callback) diff --git a/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js b/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js index b794565169c1c9..6a4e77eda3e348 100644 --- a/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js +++ b/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js @@ -864,10 +864,65 @@ class FakeSliderExample extends React.Component<{}, FakeSliderExampleState> { class AnnounceForAccessibility extends React.Component<{}> { _handleOnPress = () => - AccessibilityInfo.announceForAccessibility('Announcement Test'); + setTimeout( + () => AccessibilityInfo.announceForAccessibility('Announcement Test'), + 1000, + ); + + _handleOnPressQueued = () => + setTimeout( + () => + AccessibilityInfo.announceForAccessibility( + 'Queued Announcement Test', + true, + ), + 1000, + ); + + _handleOnPressQueueMultiple = () => { + setTimeout( + () => + AccessibilityInfo.announceForAccessibility( + 'First Queued Announcement Test', + true, + ), + 1000, + ); + setTimeout( + () => + AccessibilityInfo.announceForAccessibility( + 'Second Queued Announcement Test', + true, + ), + 1100, + ); + setTimeout( + () => + AccessibilityInfo.announceForAccessibility( + 'Third Queued Announcement Test', + true, + ), + 1200, + ); + }; render(): React.Node { - return ( + return Platform.OS === 'ios' ? ( + +