Skip to content

Conversation

@jonahwilliams
Copy link
Contributor

Description

Create a custom render semantics which will perform an announcement of the combined semantic label on iOS platforms.

Fixes #41427

@fluttergithubbot fluttergithubbot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Sep 27, 2019
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

So, live regions do not work on iOS? We have them hooked up to UIAccessibilityTraitUpdatesFrequently - maybe that's not the correct mapping?

And should this maybe live in the iOS accessibility bridge to make iOS announce whenever the value of a live region changes instead of special casing this in the framework just for snackbars?

@override
void assembleSemanticsNode(SemanticsNode node, SemanticsConfiguration config, Iterable<SemanticsNode> children) {
super.assembleSemanticsNode(node, config, children);
if (defaultTargetPlatform == TargetPlatform.iOS && node.label != null && node.label != _lastAnnouncedLabel) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you use a switch over the defaultTargetPlatform so the analyser reminds us to check this place whenever we add a new TargetPlatform?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

super.assembleSemanticsNode(node, config, children);
if (defaultTargetPlatform == TargetPlatform.iOS && node.label != null && node.label != _lastAnnouncedLabel) {
_lastAnnouncedLabel = node.label;
SemanticsService.announce(_lastAnnouncedLabel, textDirection);
Copy link
Member

Choose a reason for hiding this comment

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

This seems hacky to make an announcement as a side effect of assembling the tree...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, its a bit of a hack. Unfortunately since we take a child: Widget instead of a text String I don't think we have a better way of figuring out what to announce until after we've built the semantics tree. We could build a live region concept into our own semantics...

@jonahwilliams
Copy link
Contributor Author

Correct, there is no live region concept on iOS, which ties our hands here a bit. The updates frequently trait does not trigger any announcements as far as I can tell, it only changes how the accessibility system reads/polls for the label

@goderbauer
Copy link
Member

Couldn't we do the same thing in the iOS accessibility bridge, though in a more general case: If a node has the live region flag we compare its label/value with the old one and if it has changed, we announce it from there? Basically implement the concept of live regions in the iOS bridge instead of hacking it into individual widgets on the framework side?

@jonahwilliams
Copy link
Contributor Author

Yeah that's a good point. I'll take a look at wiring something up

@jonahwilliams jonahwilliams deleted the announce_snack branch September 27, 2019 16:26
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SnackBar not announced for a11y on iOS

4 participants