Skip to content

Commit 2541e50

Browse files
authored
[a11y] Fixes SnackBar showing more Voice Control labels than expected (flutter#194614)
Fixes flutter#157630 SnackBar incorrectly had an VoiceControl label attributed to it, because SnackBar technically has 3 actions attributed to it - kDismiss, kScrollUp, and kScrollDown. In this PR I exclude kDismiss and kScrollUp/Down/Left/Right from ever receiving VoiceOver labels. - kDismiss: only maps to Escape, not Tap. It's only used in `accessibilityPerformEscape`, which is the VoiceOver 2 finger Z-scrub or verbal "Go back" command. - kScrollUp/Down/Left/Right: Scrollables are rendered as a native UIScrollView, not as an SemanticsObject, so shouldn't receive a VoiceControl label. <img width="814" height="1770" alt="image" src="https://github.com/user-attachments/assets/cdf02512-d947-4473-9549-a280151f25bc" /> ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
1 parent 56aa96c commit 2541e50

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,10 @@ - (BOOL)accessibilityRespondsToUserInteraction {
861861
return false;
862862
}
863863

864-
// Return true only if the node contains actions other than system actions.
865-
if ((self.node.actions & ~flutter::kSystemActions) != 0) {
864+
// Return true only if the node contains actions other than system, scroll, or
865+
// dismiss actions.
866+
if ((self.node.actions & ~(flutter::kSystemActions | flutter::kScrollableSemanticsActions |
867+
static_cast<int32_t>(flutter::SemanticsAction::kDismiss))) != 0) {
866868
return true;
867869
}
868870

‎engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,4 +1572,22 @@ - (void)testUIFocusItemScrollableContainerNoFeedbackLoops {
15721572

15731573
XCTAssertEqual(bridge->observations.size(), (size_t)0);
15741574
}
1575+
1576+
- (void)testAccessibilityRespondsToUserInteraction {
1577+
fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
1578+
new flutter::testing::MockAccessibilityBridge());
1579+
fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
1580+
FlutterSemanticsObject* object = [[FlutterSemanticsObject alloc] initWithBridge:bridge uid:0];
1581+
1582+
flutter::SemanticsNode node;
1583+
node.id = 0;
1584+
node.actions = flutter::kSystemActions | flutter::kScrollableSemanticsActions |
1585+
static_cast<int32_t>(flutter::SemanticsAction::kDismiss);
1586+
[object setSemanticsNode:&node];
1587+
XCTAssertFalse(object.accessibilityRespondsToUserInteraction);
1588+
1589+
node.actions |= static_cast<int32_t>(flutter::SemanticsAction::kTap);
1590+
[object setSemanticsNode:&node];
1591+
XCTAssertTrue(object.accessibilityRespondsToUserInteraction);
1592+
}
15751593
@end

0 commit comments

Comments
 (0)