Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support queuing accessibility announcements on ios #32637

Closed

Conversation

peterc1731
Copy link
Contributor

Summary

The current implementation of AccessibilityInfo.announceForAccessibility will immediately interrupt any existing in progress speech with the announcement. Sometimes this is desirable behaviour, but often you will want to wait until existing speech is finished before reading the new announcement. This change gives us that option.

My personal use case for this feature is a custom text input. When typing on iOS with voiceover enabled, each character is read out after being selected. I wanted to add some additional information after each character to help with the context of what has changed in the input, but I didn't want to override the reading of the character itself.

This feature is supported natively on iOS by constructing an NSAttributedString with the property accessibilitySpeechQueueAnnouncement, so this change just adds an extra parameter to AccessibilityInfo.announceForAccessibility which controls the value of that property on the native side. Adding this as an extra optional parameter with false as the default ensures that existing uses of the function won't be affected.

Unfortunately, this feature doesn't appear to be supported on Android, so the new second property will be iOS only.

Changelog

[iOS] [Added] - add new argument to announceForAccessibility to allow queueing on iOS

Test Plan

I've updated the announceForAccessibility section in RNTester with multiple buttons to demonstrate the difference between queue: false (default) and queue: true and show they work as intended.

Here's the expectation for each button:

  • "Announce for Accessibility Immediately": on press, should start reading the button label, then be interrupted by the announcement
  • "Announce for Accessibility Queued": on press, should read the button label then read the announcement afterwards
  • "Announce for Accessibility Queue Multiple": on press, should read the button label, then read three announcements sequentially, no interruptions

You can see the realisation of those expectations in the following video recorded on an iPhone 12 running iOS 15.0.2:

queue-announcement-demo-2.mov

I've also tested the same way on an iPhone 8 running iOS 13.4 and it works exactly the same.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Nov 21, 2021
@react-native-bot react-native-bot added Platform: iOS iOS applications. Type: Enhancement A new feature or enhancement of an existing feature. labels Nov 21, 2021
@facebook-github-bot
Copy link
Contributor

@philIip has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@yungsters
Copy link
Contributor

Looks good. Thanks for the contribution, @peterc1731.

Would you be willing to also submit a similar PR to facebook/react-native-website so that this can be documented? (Your response does not change the fact that we will merge this.)

@peterc1731
Copy link
Contributor Author

@yungsters Yes happy to do that.

@philIip
Copy link
Contributor

philIip commented Nov 29, 2021

hi @peterc1731, can you rebase when you get the chance? i will go for the land soon.

@facebook-github-bot
Copy link
Contributor

@philIip has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@philIip has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@philIip
Copy link
Contributor

philIip commented Dec 2, 2021

just a heads up, @peterc1731 i needed to make some changes on top of your PR for backwards compatibility reasons

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @peterc1731 in 4d13579.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Dec 2, 2021
@peterc1731 peterc1731 deleted the feat/queue-a11y-announcements branch December 5, 2021 16:12
@peterc1731
Copy link
Contributor Author

thanks @philIip, I'll update the linked docs PR to reflect the API changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: iOS iOS applications. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. Type: Enhancement A new feature or enhancement of an existing feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants