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

When dispatching a semantic event, check if the node has been merged with parent (#20020)

parent 63098f2b
......@@ -2206,7 +2206,7 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im
void sendSemanticsEvent(SemanticsEvent semanticsEvent) {
if (owner.semanticsOwner == null)
return;
if (_semantics != null) {
if (_semantics != null && !_semantics.isMergedIntoParent) {
_semantics.sendEvent(semanticsEvent);
} else if (parent != null) {
final RenderObject renderParent = parent;
......
......@@ -314,4 +314,54 @@ void main() {
semanticsTester.dispose();
SystemChannels.accessibility.setMockMessageHandler(null);
});
testWidgets('switch sends semantic events from parent if fully merged', (WidgetTester tester) async {
dynamic semanticEvent;
bool value = false;
SystemChannels.accessibility.setMockMessageHandler((dynamic message) {
semanticEvent = message;
});
final SemanticsTester semanticsTester = new SemanticsTester(tester);
await tester.pumpWidget(
new MaterialApp(
home: new StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
void onChanged(bool newValue) {
setState(() {
value = newValue;
});
}
return new Material(
child: new MergeSemantics(
child: new ListTile(
leading: const Text('test'),
onTap: () {
onChanged(!value);
},
trailing: new Switch(
value: value,
onChanged: onChanged,
),
),
),
);
},
),
),
);
await tester.tap(find.byType(MergeSemantics));
final RenderObject object = tester.firstRenderObject(find.byType(MergeSemantics));
expect(value, true);
expect(semanticEvent, <String, dynamic>{
'type': 'tap',
'nodeId': object.debugSemantics.id,
'data': <String, dynamic>{},
});
expect(object.debugSemantics.getSemanticsData().hasAction(SemanticsAction.tap), true);
semanticsTester.dispose();
SystemChannels.accessibility.setMockMessageHandler(null);
});
}
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