Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(mobile): the tabs/search sheet closes with one tap or a short pull

Dev jacob882ea32c62d9
diff --git a/mobile/lib/phone/phone_search_field.dart b/mobile/lib/phone/phone_search_field.dart
index ea5fce988..a23b97479 100644
--- a/mobile/lib/phone/phone_search_field.dart
+++ b/mobile/lib/phone/phone_search_field.dart
@@ -150,6 +150,7 @@ class SheetSearchField extends StatelessWidget {
required this.onClear,
required this.hintText,
this.onCancel,
+ this.cancelLabel = 'Cancel',
});
final TextEditingController controller;
@@ -158,6 +159,10 @@ class SheetSearchField extends StatelessWidget {
final VoidCallback onClear;
final String hintText;
+ /// The word [onCancel] wears: "Cancel" while it ends a search, "Close" while
+ /// it closes the sheet.
+ final String cancelLabel;
+
/// "Cancel", beside the box. Null leaves it out.
///
/// Set for as long as the sheet is searching: it ends the SEARCH — results
@@ -226,7 +231,7 @@ class SheetSearchField extends StatelessWidget {
),
),
),
- _CancelButton(onTap: onCancel),
+ _CancelButton(onTap: onCancel, label: cancelLabel),
],
),
);
@@ -240,9 +245,10 @@ class SheetSearchField extends StatelessWidget {
/// would jump back to its full width over a gap. And the tap that ended the
/// search must not land on it a second time on the way out.
class _CancelButton extends StatelessWidget {
- const _CancelButton({required this.onTap});
+ const _CancelButton({required this.onTap, required this.label});
final VoidCallback? onTap;
+ final String label;
static const Duration _slide = Duration(milliseconds: 250);
@@ -280,7 +286,7 @@ class _CancelButton extends StatelessWidget {
height: SheetSearchField._height,
child: Center(
child: Text(
- 'Cancel',
+ label,
maxLines: 1,
style: TextStyle(
// The accent the caret already wears: the word belongs to
diff --git a/mobile/lib/phone/sheet_pull.dart b/mobile/lib/phone/sheet_pull.dart
new file mode 100644
index 000000000..27658f952
--- /dev/null
+++ b/mobile/lib/phone/sheet_pull.dart
@@ -0,0 +1,87 @@
+import 'package:flutter/widgets.dart';
+
+/// Lets the lists inside a sheet pull the sheet down, the way an iOS sheet
+/// does: a downward drag on a list already at its top moves the sheet, not
+/// the list.
+///
+/// ⚠️ **Without this, only the strip above the lists could close the sheet.**
+/// The lists win every vertical drag that starts on them. On a sheet standing
+/// full height, that left a grip-high band as the one place a thumb could pull
+/// from — "kéo mỏi tay".
+///
+/// The lists keep their bounce at the foot. At the top they stop dead instead
+/// ([_TopClampedPhysics]), so the pull past it reaches the sheet as overscroll
+/// rather than being spent on a bounce that would move the rows under a sheet
+/// that is itself moving.
+class SheetPull extends StatelessWidget {
+ const SheetPull({
+ super.key,
+ required this.onPull,
+ required this.onRelease,
+ required this.child,
+ });
+
+ /// Points the sheet should move down (negative: back up).
+ final ValueChanged<double> onPull;
+
+ /// The finger left a list mid-pull, at this downward velocity in points per
+ /// second.
+ final ValueChanged<double> onRelease;
+
+ final Widget child;
+
+ @override
+ Widget build(BuildContext context) {
+ return ScrollConfiguration(
+ behavior: const _TopClampedBehavior(),
+ child: NotificationListener<ScrollNotification>(
+ onNotification: _handle,
+ child: child,
+ ),
+ );
+ }
+
+ bool _handle(ScrollNotification notification) {
+ if (notification.metrics.axis != Axis.vertical) return false;
+ // Overscroll past the top, while a finger drives it — not a fling's coast.
+ if (notification is OverscrollNotification &&
+ notification.dragDetails != null &&
+ notification.overscroll < 0) {
+ onPull(-notification.overscroll);
+ }
+ if (notification is ScrollEndNotification) {
+ onRelease(notification.dragDetails?.primaryVelocity ?? 0);
+ }
+ return false;
+ }
+}
+
+class _TopClampedBehavior extends ScrollBehavior {
+ const _TopClampedBehavior();
+
+ @override
+ ScrollPhysics getScrollPhysics(BuildContext context) =>
+ _TopClampedPhysics(parent: super.getScrollPhysics(context));
+}
+
+/// The platform's physics, except that the top edge clamps: a drag past it is
+/// reported as overscroll instead of bouncing.
+class _TopClampedPhysics extends ScrollPhysics {
+ const _TopClampedPhysics({super.parent});
+
+ @override
+ _TopClampedPhysics applyTo(ScrollPhysics? ancestor) =>
+ _TopClampedPhysics(parent: buildParent(ancestor));
+
+ @override
+ double applyBoundaryConditions(ScrollMetrics position, double value) {
+ final top = position.minScrollExtent;
+ // Moving further past a top edge already reached.
+ if (value < position.pixels && position.pixels <= top) {
+ return value - position.pixels;
+ }
+ // Crossing the top edge in this step: stop at it, report the rest.
+ if (value < top && top < position.pixels) return value - top;
+ return super.applyBoundaryConditions(position, value);
+ }
+}
diff --git a/mobile/lib/phone/terminal_search.dart b/mobile/lib/phone/terminal_search.dart
index 7e3de9d71..ecbe57049 100644
--- a/mobile/lib/phone/terminal_search.dart
+++ b/mobile/lib/phone/terminal_search.dart
@@ -17,6 +17,7 @@ import 'phone_search_controller.dart';
import 'phone_search_field.dart';
import 'phone_search_results.dart';
import 'sheet_list.dart';
+import 'sheet_pull.dart';
/// The terminal's way to another agent: a sheet up from the bottom, over the
/// terminal, holding the account's tabs with a search field across its top.
@@ -133,6 +134,14 @@ class _TerminalSearchOverlayState extends State<TerminalSearchOverlay>
/// [BottomSheet]'s own figure, so this sheet lets go like the others do.
static const double _flingSpeed = 700;
+ /// How far a pull has to bring the sheet down to close it — or half its
+ /// height, where that is less (a keyboard standing under it).
+ ///
+ /// ⚠️ **Not [BottomSheet]'s half on its own.** That rule was written for a
+ /// sheet a share of the screen high; this one stands full height, so half of
+ /// it was a drag most of the way down the phone.
+ static const double _closeDistance = 120;
+
/// How close under the status bar the sheet's top edge stands while it
/// reads the tabs: a strip of the dimmed page left showing, which is what
/// says it is a layer over the terminal rather than a page of its own.
@@ -345,16 +354,24 @@ class _TerminalSearchOverlayState extends State<TerminalSearchOverlay>
openDeskAgent(context, notifier, group, entry);
}
- void _onPull(DragUpdateDetails details) {
- final height = _sheetKey.currentContext?.size?.height ?? 0;
+ double get _sheetHeight => _sheetKey.currentContext?.size?.height ?? 0;
+
+ /// Moves the sheet [points] down — from its own drag, or from a list's
+ /// overscroll ([SheetPull]). Never above where it stands open.
+ void _pullBy(double points) {
+ final height = _sheetHeight;
if (height <= 0) return;
- _pull.value += details.primaryDelta! / height;
+ _pull.value = math.max(0, _pull.value + points / height);
}
- /// Let go: closed on a fling down or past half its height — [BottomSheet]'s
- /// own rule — and back up otherwise.
- void _onRelease(DragEndDetails details) {
- if ((details.primaryVelocity ?? 0) > _flingSpeed || _pull.value > 0.5) {
+ /// Let go: closed on a fling down or past [_closeDistance], and back up
+ /// otherwise. A release with no pull behind it — a list's own scroll
+ /// ending — leaves the sheet alone.
+ void _release(double velocity) {
+ if (_pull.value == 0) return;
+ final pulled = _pull.value * _sheetHeight;
+ final closeAt = math.min(_closeDistance, _sheetHeight / 2);
+ if (velocity > _flingSpeed || pulled > closeAt) {
_close();
return;
}
@@ -495,8 +512,8 @@ class _TerminalSearchOverlayState extends State<TerminalSearchOverlay>
key: _sheetKey,
// The whole sheet can be pulled down, as a route's sheet can. The lists
// in it scroll on the same drag and win it where they are.
- onVerticalDragUpdate: _onPull,
- onVerticalDragEnd: _onRelease,
+ onVerticalDragUpdate: (details) => _pullBy(details.primaryDelta!),
+ onVerticalDragEnd: (details) => _release(details.primaryVelocity ?? 0),
onVerticalDragCancel: _settle,
child: CustomPaint(
foregroundPainter: _TopRim(color: AppGlass.hair),
@@ -537,10 +554,20 @@ class _TerminalSearchOverlayState extends State<TerminalSearchOverlay>
// search — the caret stays where the next query will go.
_focus.requestFocus();
},
- onCancel: _searching ? _cancel : null,
+ // Always a way out on the sheet's face: Cancel ends the
+ // search, Close the sheet — a full-height sheet leaves too
+ // little dimmed page to tap and too far to pull.
+ onCancel: _searching ? _cancel : _close,
+ cancelLabel: _searching ? 'Cancel' : 'Close',
+ ),
+ ),
+ Expanded(
+ child: SheetPull(
+ onPull: _pullBy,
+ onRelease: _release,
+ child: _content(),
),
),
- Expanded(child: _content()),
],
),
),
diff --git a/mobile/test/phone_search_test.dart b/mobile/test/phone_search_test.dart
index 925e3d53d..6d65be8d5 100644
--- a/mobile/test/phone_search_test.dart
+++ b/mobile/test/phone_search_test.dart
@@ -1283,6 +1283,70 @@ void main() {
expect(closed, 1);
});
+ // The sheet stands full height, so the dimmed strip above it is too thin
+ // to tap and half its height too far to pull. It needs a way out that
+ // costs one tap or a short pull from anywhere on it.
+ group('terminal search: the sheet closes without a long pull', () {
+ Future<int Function()> openSheet(
+ WidgetTester tester, {
+ int agents = 1,
+ }) async {
+ final app = _app([
+ _machine('box', [
+ for (var i = 0; i < agents; i++) _agent('${3100 + i}', minutesAgo: i),
+ ]),
+ ]);
+ addTearDown(app.dispose);
+ var closed = 0;
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: TerminalSearchOverlay(
+ notifier: app,
+ animation: const AlwaysStoppedAnimation(1),
+ onClose: () => closed++,
+ ),
+ ),
+ ),
+ );
+ await tester.pump();
+ return () => closed;
+ }
+
+ testWidgets('Close sits beside the field and closes it in one tap', (
+ tester,
+ ) async {
+ final closed = await openSheet(tester);
+ await tester.pump(const Duration(milliseconds: 400));
+
+ await tester.tap(find.text('Close'));
+ await tester.pump();
+ expect(closed(), 1);
+ });
+
+ // Enough rows to scroll, so the pull goes through the list's own drag:
+ // the list is at its top, and the overscroll moves the sheet instead.
+ testWidgets('a short pull down on the list closes it', (tester) async {
+ final closed = await openSheet(tester, agents: 30);
+ final list = find.byType(Scrollable).last;
+
+ await tester.drag(list, const Offset(0, 160));
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 300));
+ expect(closed(), 1);
+ });
+
+ testWidgets('a nudge settles back up, and leaves it open', (tester) async {
+ final closed = await openSheet(tester, agents: 30);
+ final list = find.byType(Scrollable).last;
+
+ await tester.drag(list, const Offset(0, 40));
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 300));
+ expect(closed(), 0);
+ });
+ });
+
testWidgets('one bar: no Cancel beside it, and its chevron closes search', (
tester,
) async {