From a98bfd755c84796cd16e8357961c132876f855d8 Mon Sep 17 00:00:00 2001 From: David Shuckerow Date: Mon, 20 Aug 2018 10:48:24 -0700 Subject: [PATCH] Wrap the ReorderableList's children with a MergeSemantics (#20715) --- .../lib/src/material/reorderable_list.dart | 13 +++-- .../test/material/reorderable_list_test.dart | 57 +++++++++++++++++++ 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/packages/flutter/lib/src/material/reorderable_list.dart b/packages/flutter/lib/src/material/reorderable_list.dart index 983694ce07..f4e7ab0670 100644 --- a/packages/flutter/lib/src/material/reorderable_list.dart +++ b/packages/flutter/lib/src/material/reorderable_list.dart @@ -391,10 +391,15 @@ class _ReorderableListContentState extends State<_ReorderableListContent> with T // // We also apply the relevant custom accessibility actions for moving the item // up, down, to the start, and to the end of the list. - return new KeyedSubtree(key: keyIndexGlobalKey, child: new Semantics( - customSemanticsActions: semanticsActions, - child: toWrap, - )); + return new KeyedSubtree( + key: keyIndexGlobalKey, + child: new MergeSemantics( + child: new Semantics( + customSemanticsActions: semanticsActions, + child: toWrap, + ), + ), + ); } Widget buildDragTarget(BuildContext context, List acceptedCandidates, List rejectedCandidates) { diff --git a/packages/flutter/test/material/reorderable_list_test.dart b/packages/flutter/test/material/reorderable_list_test.dart index 483677068e..592dd9efe1 100644 --- a/packages/flutter/test/material/reorderable_list_test.dart +++ b/packages/flutter/test/material/reorderable_list_test.dart @@ -350,6 +350,63 @@ void main() { handle.dispose(); }); + + testWidgets("Doesn't hide accessibility when a child declares its own semantics", (WidgetTester tester) async { + final SemanticsHandle handle = tester.ensureSemantics(); + final Widget reorderableListView = new ReorderableListView( + children: [ + const SizedBox( + key: Key('List tile 1'), + height: itemHeight, + child: Text('List tile 1'), + ), + new SizedBox( + key: const Key('Switch tile'), + height: itemHeight, + child: new Material( + child: new SwitchListTile( + title: const Text('Switch tile'), + value: true, + onChanged: (bool newValue) {}, + ), + ), + ), + const SizedBox( + key: Key('List tile 2'), + height: itemHeight, + child: Text('List tile 2'), + ), + ], + scrollDirection: Axis.vertical, + onReorder: (int oldIndex, int newIndex) {}, + ); + await tester.pumpWidget(new MaterialApp( + home: new SizedBox( + height: itemHeight * 10, + child: reorderableListView, + ), + )); + + // Get the switch tile's semantics: + final SemanticsData semanticsData = tester.getSemanticsData(find.byKey(const Key('Switch tile'))); + + // Check for properties of both SwitchTile semantics and the ReorderableListView custom semantics actions. + expect(semanticsData, matchesSemanticsData( + hasToggledState: true, + isToggled: true, + isEnabled: true, + hasEnabledState: true, + label: 'Switch tile', + hasTapAction: true, + customActions: const [ + CustomSemanticsAction(label: 'Move up'), + CustomSemanticsAction(label: 'Move down'), + CustomSemanticsAction(label: 'Move to the end'), + CustomSemanticsAction(label: 'Move to the start'), + ], + )); + handle.dispose(); + }); }); });