Skip to content

Commit

Permalink
Reverts "Draggable feedback positioning (#145647)" (#147658)
Browse files Browse the repository at this point in the history
Reverts: flutter/flutter#145647
Initiated by: jmagman
Reason for reverting: Failing draggable_test in post-submit.
Original PR Author: timcreatedit

Reviewed By: {justinmc, goderbauer}

This change reverts the following previous change:
We changed the coordinates used to position the `Draggable` feedback by transforming them into the `Overlay`s coordinate space. This has no influence on any untransformed `Overlay`, most Flutter apps should be not affected. 
This PR fixes the positioning of the feedback in transformed context (see #145639 for before video):

https://github.com/flutter/flutter/assets/42270125/df34e198-0667-453d-a27a-a79b2e2825a1

- fixes #145639
  • Loading branch information
auto-submit[bot] authored May 1, 2024
1 parent 71a2945 commit 5a41e1e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 134 deletions.
11 changes: 4 additions & 7 deletions packages/flutter/lib/src/widgets/drag_target.dart
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,6 @@ class _DragAvatar<T extends Object> extends Drag {
final List<_DragTargetState<Object>> _enteredTargets = <_DragTargetState<Object>>[];
Offset _position;
Offset? _lastOffset;
late Offset _overlayOffset;
OverlayEntry? _entry;

@override
Expand All @@ -859,10 +858,6 @@ class _DragAvatar<T extends Object> extends Drag {

void updateDrag(Offset globalPosition) {
_lastOffset = globalPosition - dragStartPoint;
final RenderBox box = overlayState.context.findRenderObject()! as RenderBox;
final Offset overlaySpaceOffset = box.globalToLocal(globalPosition);
_overlayOffset = overlaySpaceOffset - dragStartPoint;

_entry!.markNeedsBuild();
final HitTestResult result = HitTestResult();
WidgetsBinding.instance.hitTestInView(result, globalPosition + feedbackOffset, viewId);
Expand Down Expand Up @@ -948,9 +943,11 @@ class _DragAvatar<T extends Object> extends Drag {
}

Widget _build(BuildContext context) {
final RenderBox box = overlayState.context.findRenderObject()! as RenderBox;
final Offset overlayTopLeft = box.localToGlobal(Offset.zero);
return Positioned(
left: _overlayOffset.dx,
top: _overlayOffset.dy,
left: _lastOffset!.dx - overlayTopLeft.dx,
top: _lastOffset!.dy - overlayTopLeft.dy,
child: ExcludeSemantics(
excluding: ignoringFeedbackSemantics,
child: IgnorePointer(
Expand Down
127 changes: 0 additions & 127 deletions packages/flutter/test/widgets/draggable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -967,10 +967,6 @@ void main() {
await gesture.moveTo(thirdLocation);
await tester.pump();
expect(tester.getTopLeft(find.text('N')), thirdLocation);

// Finish gesture to release resources.
await gesture.up();
await tester.pump();
});

testWidgets('Horizontal axis draggable moves horizontally', (WidgetTester tester) async {
Expand All @@ -986,10 +982,6 @@ void main() {
await gesture.moveTo(thirdLocation);
await tester.pump();
expect(tester.getTopLeft(find.text('H')), thirdLocation);

// Finish gesture to release resources.
await gesture.up();
await tester.pump();
});

testWidgets('Horizontal axis draggable does not move vertically', (WidgetTester tester) async {
Expand All @@ -1008,10 +1000,6 @@ void main() {
await gesture.moveTo(thirdDragLocation);
await tester.pump();
expect(tester.getTopLeft(find.text('H')), thirdWidgetLocation);

// Finish gesture to release resources.
await gesture.up();
await tester.pump();
});

testWidgets('Vertical axis draggable moves vertically', (WidgetTester tester) async {
Expand All @@ -1027,10 +1015,6 @@ void main() {
await gesture.moveTo(thirdLocation);
await tester.pump();
expect(tester.getTopLeft(find.text('V')), thirdLocation);

// Finish gesture to release resources.
await gesture.up();
await tester.pump();
});

testWidgets('Vertical axis draggable does not move horizontally', (WidgetTester tester) async {
Expand All @@ -1049,10 +1033,6 @@ void main() {
await gesture.moveTo(thirdDragLocation);
await tester.pump();
expect(tester.getTopLeft(find.text('V')), thirdWidgetLocation);

// Finish gesture to release resources.
await gesture.up();
await tester.pump();
});
});

Expand Down Expand Up @@ -1686,10 +1666,6 @@ void main() {
expect(find.text('Dragging'), findsOneWidget);
expect(find.text('Target'), findsOneWidget);
expect(find.text('Rejected'), findsNothing);

// Finish gesture to release resources.
await gesture.up();
await tester.pump();
});


Expand Down Expand Up @@ -3123,10 +3099,6 @@ void main() {
),
findsNothing,
);

// Finish gesture to release resources.
await gesture.up();
await tester.pump();
});

testWidgets('Drag feedback is put on root overlay with [rootOverlay] flag', (WidgetTester tester) async {
Expand Down Expand Up @@ -3525,93 +3497,6 @@ void main() {
await tester.pumpAndSettle();
});

testWidgets('Drag and drop - feedback matches pointer in scaled MaterialApp', (WidgetTester tester) async {
await tester.pumpWidget(Transform.scale(
scale: 0.5,
child: const MaterialApp(
home: Scaffold(
body: Draggable<int>(
data: 42,
feedback: Text('Feedback'),
child: Text('Source'),
),
),
),
));

final Offset location = tester.getTopLeft(find.text('Source'));
final TestGesture gesture = await tester.startGesture(location);
final Offset secondLocation = location + const Offset(100, 100);
await gesture.moveTo(secondLocation);
await tester.pump();
final Offset appTopLeft = tester.getTopLeft(find.byType(MaterialApp));
expect(tester.getTopLeft(find.text('Source')), appTopLeft);
expect(tester.getTopLeft(find.text('Feedback')), secondLocation);

// Finish gesture to release resources.
await gesture.up();
await tester.pumpAndSettle();
});

testWidgets('Drag and drop - childDragAnchorStrategy works in scaled MaterialApp', (WidgetTester tester) async {
final Key sourceKey = UniqueKey();
final Key feedbackKey = UniqueKey();
await tester.pumpWidget(Transform.scale(
scale: 0.5,
child: MaterialApp(
home: Scaffold(
body: Draggable<int>(
data: 42,
feedback: Text('Text', key: feedbackKey),
child: Text('Text', key: sourceKey),
),
),
),
));
final Finder source = find.byKey(sourceKey);
final Finder feedback = find.byKey(feedbackKey);

final TestGesture gesture = await tester.startGesture(tester.getCenter(source));
await tester.pump();
expect(tester.getTopLeft(source), tester.getTopLeft(feedback));

// Finish gesture to release resources.
await gesture.up();
await tester.pumpAndSettle();
});

testWidgets('Drag and drop - feedback matches pointer in rotated MaterialApp', (WidgetTester tester) async {
await tester.pumpWidget(Transform.rotate(
angle: 1, // ~57 degrees
child: const MaterialApp(
home: Scaffold(
body: Draggable<int>(
data: 42,
feedback: Text('Feedback'),
child: Text('Source'),
),
),
),
));

final Offset location = tester.getTopLeft(find.text('Source'));
final TestGesture gesture = await tester.startGesture(location);
final Offset secondLocation = location + const Offset(100, 100);
await gesture.moveTo(secondLocation);
await tester.pump();
final Offset appTopLeft = tester.getTopLeft(find.byType(MaterialApp));
expect(tester.getTopLeft(find.text('Source')), appTopLeft);
final Offset feedbackTopLeft = tester.getTopLeft(find.text('Feedback'));

// Different rotations can incur rounding errors, this makes it more robust
expect(feedbackTopLeft.dx, moreOrLessEquals(secondLocation.dx));
expect(feedbackTopLeft.dy, moreOrLessEquals(secondLocation.dy));

// Finish gesture to release resources.
await gesture.up();
await tester.pumpAndSettle();
});

testWidgets('configurable Draggable hit test behavior', (WidgetTester tester) async {
const HitTestBehavior hitTestBehavior = HitTestBehavior.deferToChild;

Expand Down Expand Up @@ -3688,10 +3573,6 @@ void main() {

await tester.tap(find.text('Draggable'));
expect(onTap, true);

// Finish gesture to release resources.
await gesture.up();
await tester.pump();
});

testWidgets('configurable feedback ignore pointer behavior - LongPressDraggable', (WidgetTester tester) async {
Expand Down Expand Up @@ -3723,10 +3604,6 @@ void main() {

await tester.tap(find.text('Draggable'));
expect(onTap, true);

// Finish gesture to release resources.
await gesture.up();
await tester.pump();
});

testWidgets('configurable DragTarget hit test behavior', (WidgetTester tester) async {
Expand Down Expand Up @@ -3934,10 +3811,6 @@ Future<void> _testChildAnchorFeedbackPosition({ required WidgetTester tester, do
final Offset sourceTopLeft = tester.getTopLeft(find.text('Source'));
final Offset dragOffset = secondLocation - firstLocation;
expect(feedbackTopLeft, equals(sourceTopLeft + dragOffset));

// Finish gesture to release resources.
await gesture.up();
await tester.pump();
}

class DragTargetData { }
Expand Down

0 comments on commit 5a41e1e

Please sign in to comment.