Skip to content

Commit

Permalink
simulatedAccessibilityTraversal account for force merging (flutter#13…
Browse files Browse the repository at this point in the history
  • Loading branch information
chunhtai authored and christopherfujino committed Sep 27, 2023
1 parent cddb15f commit 722b9a1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/flutter_test/lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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/SemanticsObject.mm#SemanticsObject.isAccessibilityElement](https://github.com/flutter/engine/blob/main/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm#L449)
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
// has, it is _not_ important for accessibility, so we short circuit.
if (node.hasFlag(SemanticsFlag.scopesRoute)) {
if (data.hasFlag(SemanticsFlag.scopesRoute)) {
return false;
}

final bool hasNonScrollingAction = node.getSemanticsData().actions & ~_scrollingActions != 0;
final bool hasNonScrollingAction = data.actions & ~_scrollingActions != 0;
if (hasNonScrollingAction) {
return true;
}

final bool hasImportantFlag = node.getSemanticsData().flags & _importantFlagsForAccessibility != 0;
final bool hasImportantFlag = data.flags & _importantFlagsForAccessibility != 0;
if (hasImportantFlag) {
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) {
return true;
}
Expand Down
32 changes: 32 additions & 0 deletions packages/flutter_test/test/controller_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,38 @@ void main() {
tester.semantics.simulatedAccessibilityTraversal(),
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')],
),
);
});
});
});
}
Expand Down

0 comments on commit 722b9a1

Please sign in to comment.