Unverified Commit d098dc34 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Add excludeSemantics flag to semantics widget (#19650)

parent cb2b9c30
...@@ -3166,6 +3166,7 @@ class RenderSemanticsAnnotations extends RenderProxyBox { ...@@ -3166,6 +3166,7 @@ class RenderSemanticsAnnotations extends RenderProxyBox {
RenderBox child, RenderBox child,
bool container = false, bool container = false,
bool explicitChildNodes, bool explicitChildNodes,
bool excludeSemantics = false,
bool enabled, bool enabled,
bool checked, bool checked,
bool toggled, bool toggled,
...@@ -3210,6 +3211,7 @@ class RenderSemanticsAnnotations extends RenderProxyBox { ...@@ -3210,6 +3211,7 @@ class RenderSemanticsAnnotations extends RenderProxyBox {
}) : assert(container != null), }) : assert(container != null),
_container = container, _container = container,
_explicitChildNodes = explicitChildNodes, _explicitChildNodes = explicitChildNodes,
_excludeSemantics = excludeSemantics,
_enabled = enabled, _enabled = enabled,
_checked = checked, _checked = checked,
_toggled = toggled, _toggled = toggled,
...@@ -3291,6 +3293,22 @@ class RenderSemanticsAnnotations extends RenderProxyBox { ...@@ -3291,6 +3293,22 @@ class RenderSemanticsAnnotations extends RenderProxyBox {
markNeedsSemanticsUpdate(); markNeedsSemanticsUpdate();
} }
/// Whether decendants of this [RenderObject] should have their semantic
/// information ignored.
///
/// When this flag is set to true, all child semantics nodes are ignored.
/// This can be used as a convenience for cases where a child is wrapped in
/// an [ExcludeSemantics] widget and then another [Semantics] widget.
bool get excludeSemantics => _excludeSemantics;
bool _excludeSemantics;
set excludeSemantics(bool value) {
assert(value != null);
if (_excludeSemantics == value)
return;
_excludeSemantics = value;
markNeedsSemanticsUpdate();
}
/// If non-null, sets the [SemanticsNode.hasCheckedState] semantic to true and /// If non-null, sets the [SemanticsNode.hasCheckedState] semantic to true and
/// the [SemanticsNode.isChecked] semantic to the given value. /// the [SemanticsNode.isChecked] semantic to the given value.
bool get checked => _checked; bool get checked => _checked;
...@@ -3900,6 +3918,14 @@ class RenderSemanticsAnnotations extends RenderProxyBox { ...@@ -3900,6 +3918,14 @@ class RenderSemanticsAnnotations extends RenderProxyBox {
markNeedsSemanticsUpdate(); markNeedsSemanticsUpdate();
} }
@override
void visitChildrenForSemantics(RenderObjectVisitor visitor) {
if (excludeSemantics)
return;
super.visitChildrenForSemantics(visitor);
}
@override @override
void describeSemanticsConfiguration(SemanticsConfiguration config) { void describeSemanticsConfiguration(SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config); super.describeSemanticsConfiguration(config);
......
...@@ -5077,6 +5077,7 @@ class Semantics extends SingleChildRenderObjectWidget { ...@@ -5077,6 +5077,7 @@ class Semantics extends SingleChildRenderObjectWidget {
Widget child, Widget child,
bool container = false, bool container = false,
bool explicitChildNodes = false, bool explicitChildNodes = false,
bool excludeSemantics = false,
bool enabled, bool enabled,
bool checked, bool checked,
bool selected, bool selected,
...@@ -5122,6 +5123,7 @@ class Semantics extends SingleChildRenderObjectWidget { ...@@ -5122,6 +5123,7 @@ class Semantics extends SingleChildRenderObjectWidget {
child: child, child: child,
container: container, container: container,
explicitChildNodes: explicitChildNodes, explicitChildNodes: explicitChildNodes,
excludeSemantics: excludeSemantics,
properties: new SemanticsProperties( properties: new SemanticsProperties(
enabled: enabled, enabled: enabled,
checked: checked, checked: checked,
...@@ -5174,6 +5176,7 @@ class Semantics extends SingleChildRenderObjectWidget { ...@@ -5174,6 +5176,7 @@ class Semantics extends SingleChildRenderObjectWidget {
Widget child, Widget child,
this.container = false, this.container = false,
this.explicitChildNodes = false, this.explicitChildNodes = false,
this.excludeSemantics = false,
@required this.properties, @required this.properties,
}) : assert(container != null), }) : assert(container != null),
assert(properties != null), assert(properties != null),
...@@ -5210,11 +5213,21 @@ class Semantics extends SingleChildRenderObjectWidget { ...@@ -5210,11 +5213,21 @@ class Semantics extends SingleChildRenderObjectWidget {
/// to create semantic boundaries that are either writable or not for children. /// to create semantic boundaries that are either writable or not for children.
final bool explicitChildNodes; final bool explicitChildNodes;
/// Whether to replace all child semantics with this node.
///
/// Defaults to false.
///
/// When this flag is set to true, all child semantics nodes are ignored.
/// This can be used as a convenience for cases where a child is wrapped in
/// an [ExcludeSemantics] widget and then another [Semantics] widget.
final bool excludeSemantics;
@override @override
RenderSemanticsAnnotations createRenderObject(BuildContext context) { RenderSemanticsAnnotations createRenderObject(BuildContext context) {
return new RenderSemanticsAnnotations( return new RenderSemanticsAnnotations(
container: container, container: container,
explicitChildNodes: explicitChildNodes, explicitChildNodes: explicitChildNodes,
excludeSemantics: excludeSemantics,
enabled: properties.enabled, enabled: properties.enabled,
checked: properties.checked, checked: properties.checked,
toggled: properties.toggled, toggled: properties.toggled,
...@@ -5275,6 +5288,7 @@ class Semantics extends SingleChildRenderObjectWidget { ...@@ -5275,6 +5288,7 @@ class Semantics extends SingleChildRenderObjectWidget {
renderObject renderObject
..container = container ..container = container
..explicitChildNodes = explicitChildNodes ..explicitChildNodes = explicitChildNodes
..excludeSemantics = excludeSemantics
..scopesRoute = properties.scopesRoute ..scopesRoute = properties.scopesRoute
..enabled = properties.enabled ..enabled = properties.enabled
..checked = properties.checked ..checked = properties.checked
......
...@@ -1020,6 +1020,31 @@ void main() { ...@@ -1020,6 +1020,31 @@ void main() {
handle.dispose(); handle.dispose();
semantics.dispose(); semantics.dispose();
}); });
testWidgets('Semantics excludeSemantics ignores children', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
await tester.pumpWidget(new Semantics(
label: 'label',
excludeSemantics: true,
textDirection: TextDirection.ltr,
child: new Semantics(
label: 'other label',
textDirection: TextDirection.ltr,
),
));
expect(semantics, hasSemantics(
new TestSemantics(
children: <TestSemantics>[
new TestSemantics(
label: 'label',
textDirection: TextDirection.ltr,
),
],
), ignoreId: true, ignoreRect: true, ignoreTransform: true)
);
semantics.dispose();
});
} }
class CustomSortKey extends OrdinalSortKey { class CustomSortKey extends OrdinalSortKey {
......
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