In the semantics tree, do not detach a child if it has already been assigned a new parent (#6773)

Fixes https://github.com/flutter/flutter/issues/6690

Also add a version of the Gallery smoke test that enables semantics
This commit is contained in:
Jason Simmons
2016-11-10 12:55:56 -08:00
committed by GitHub
parent 546cef5277
commit ca5e1f3f23
3 changed files with 62 additions and 45 deletions

View File

@@ -138,7 +138,11 @@ abstract class RendererBinding extends BindingBase implements SchedulerBinding,
SemanticsHandle _semanticsHandle;
void _handleSemanticsEnabledChanged() {
if (ui.window.semanticsEnabled) {
setSemanticsEnabled(ui.window.semanticsEnabled);
}
void setSemanticsEnabled(bool enabled) {
if (enabled) {
_semanticsHandle ??= _pipelineOwner.ensureSemantics();
} else {
_semanticsHandle?.dispose();

View File

@@ -372,6 +372,7 @@ class SemanticsNode extends AbstractNode {
/// child list for the given frame at once instead of needing to process the
/// changes incrementally as new children are compiled.
void finalizeChildren() {
// The goal of this function is updating sawChange.
if (_children != null) {
for (SemanticsNode child in _children)
child._dead = true;
@@ -473,8 +474,12 @@ class SemanticsNode extends AbstractNode {
owner._detachedNodes.add(this);
super.detach();
if (_children != null) {
for (SemanticsNode child in _children)
child.detach();
for (SemanticsNode child in _children) {
// The list of children may be stale and may contain nodes that have
// been assigned to a different parent.
if (child.parent == this)
child.detach();
}
}
}