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

Android: using AccessibilityNodeInfo#addAction to announce Expandable/Collapsible State #34353

Closed
wants to merge 25 commits into from

Conversation

fabOnReact
Copy link
Contributor

@fabOnReact fabOnReact commented Aug 5, 2022

Summary

Expandable and Collapsible are unique in the Android Accessibility API, in that they are not represented as properties on the View or AccessibilityNodeInfo, but are only represented as AccessibilityActions on the AccessibilityNodeInfo. This means that Talkback determines whether or not a node is "expandable" or "collapsible", or potentially even both, by looking at the list of AccessibilityActions attached to the AccessibilityNodeInfo.

When setting the accessibilityState's expandable property, it should correlate to adding an action of either AccessibilityNodeInfoCompat.ACTION_EXPAND or AccessibilityNodeInfoCompat.ACTION_COLLAPSE on the AccessibilityNodeInfo. This work should be done in the ReactAccessibilityDelegate class's

Currently, this feature is being "faked" by appending to the contentDescription in the BaseViewManager class. This should be removed when this feature is implemented properly.

fixes #30841

Changelog

[Android] [Fixed] - using AccessibilityNodeInfo#addAction to announce Expandable/Collapsible State

Test Plan

  • On some components, the state expanded/collapsed is properly announced on focus, on some it is not.
  • On some components only the expanded/collapsed state is announced, and not other component text.
  • Upon change, state change is not always announced.
  • The accessibilityState's "expanded" field does not seem to work on all element types (for example, it has no effect on 's).
  • using accessibilityActions it is possible to add an action for expand/collapse, but these are treated as custom actions and must have their own label defined, rather than using Androids built in expand/collapse actions, which Talkback has predefined labels for.

https://snack.expo.io/0YOQfXFBi

Tests 15th August 2022:

Tests 6th September 2022:

Announcing state with custom actions on Fabric (FAIL).
The issue is not a regression from this PR, as documented in #34353 (comment). It will be fixed in a separate PR.

@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 Aug 5, 2022
@react-native-bot react-native-bot added Bug Platform: Android Android applications. labels Aug 5, 2022
@analysis-bot
Copy link

analysis-bot commented Aug 5, 2022

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,637,392 -509
android hermes armeabi-v7a 7,049,372 -519
android hermes x86 7,939,356 -516
android hermes x86_64 7,911,371 -524
android jsc arm64-v8a 9,513,631 -64
android jsc armeabi-v7a 8,288,904 -90
android jsc x86 9,453,169 -82
android jsc x86_64 10,044,414 -75

Base commit: a789ead
Branch: main

@analysis-bot
Copy link

analysis-bot commented Aug 5, 2022

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

Base commit: a789ead
Branch: main

@fabOnReact
Copy link
Contributor Author

fabOnReact commented Aug 8, 2022

This issue will be fixed in a separate PR, it is tracked in a separate task as not a regression introduced in this PR, neither documented or reported in the original issue.

Main Branch - onAccessibilityAction not called on Fabric renderer

on Paper renderer, onAccessibilityAction is correctly called. It is not called on Fabric.

2022-08-08.21-08-17.mp4

The callback is triggered here

  • Move back in the commit history. Understand when the onAccessibilityAction stopped to work on Fabric

@fabOnReact

This comment was marked as off-topic.

@fabOnReact fabOnReact marked this pull request as ready for review August 15, 2022 15:14
@fabOnReact fabOnReact marked this pull request as draft August 15, 2022 15:14
@fabOnReact fabOnReact changed the title Android: Expandable/Collapsible State #30841 Android: Expandable/Collapsible State Aug 16, 2022
@fabOnReact
Copy link
Contributor Author

fabOnReact commented Aug 17, 2022

extended/collapsed is announced on state change on Paper (PASS) (enable audio)

2022-08-17.11-31-13.mp4

announce the visible text on Paper (PASS) (enable audio)

the same result as with fabric see the corresponding example in #34353 (comment)

announcing state with custom actions on Paper (PASS) (enable audio)

2022-08-17.11-56-35.mp4

@fabOnReact
Copy link
Contributor Author

fabOnReact commented Aug 17, 2022

extended/collapsed is announced on state change on Fabric (enable audio) (PASS)

2022-08-17.17-14-37.mp4

announce the visible text on Fabric (enable audio) (Pass)

2022-08-17.17-44-22.mp4

announcing state with custom actions on Fabric (FAIL). The issue is with main branch #34353 (comment), will be fixed in a different PR.

