Skip to content

Commit 52914c7

Browse files
authored
simulatedAccessibilityTraversal account for force merging (#135178)
fixes flutter/flutter#135144
1 parent def1753 commit 52914c7

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

packages/flutter_test/lib/src/controller.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,23 +242,29 @@ class SemanticsController {
242242
/// * [flutter/engine/AccessibilityBridge.java#SemanticsNode.isFocusable()](https://github.com/flutter/engine/blob/main/shell/platform/android/io/flutter/view/AccessibilityBridge.java#L2641)
243243
/// * [flutter/engine/SemanticsObject.mm#SemanticsObject.isAccessibilityElement](https://github.com/flutter/engine/blob/main/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm#L449)
244244
bool _isImportantForAccessibility(SemanticsNode node) {
245+
if (node.isMergedIntoParent) {
246+
// If this node is merged, all its information are present on an ancestor
247+
// node.
248+
return false;
249+
}
250+
final SemanticsData data = node.getSemanticsData();
245251
// If the node scopes a route, it doesn't matter what other flags/actions it
246252
// has, it is _not_ important for accessibility, so we short circuit.
247-
if (node.hasFlag(SemanticsFlag.scopesRoute)) {
253+
if (data.hasFlag(SemanticsFlag.scopesRoute)) {
248254
return false;
249255
}
250256

251-
final bool hasNonScrollingAction = node.getSemanticsData().actions & ~_scrollingActions != 0;
257+
final bool hasNonScrollingAction = data.actions & ~_scrollingActions != 0;
252258
if (hasNonScrollingAction) {
253259
return true;
254260
}
255261

256-
final bool hasImportantFlag = node.getSemanticsData().flags & _importantFlagsForAccessibility != 0;
262+
final bool hasImportantFlag = data.flags & _importantFlagsForAccessibility != 0;
257263
if (hasImportantFlag) {
258264
return true;
259265
}
260266

261-
final bool hasContent = node.label.isNotEmpty || node.value.isNotEmpty || node.hint.isNotEmpty;
267+
final bool hasContent = data.label.isNotEmpty || data.value.isNotEmpty || data.hint.isNotEmpty;
262268
if (hasContent) {
263269
return true;
264270
}

packages/flutter_test/test/controller_test.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,38 @@ void main() {
982982
tester.semantics.simulatedAccessibilityTraversal(),
983983
containsAllInOrder(expectedMatchers));
984984
});
985+
986+
testWidgets('merging node should not be visited', (WidgetTester tester) async {
987+
await tester.pumpWidget(
988+
MaterialApp(
989+
home: MergeSemantics(
990+
child: Column(
991+
children: <Widget>[
992+
Semantics(
993+
container: true,
994+
child: const Text('1'),
995+
),
996+
Semantics(
997+
container: true,
998+
child: const Text('2'),
999+
),
1000+
Semantics(
1001+
container: true,
1002+
child: const Text('3'),
1003+
),
1004+
],
1005+
),
1006+
),
1007+
),
1008+
);
1009+
1010+
expect(
1011+
tester.semantics.simulatedAccessibilityTraversal(),
1012+
orderedEquals(
1013+
<Matcher>[containsSemantics(label: '1\n2\n3')],
1014+
),
1015+
);
1016+
});
9851017
});
9861018
});
9871019
}

0 commit comments

Comments
 (0)