fix: keep dock drag springs live and add elastic leading-edge pull

This commit is contained in:
david1465833828
2026-10-28 11:57:44 +08:00
parent 6604f31d98
commit c5cfbced5c
9 changed files with 261 additions and 42 deletions
+73 -2
View File
@@ -11,6 +11,37 @@ import 'navigation_test.dart' show uiController;
void main() {
setUpAll(tzdata.initializeTimeZones);
testWidgets('drag tugs the leading edge and lens follows with elastic lag', (
tester,
) async {
await tester.pumpWidget(_dock());
await tester.pumpAndSettle();
await tester.tap(find.byIcon(Icons.assignment_rounded));
await tester.pumpAndSettle();
final lens = find.byType(GlassRefraction).last;
final body = find.byType(GlassRefraction).first;
final gesture = await tester.startGesture(
tester.getCenter(find.byKey(const Key('dock-cursor'))),
);
await tester.pump(const Duration(milliseconds: 110));
await tester.pump(const Duration(milliseconds: 700));
await gesture.moveBy(const Offset(24, 0));
await tester.pump();
final initialX = tester.getCenter(lens).dx;
final initialBody = tester.getRect(body);
await gesture.moveBy(const Offset(60, 0));
await tester.pump();
expect(tester.getCenter(lens).dx - initialX, lessThan(45));
await tester.pump(const Duration(milliseconds: 180));
expect(tester.getCenter(lens).dx, greaterThan(initialX + 35));
final draggedBody = tester.getRect(body);
final leading = draggedBody.right - initialBody.right;
final trailing = draggedBody.left - initialBody.left;
expect(leading - trailing, greaterThan(7));
await gesture.cancel();
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
});
testWidgets('inactive icon press leaves the cursor at its resting size', (
tester,
) async {
@@ -80,6 +111,42 @@ void main() {
await tester.pumpAndSettle();
expect(tester.getSize(body), resting.size);
});
testWidgets(
'lens keeps softly stretching and squeezing during an even drag',
(tester) async {
await tester.pumpWidget(_dock());
await tester.pumpAndSettle();
final lens = find.byType(GlassRefraction).last;
final gesture = await tester.startGesture(
tester.getCenter(find.byKey(const Key('dock-cursor'))),
);
await tester.pump(const Duration(milliseconds: 110));
await tester.pump(const Duration(milliseconds: 700));
await gesture.moveBy(const Offset(24, 0));
await tester.pump();
final widths = <double>[], heights = <double>[], centres = <double>[];
for (var i = 0; i < 22; i++) {
await gesture.moveBy(const Offset(5, 0));
await tester.pump(const Duration(milliseconds: 20));
if (i > 3) {
final size = tester.getSize(lens);
widths.add(size.width);
heights.add(size.height);
centres.add(tester.getCenter(lens).dx);
}
}
expect(widths.reduce(math.max) - widths.reduce(math.min), greaterThan(6));
expect(
heights.reduce(math.max) - heights.reduce(math.min),
greaterThan(2),
);
expect(centres.last - centres.first, greaterThan(50));
await gesture.up();
await tester.pumpAndSettle();
expect(tester.getSize(lens).width, closeTo(86, 0.1));
expect(tester.getSize(lens).height, closeTo(52, 0.1));
},
);
testWidgets(
'rapid reverse taps keep position continuous and finish on last tab',
(tester) async {
@@ -258,7 +325,9 @@ void main() {
await tester.pump();
await gesture.moveBy(const Offset(86, 0));
await tester.pump();
await tester.pump(const Duration(milliseconds: 180));
for (var frame = 0; frame < 12; frame++) {
await tester.pump(const Duration(milliseconds: 16));
}
expect(tester.getCenter(icon).dy, lessThan(y - 1));
await tester.pump(const Duration(milliseconds: 600));
expect(tester.getCenter(icon).dy, closeTo(y, 0.1));
@@ -278,7 +347,9 @@ void main() {
await tester.pump();
await gesture.moveBy(const Offset(86, 0));
await tester.pump();
await tester.pump(const Duration(milliseconds: 180));
for (var frame = 0; frame < 12; frame++) {
await tester.pump(const Duration(milliseconds: 16));
}
final before = tester.getRect(icon);
await gesture.up();
await tester.pump();