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

adding iOS support for accessibilityLiveRegion #35432

Closed

Conversation

fabOnReact
Copy link
Contributor

@fabOnReact fabOnReact commented Nov 22, 2022

Summary

The functionality is included in two components:

  • RCTViewComponentView
  • RCTParagraphComponentView

RCTViewComponentView

RCTViewComponentView is the Fabric API built on top of iOS UIView. The class will compare the old and new props sent from React fabric renderer and save the values as instance variables like accessibilityLabel, and accessibilityValue on the native iOS components.
Once the update process is completed, the VoiceOver announcement is triggered in finalizeUpdates which is responsible for updating the iOS native User Interface with the new props sent from the react fabric renderer (see RCTMountingManager and react-reconciler).

RCTParagraphComponentView

The native iOS component for Text is RCTParagraphComponentView.
This component's peculiarity is that it overrides the accessibilityLabel of the parent View component with its text value (#34735 (comment)).
ReactNative supports nested Text components represented on iOS as an array of accessibility elements. Updating the accessibility elements attributedText triggers a VoiceOver announcement if accessibilityLiveRegion is enabled.

VoiceOver announces changes in the accessibility attributes of children.

Adding dynamic VoiceOver announcement to iOS RCTViewComponent


The functionality adds VoiceOver dynamic announcements for changes in accessibilityLabel, hint, state, or other attributes of components with the accessibilityLiveRegion prop. 
Announcements of components with accessibilityLiveRegion polite are queued using UIAccessibilitySpeechAttributeQueueAnnouncement.

RCTParagraphComponent dynamic VoiceOver announcements


The react-native Text Component updates the native iOS attributedText with a special prop named children. The text creation and update are triggered from the Fabric renderer with the methods createTextInstance and updateHostText.
updateState invalidates the iOS UIView with setNeedsDisplay. The UIView component retrieves and displays the updated attributedString from the new _state (more code pointers here).


A manual VoiceOver announcement is triggered after the state change to announce the updated Paragraph attributedText.

Other notes

fixes #34735. The below functionalities are moved to a separate PR:

Changelog

[iOS] [Added] - adding iOS support for accessibilityLiveRegion

Test Plan

  • accessibilityLiveRegion polite => announces after other announcements (queued)
  • accessibilityLiveRegion assertive => interrupts announcements

#35432 (comment)
#35432 (comment)
#35432 (comment)
#35432 (comment)
#35432 (comment)

Read documentation, investigate different solutions, plan work (details)
--
Test existing react-native accessibilityLiveRegion functionality on Android Paper (details)Include Video recording of different scenarios (assertive, polite, none)Write down expected behaviour for iOS
Implementation Design (details)
Detect accessibility content change (details)