@fabOnReact fabOnReact marked this pull request as ready for review August 17, 2022 11:39
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 17, 2022
@fabOnReact fabOnReact changed the title Android: Expandable/Collapsible State Android: using AccessibilityNodeInfo#addAction to announce Expandable/Collapsible State Aug 17, 2022
@@ -414,6 +414,8 @@ private static void setState(
context.getString(
boolValue ? R.string.state_on_description : R.string.state_off_description));
}
} else if (state.equals("expanded") && value.getType() == ReadableType.Boolean) {
info.addAction(value.asBoolean() ? AccessibilityNodeInfoCompat.ACTION_EXPAND : AccessibilityNodeInfoCompat.ACTION_COLLAPSE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm misreading this, but isn't this adding an action of "ACTION_EXPAND" when the state is "expanded"?

It should do the opposite, when a state is "expanded" the only available action should be "ACTION_COLLAPSE" and when a state is "collapsed" the only available action should be "ACTION_EXPAND".

Copy link
Contributor Author

@fabOnReact fabOnReact Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blavalla Thanks a lot. I added the suggested changes. I also added these changes:

  • updated the AccessibilityExample (videos)
  • added setTag and getTag to retrieve and update the accessibility_state_expanded in ReactAccessibilityDelegate

@Override
@ReactProp(name = ViewProps.ACCESSIBILITY_STATE)
public void setViewState(@NonNull T view, @Nullable ReadableMap accessibilityState) {
if (accessibilityState == null) {
return;
}
if (accessibilityState.hasKey("expanded")) {
view.setTag(R.id.accessibility_state_expanded, accessibilityState.getBoolean("expanded"));
}

if (host.getTag(R.id.accessibility_state_expanded) != null) {
final boolean accessibilityStateExpanded =
(boolean) host.getTag(R.id.accessibility_state_expanded);
info.addAction(
accessibilityStateExpanded
? AccessibilityNodeInfoCompat.ACTION_COLLAPSE
: AccessibilityNodeInfoCompat.ACTION_EXPAND);
}

  • added the logic in performAccessibilityAction to announce the change in expanded collapsed state when using accessibility menu without implementation of onAccessibilityAction.

public boolean performAccessibilityAction(View host, int action, Bundle args) {
if (action == AccessibilityNodeInfoCompat.ACTION_COLLAPSE) {
host.setTag(R.id.accessibility_state_expanded, false);
}
if (action == AccessibilityNodeInfoCompat.ACTION_EXPAND) {
host.setTag(R.id.accessibility_state_expanded, true);
}

  • updated the summary with the new video test cases
  • further investigated the issue with onAccessibilityAction not triggered on Fabric (summary available here).

It should do the opposite, when a state is "expanded" the only available action should be "ACTION_COLLAPSE" and when a state is "collapsed" the only available action should be "ACTION_EXPAND".
facebook#34353 (comment)
@fabOnReact fabOnReact marked this pull request as draft September 1, 2022 08:15
@fabOnReact
Copy link
Contributor Author

fabOnReact commented Sep 6, 2022

Button which keeps control of extended/collapsed state in JavaScript with onAccessibilityAction, accessibilityActions and accessibiltyState (Paper)

2022-09-06.10-40-19.mp4

@fabOnReact
Copy link
Contributor Author

fabOnReact commented Sep 6, 2022

TouchableWithoutFeedback keeps control of extended/collapsed state in Android Widget (Paper)

2022-09-06.11-19-01.mp4

Just for note, the initial available action is collapse. The video was recorded after interacting with the component.

@fabOnReact
Copy link
Contributor Author

TouchableWithoutFeedback keeps control of extended/collapsed state in Android Widget (Fabric)

2022-09-06.11-39-11.mp4

@fabOnReact
Copy link
Contributor Author

TouchableOpacity announces visible text and triggers expanded/collapsed with onPress and accessiblity menu (Fabric)

2022-09-06.11-43-47.mp4

@fabOnReact fabOnReact marked this pull request as ready for review September 6, 2022 07:07
Copy link
Contributor

@blavalla blavalla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thanks for being so thorough here.

@facebook-github-bot
Copy link
Contributor

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

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @fabriziobertoglio1987 in 082a033.

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 Nov 8, 2022
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
…/Collapsible State (facebook#34353)

Summary:
>Expandable and Collapsible are unique in the Android Accessibility API, in that they are not represented as properties on the View or AccessibilityNodeInfo, but are only represented as AccessibilityActions on the AccessibilityNodeInfo. This means that Talkback determines whether or not a node is "expandable" or "collapsible", or potentially even both, by looking at the list of AccessibilityActions attached to the AccessibilityNodeInfo.

>When setting the accessibilityState's expandable property, it should correlate to adding an action of either AccessibilityNodeInfoCompat.ACTION_EXPAND or AccessibilityNodeInfoCompat.ACTION_COLLAPSE on the AccessibilityNodeInfo. This work should be done in the ReactAccessibilityDelegate class's

>Currently, this feature is being "faked" by appending to the contentDescription in the BaseViewManager class. This should be removed when this feature is implemented properly.

fixes facebook#30841

## Changelog

[Android] [Fixed] - using AccessibilityNodeInfo#addAction to announce Expandable/Collapsible State

Pull Request resolved: facebook#34353

Test Plan:
- On some components, the state expanded/collapsed is properly announced on focus, on some it is not.
- On some components only the expanded/collapsed state is announced, and not other component text.
- Upon change, state change is not always announced.
- The accessibilityState's "expanded" field does not seem to work on all element types (for example, it has no effect on 's).
- using accessibilityActions it is possible to add an action for expand/collapse, but these are treated as custom actions and must have their own label defined, rather than using Androids built in expand/collapse actions, which Talkback has predefined labels for.

https://snack.expo.io/0YOQfXFBi

Tests  15th August 2022:
- Paper [Tests](facebook#34353 (comment))
- Fabric [Tests](facebook#34353 (comment))

Tests 6th September 2022:
- [Button which keeps control of extended/collapsed state in JavaScript with onAccessibilityAction, accessibilityActions and accessibiltyState (Paper)](facebook#34353 (comment))
- [TouchableWithoutFeedback keeps control of extended/collapsed state in Android Widget (Paper)](facebook#34353 (comment))
- [TouchableWithoutFeedback keeps control of extended/collapsed state in Android Widget (Fabric)](facebook#34353 (comment))
- [TouchableOpacity announces visible text and triggers expanded/collapsed with onPress and accessiblity menu (Fabric)](facebook#34353 (comment))

Announcing state with custom actions on Fabric (FAIL).
The issue is not a regression from this PR, as documented in facebook#34353 (comment). It will be fixed in a separate PR.

Reviewed By: NickGerleman

Differential Revision: D39893863

Pulled By: blavalla

fbshipit-source-id: f6af78b1839ba7d97eca052bd258faae00cbd27b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accessibility Bug 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: Android Android applications. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android: Expandable/Collapsible State
5 participants