Unverified Commit 722a085f authored by Darren Austin's avatar Darren Austin Committed by GitHub

Properly position the built-in drag handles on horizontal lists. (#79484)

parent 6fd2dcff
...@@ -369,25 +369,48 @@ class _ReorderableListViewState extends State<ReorderableListView> { ...@@ -369,25 +369,48 @@ class _ReorderableListViewState extends State<ReorderableListView> {
case TargetPlatform.linux: case TargetPlatform.linux:
case TargetPlatform.windows: case TargetPlatform.windows:
case TargetPlatform.macOS: case TargetPlatform.macOS:
return Stack( switch (widget.scrollDirection) {
key: itemGlobalKey, case Axis.horizontal:
children: <Widget>[ return Stack(
itemWithSemantics, key: itemGlobalKey,
Positioned.directional( children: <Widget>[
textDirection: Directionality.of(context), itemWithSemantics,
top: 0, Positioned.directional(
bottom: 0, textDirection: Directionality.of(context),
end: 8, start: 0,
child: Align( end: 0,
alignment: AlignmentDirectional.centerEnd, bottom: 8,
child: ReorderableDragStartListener( child: Align(
index: index, alignment: AlignmentDirectional.bottomCenter,
child: const Icon(Icons.drag_handle), child: ReorderableDragStartListener(
index: index,
child: const Icon(Icons.drag_handle),
),
),
), ),
), ],
), );
], case Axis.vertical:
); return Stack(
key: itemGlobalKey,
children: <Widget>[
itemWithSemantics,
Positioned.directional(
textDirection: Directionality.of(context),
top: 0,
bottom: 0,
end: 8,
child: Align(
alignment: AlignmentDirectional.centerEnd,
child: ReorderableDragStartListener(
index: index,
child: const Icon(Icons.drag_handle),
),
),
),
],
);
}
case TargetPlatform.iOS: case TargetPlatform.iOS:
case TargetPlatform.android: case TargetPlatform.android:
......
...@@ -30,8 +30,14 @@ void main() { ...@@ -30,8 +30,14 @@ void main() {
); );
} }
Widget build({ Widget? header, Axis scrollDirection = Axis.vertical, TextDirection textDirection = TextDirection.ltr }) { Widget build({
Widget? header,
Axis scrollDirection = Axis.vertical,
TextDirection textDirection = TextDirection.ltr,
TargetPlatform? platform,
}) {
return MaterialApp( return MaterialApp(
theme: ThemeData(platform: platform),
home: Directionality( home: Directionality(
textDirection: textDirection, textDirection: textDirection,
child: SizedBox( child: SizedBox(
...@@ -1309,6 +1315,28 @@ void main() { ...@@ -1309,6 +1315,28 @@ void main() {
expect(getTestItemPosition(), startPosition); expect(getTestItemPosition(), startPosition);
}); });
// TODO(djshuckerow): figure out how to write a test for scrolling the list. // TODO(djshuckerow): figure out how to write a test for scrolling the list.
testWidgets('Vertical list renders drag handle in correct position', (WidgetTester tester) async {
await tester.pumpWidget(build(platform: TargetPlatform.macOS));
final Finder listView = find.byType(ReorderableListView);
final Finder item1 = find.byKey(const Key('Item 1'));
final Finder dragHandle = find.byIcon(Icons.drag_handle).first;
// Should be centered vertically within the item and 8 pixels from the right edge of the list.
expect(tester.getCenter(dragHandle).dy, tester.getCenter(item1).dy);
expect(tester.getTopRight(dragHandle).dx, tester.getSize(listView).width - 8);
});
testWidgets('Horizontal list renders drag handle in correct position', (WidgetTester tester) async {
await tester.pumpWidget(build(scrollDirection: Axis.horizontal, platform: TargetPlatform.macOS));
final Finder listView = find.byType(ReorderableListView);
final Finder item1 = find.byKey(const Key('Item 1'));
final Finder dragHandle = find.byIcon(Icons.drag_handle).first;
// Should be centered horizontally within the item and 8 pixels from the bottom of the list.
expect(tester.getCenter(dragHandle).dx, tester.getCenter(item1).dx);
expect(tester.getBottomRight(dragHandle).dy, tester.getSize(listView).height - 8);
});
}); });
testWidgets('ReorderableListView, can deal with the dragged item getting unmounted and rebuilt during drag', (WidgetTester tester) async { testWidgets('ReorderableListView, can deal with the dragged item getting unmounted and rebuilt during drag', (WidgetTester tester) async {
......
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