Unverified Commit 52914c76 authored by chunhtai's avatar chunhtai Committed by GitHub

simulatedAccessibilityTraversal account for force merging (#135178)

fixes https://github.com/flutter/flutter/issues/135144
parent def17532
...@@ -242,23 +242,29 @@ class SemanticsController { ...@@ -242,23 +242,29 @@ class SemanticsController {
/// * [flutter/engine/AccessibilityBridge.java#SemanticsNode.isFocusable()](https://github.com/flutter/engine/blob/main/shell/platform/android/io/flutter/view/AccessibilityBridge.java#L2641) /// * [flutter/engine/AccessibilityBridge.java#SemanticsNode.isFocusable()](https://github.com/flutter/engine/blob/main/shell/platform/android/io/flutter/view/AccessibilityBridge.java#L2641)
/// * [flutter/engine/SemanticsObject.mm#SemanticsObject.isAccessibilityElement](https://github.com/flutter/engine/blob/main/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm#L449) /// * [flutter/engine/SemanticsObject.mm#SemanticsObject.isAccessibilityElement](https://github.com/flutter/engine/blob/main/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm#L449)
bool _isImportantForAccessibility(SemanticsNode node) { bool _isImportantForAccessibility(SemanticsNode node) {
if (node.isMergedIntoParent) {
// If this node is merged, all its information are present on an ancestor
// node.
return false;
}
final SemanticsData data = node.getSemanticsData();
// If the node scopes a route, it doesn't matter what other flags/actions it // If the node scopes a route, it doesn't matter what other flags/actions it
// has, it is _not_ important for accessibility, so we short circuit. // has, it is _not_ important for accessibility, so we short circuit.
if (node.hasFlag(SemanticsFlag.scopesRoute)) { if (data.hasFlag(SemanticsFlag.scopesRoute)) {
return false; return false;
} }
final bool hasNonScrollingAction = node.getSemanticsData().actions & ~_scrollingActions != 0; final bool hasNonScrollingAction = data.actions & ~_scrollingActions != 0;
if (hasNonScrollingAction) { if (hasNonScrollingAction) {
return true; return true;
} }
final bool hasImportantFlag = node.getSemanticsData().flags & _importantFlagsForAccessibility != 0; final bool hasImportantFlag = data.flags & _importantFlagsForAccessibility != 0;
if (hasImportantFlag) { if (hasImportantFlag) {
return true; return true;
} }
final bool hasContent = node.label.isNotEmpty || node.value.isNotEmpty || node.hint.isNotEmpty; final bool hasContent = data.label.isNotEmpty || data.value.isNotEmpty || data.hint.isNotEmpty;
if (hasContent) { if (hasContent) {
return true; return true;
} }
......
...@@ -982,6 +982,38 @@ void main() { ...@@ -982,6 +982,38 @@ void main() {
tester.semantics.simulatedAccessibilityTraversal(), tester.semantics.simulatedAccessibilityTraversal(),
containsAllInOrder(expectedMatchers)); containsAllInOrder(expectedMatchers));
}); });
testWidgets('merging node should not be visited', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: MergeSemantics(
child: Column(
children: <Widget>[
Semantics(
container: true,
child: const Text('1'),
),
Semantics(
container: true,
child: const Text('2'),
),
Semantics(
container: true,
child: const Text('3'),
),
],
),
),
),
);
expect(
tester.semantics.simulatedAccessibilityTraversal(),
orderedEquals(
<Matcher>[containsSemantics(label: '1\n2\n3')],
),
);
});
}); });
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment