Skip to content

Commit ccc8a81

Browse files
authored
[Android][a11y] Set visibleToUser=false for hidden semantics nodes (flutter#194411)
Updates `AccessibilityBridge` to set `setVisibleToUser` to `false` when a semantics node has `Flag.IS_HIDDEN`, instead of always hardcoding `true`. When scrolling a list with TalkBack (for example, a `CustomScrollView` with a pinned header), items that scroll behind the header are marked `IS_HIDDEN` by Flutter. Because `AccessibilityBridge` still reported `isVisibleToUser` as `true` for those hidden nodes, TalkBack would get confused after scrolling and trigger a second scroll on a single swipe, skipping a full screen of items. Fixes flutter#194260 | Before | After | | --- | --- | | https://github.com/user-attachments/assets/9d1d04fd-41dd-4328-9fbe-670cd09ad95a|https://github.com/user-attachments/assets/87d6f2d4-1180-491f-838d-d1b59b04313d| ## 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 aebd23e commit ccc8a81

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
870870
}
871871
final Rect boundsInScreen = getBoundsInScreen(bounds);
872872
result.setBoundsInScreen(boundsInScreen);
873-
result.setVisibleToUser(true);
873+
result.setVisibleToUser(!semanticsNode.hasFlag(Flag.IS_HIDDEN));
874874
result.setEnabled(
875875
!semanticsNode.hasFlag(Flag.HAS_ENABLED_STATE) || semanticsNode.hasFlag(Flag.IS_ENABLED));
876876

‎engine/src/flutter/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3447,6 +3447,34 @@ public void itDoesNotLogDeprecationWarningForAnnounceOnAPI35() {
34473447
}
34483448
}
34493449

3450+
@Test
3451+
public void itSetsVisibleToUserFalseForHiddenNodes() {
3452+
AccessibilityBridge accessibilityBridge = setUpBridge();
3453+
3454+
TestSemanticsNode root = new TestSemanticsNode();
3455+
root.id = 0;
3456+
3457+
TestSemanticsNode visibleNode = new TestSemanticsNode();
3458+
visibleNode.id = 1;
3459+
visibleNode.label = "visible";
3460+
root.children.add(visibleNode);
3461+
3462+
TestSemanticsNode hiddenNode = new TestSemanticsNode();
3463+
hiddenNode.id = 2;
3464+
hiddenNode.label = "hidden";
3465+
hiddenNode.addFlag(AccessibilityBridge.Flag.IS_HIDDEN);
3466+
root.children.add(hiddenNode);
3467+
3468+
TestSemanticsUpdate testSemanticsUpdate = root.toUpdate();
3469+
testSemanticsUpdate.sendUpdateToBridge(accessibilityBridge);
3470+
3471+
AccessibilityNodeInfo visibleNodeInfo = accessibilityBridge.createAccessibilityNodeInfo(1);
3472+
assertTrue(visibleNodeInfo.isVisibleToUser());
3473+
3474+
AccessibilityNodeInfo hiddenNodeInfo = accessibilityBridge.createAccessibilityNodeInfo(2);
3475+
assertFalse(hiddenNodeInfo.isVisibleToUser());
3476+
}
3477+
34503478
/// The encoding for semantics is described in platform_view_android.cc
34513479
class TestSemanticsUpdate {
34523480
TestSemanticsUpdate(ByteBuffer buffer, String[] strings, ByteBuffer[] stringAttributeArgs) {

0 commit comments

Comments
 (0)