Read documentation, investigate different solutions, plan work ([details](facebook#34735 (comment)))
"Test existing react-native accessibilityLiveRegion functionality on Android Paper ([details](facebook#34735 (comment)))
Include Video recording of different scenarios (assertive, polite, none)
Write down expected behaviour for iOS"
Implementation Design ([details](facebook#34735 (comment)))
Detect accessibility content change ([details](facebook#34735 (comment)))
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 22, 2022
@analysis-bot
Copy link

analysis-bot commented Nov 22, 2022

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,110,765 -1,354,102
android hermes armeabi-v7a 6,479,568 -1,304,914
android hermes x86 7,529,618 -1,409,657
android hermes x86_64 7,387,987 -1,409,376
android jsc arm64-v8a 8,976,897 -680,629
android jsc armeabi-v7a 7,708,370 -682,024
android jsc x86 9,039,894 -681,347
android jsc x86_64 9,517,276 -681,486

Base commit: 46ffeca
Branch: main

@analysis-bot
Copy link

analysis-bot commented Nov 22, 2022

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 46ffeca
Branch: main

@pull-bot
Copy link

PR build artifact for 972a40a is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

Add prop accessibilityLiveRegion to react-native iOS API
Trigger polite/assertive announcement if label/hint changesdd prop accessibilityLiveRegion to react-native iOS API
@pull-bot
Copy link

PR build artifact for 53f7b76 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@pull-bot
Copy link

PR build artifact for 53f7b76 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@react-native-bot react-native-bot added Platform: iOS iOS applications. Type: Enhancement A new feature or enhancement of an existing feature. labels Nov 22, 2022
@pull-bot
Copy link

PR build artifact for 85b1c1f is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@pull-bot
Copy link

PR build artifact for 85b1c1f is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

…bilityLiveRegion to children on iOS.

If a view with accessibilityLiveRegion does not have accessibilityLabel, the view announces the child text component.
- check if the view does not have accessibilityLabel
- Run a loop on each children and add accessibilityLiveRegion if children is focusable
https://stackoverflow.com/questions/32370994/how-to-pass-props-to-this-props-children
@pull-bot
Copy link

PR build artifact for 17af1f8 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@pull-bot
Copy link

PR build artifact for 17af1f8 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

…assertive

Read Implementation RCTParagraphComponentViewUnderstand logic behind announcement of the accessibilityLabel
--
Add announcement for Accessibility State. RCTViewComponent updateProps will save the accessibilityState in self.accessibilityTraits. Use self.accessibilityTraits to announce the change in value from updatePropsRead iOS ImplementationTest the announcement of self.accessibilityTraits with UIAccessibilityPostNotification
Read accessibilityValue logic in RCTComponentView
Chain Label + Hint + State to avoid cutting announcements when using assertiveCreate a local variables named label, hint, state, roleVerify order used on iOS to announce Label, Hint, State (selected my label Button my hint) => state label role hintAdd Label, Hint and State to accessibilityLiveRegionAnnouncement respecting correct orderTrigger announcement if accessibilityLiveRegionAnnouncement is not empty

"Read Implementation RCTParagraphComponentView
Understand logic behind announcement of the accessibilityLabel"
"Add announcement for Accessibility State. RCTViewComponent updateProps will save the accessibilityState in self.accessibilityTraits. Use self.accessibilityTraits to announce the change in value from updateProps
Read iOS Implementation
Test the announcement of self.accessibilityTraits with [UIAccessibilityPostNotification](https://github.com/fabriziobertoglio1987/react-native/blob/17af1f8489e202a65c1e20c440756db2be95a8b4/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm#L305)"
Read [accessibilityValue logic](https://github.com/fabriziobertoglio1987/react-native/blob/17af1f8489e202a65c1e20c440756db2be95a8b4/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm#L365) in RCTComponentView
"Chain Label + Hint + State to avoid cutting announcements when using assertive
Create a local variables named label, hint, state, role
Verify order used on iOS to announce Label, Hint, State (selected my label Button my hint) => state label role hint
Add Label, Hint and State to accessibilityLiveRegionAnnouncement respecting correct order
Trigger announcement if accessibilityLiveRegionAnnouncement is not empty "
@pull-bot
Copy link

PR build artifact for 119892c is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@pull-bot
Copy link

PR build artifact for 119892c is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@pull-bot
Copy link

PR build artifact for 744408a is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@pull-bot
Copy link

PR build artifact for 744408a is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@fabOnReact fabOnReact changed the title 🚧 Draft solution for iOS accessibilityLiveRegion 🚧 adding iOS support for accessibilityLiveRegion Nov 28, 2022
@fabOnReact
Copy link
Contributor Author

P type task
6 bug Use correct default in useContext (link)
7 bug move accLiveRegion prop to separate variable while keeping compatability with web props
8 bug Nested text does not support accessibilityLiveRegion on iOS and Android (link)

P type task
6 bug Use correct default in useContext (link)
7 bug move accLiveRegion prop to separate variable while keeping compatability with web props
8 bug Nested text does not support accessibilityLiveRegion on iOS and Android (link)

@fabOnReact
Copy link
Contributor Author

fixing issue with Android TextInput not passing accLiveRegion prop

Screenshot 2022-12-12 at 9 51 20 PM

2022-12-12.21-50-12.mp4

@fabOnReact
Copy link
Contributor Author

Android - correctly announcing change of ariaLive in Text component

2022-12-12.22-02-30.mp4

@pull-bot
Copy link

PR build artifact for 88cbc2c is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@pull-bot
Copy link

PR build artifact for 88cbc2c is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@fabOnReact
Copy link
Contributor Author

https://app.circleci.com/pipelines/github/facebook/react-native/18392/workflows/498185fe-7241-47d5-a5b7-6fb22b4010a9/jobs/391153/steps

P type task
9 review Review diff
10 review Review Circle CI
11 review Avoid re-implementating RCTIsReactRootView
12 review check warning messages from linter. Enable linting tool and go through file changes

@pull-bot
Copy link

PR build artifact for 133f440 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@pull-bot
Copy link

PR build artifact for 133f440 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@fabOnReact fabOnReact marked this pull request as ready for review December 14, 2022 13:55
@pull-bot
Copy link

PR build artifact for 59a23ba is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@pull-bot
Copy link

PR build artifact for 59a23ba is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

fabOnReact added a commit to fabOnReact/react-native that referenced this pull request Dec 14, 2022
@alextait1
Copy link

Just adding a comment here regarding documentation. I think it would be really valuable to add a warning comment to the docs for both Android and iOS cautioning people to reach for polite over assertive in most cases. Marketers can be prone to abusing assertive live regions on the web and in 90%+ of cases (IMO) polite is the better user experience. cc @blavalla

@facebook-github-bot
Copy link
Contributor

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

@github-actions
Copy link

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jul 21, 2023
@github-actions
Copy link

This PR was closed because it has been stalled for 7 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accessibility CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon. Type: Enhancement A new feature or enhancement of an existing feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android/iOS Accessible Live Regions
6 participants