Skip to content

Commit

Permalink
When dispatching a semantic event, check if the node has been merged …
Browse files Browse the repository at this point in the history
…with parent (flutter#20020)
  • Loading branch information
jonahwilliams authored Jul 31, 2018
1 parent 63098f2 commit e9c8e36
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/rendering/object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
50 changes: 50 additions & 0 deletions packages/flutter/test/material/switch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

0 comments on commit e9c8e36

Please sign in to comment.