From 44ea45150ffe5e1d0a1e5327de3ec004f23972ab Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sat, 31 Oct 2026 16:53:24 +0000 Subject: [PATCH] Compact floating tab bars with circular selection and equal edge gaps The floating tab bar is now sized to its icon tabs at the bottom right on every width, the selected icon sits in a tinted circle on both hosts, and the gap from each outer circle to the pill's sides equals the gap to its top, bottom and neighbours. --- .../ui/adaptive/floating_destination_bar.dart | 164 +++++++++---- app/notes/tab-bar-edge-gaps.md | 29 +++ .../pipelines/pipeline_tabs_test.dart | 18 +- .../runs/ui/run_detail_tabs_test.dart | 11 +- .../ui/run_detail_visit_sections_test.dart | 12 +- app/test/shell/floating_tab_bar_test.dart | 40 +++- app/test/shell/shell_bar_test.dart | 7 +- .../shell/split_destination_bar_test.dart | 8 +- .../adaptive/floating_bar_edge_gap_test.dart | 219 ++++++++++++++++++ 9 files changed, 430 insertions(+), 78 deletions(-) create mode 100644 app/notes/tab-bar-edge-gaps.md create mode 100644 app/test/ui/adaptive/floating_bar_edge_gap_test.dart diff --git a/app/lib/ui/adaptive/floating_destination_bar.dart b/app/lib/ui/adaptive/floating_destination_bar.dart index 13edb089..958e999f 100644 --- a/app/lib/ui/adaptive/floating_destination_bar.dart +++ b/app/lib/ui/adaptive/floating_destination_bar.dart @@ -10,12 +10,15 @@ import 'glass_pill.dart'; /// instead of becoming a full-width system bar. Used for the app's /// destinations and for every page's own tabs. /// -/// Placement follows the width the bar is given, live: below -/// [kFloatingBarWideWidth] the pill spans it minus [kFloatingBarMargin] on -/// each side; at or above it the pill is only as wide as its tabs and sits at -/// the trailing (right, in left-to-right text) edge, near the thumb. Either -/// way it keeps [kFloatingBarMargin] above the bottom safe area. Only the pill -/// takes taps: the space beside it reaches the content behind. +/// At any width the pill is only as wide as its icon tabs and sits at the +/// trailing (right, in left-to-right text) edge, near the thumb, keeping +/// [kFloatingBarMargin] from the sides and above the bottom safe area. Only +/// the pill takes taps: the space beside it reaches the content behind. +/// +/// The selected tab's icon sits in a tinted circle. Each circle keeps the +/// same gap from its neighbours as from the pill's top and bottom, and the +/// outer ones the same gap from the pill's sides, so the pill's round ends +/// are concentric with them. /// /// The tabs show icons only. Each tab's label stays its accessible name (and /// the Material tooltip), so screen readers still announce it; the icons must @@ -38,24 +41,44 @@ class FloatingDestinationBar extends StatelessWidget { final bool cupertino; /// The edge the bar floats at. At [FloatingBarEdge.top] (an open item's - /// tabs under its pane's top bar) a wide bar sits at the leading edge, in - /// line with the bar's title, and keeps no bottom safe area. + /// tabs under its pane's top bar) the bar sits at the leading edge, in line + /// with the bar's title, and keeps no bottom safe area. final FloatingBarEdge edge; final int currentIndex; final ValueChanged onTap; final List items; /// Height of the Material bar inside the pill (the stock bar is 80; with - /// labels hidden the icon and its indicator need less). + /// labels hidden the icon and its highlight need less). static const double materialHeight = 56; /// Height of the Cupertino bar inside the pill (the stock bar's 50). static const double cupertinoHeight = 50; - /// Width of one icon-only tab on a wide window: a comfortable touch target - /// around the Material indicator (64) or the Cupertino selection capsule. - static const double materialTabWidth = 72; - static const double cupertinoTabWidth = 64; + /// Padding between the icon (Material 24, Cupertino 26) and the edge of + /// its selection circle. + static const double _materialRing = 8; + static const double _cupertinoRing = 6; + + /// Diameter of the selection circle. + static const double materialHighlightSize = 24 + 2 * _materialRing; + static const double cupertinoHighlightSize = 26 + 2 * _cupertinoRing; + + /// The gap between a tab's circle and the pill's top and bottom; the outer + /// circles keep the same gap from the pill's sides, and neighbours from + /// each other. + static const double materialEdgeGap = + (materialHeight - materialHighlightSize) / 2; + static const double cupertinoEdgeGap = + (cupertinoHeight - cupertinoHighlightSize) / 2; + + /// Width of one tab: its circle and one edge gap (48 Material, 44 + /// Cupertino: the platforms' minimum touch targets). The pill is one more + /// edge gap wider than its tabs. + static const double materialTabWidth = + materialHighlightSize + materialEdgeGap; + static const double cupertinoTabWidth = + cupertinoHighlightSize + cupertinoEdgeGap; /// The side margin at [FloatingBarEdge.top], matching the top bar's own. static const double topMargin = 12; @@ -63,27 +86,18 @@ class FloatingDestinationBar extends StatelessWidget { @override Widget build(BuildContext context) { final top = edge == FloatingBarEdge.top; - final margins = 2 * (top ? topMargin : kFloatingBarMargin); final bar = LayoutBuilder( builder: (context, constraints) { - // Wide is judged on the space the bar is given, margins included, - // the way the shell and the pages judge their own layouts. - final available = constraints.maxWidth; - final wide = available + margins >= kFloatingBarWideWidth; - final width = wide - ? math.min(available, _tabsWidth(context)) - : available; + final width = math.max(0.0, math.min(constraints.maxWidth, _tabsWidth)); return Align( // As tall as the pill, so a scaffold or overlay measures the bar // and not the whole area it may grow into. heightFactor: 1, - alignment: !wide - ? Alignment.bottomCenter - : top + alignment: top ? AlignmentDirectional.topStart : AlignmentDirectional.bottomEnd, child: SizedBox( - width: math.max(0, width), + width: width, // The insets are handled around the pill. The host bars pad // themselves by any media padding left over (a page's top bar, // another floating bar below a pane), which would swell the pill. @@ -95,9 +109,10 @@ class FloatingDestinationBar extends StatelessWidget { removeRight: true, child: GlassPill( cupertino: cupertino, - child: cupertino - ? _cupertinoBar(context) - : _materialBar(context), + child: _edgeAligned( + width, + cupertino ? _cupertinoBar(context) : _materialBar(context), + ), ), ), ), @@ -124,19 +139,48 @@ class FloatingDestinationBar extends StatelessWidget { ); } + double get _highlight => + cupertino ? cupertinoHighlightSize : materialHighlightSize; + double get _gap => cupertino ? cupertinoEdgeGap : materialEdgeGap; + /// The width the icon-only tabs need side by side. Icons do not scale with /// text, so the pill keeps its size at any text scale. - double _tabsWidth(BuildContext context) => - (cupertino ? cupertinoTabWidth : materialTabWidth) * items.length; + double get _tabsWidth => pillWidth(cupertino: cupertino, tabs: items.length); + + /// The width of a pill holding [tabs] tabs, when the space allows it. + static double pillWidth({required bool cupertino, required int tabs}) => + cupertino + ? cupertinoTabWidth * tabs + cupertinoEdgeGap + : materialTabWidth * tabs + materialEdgeGap; + + /// Insets the host bar's equal tab slots so the outer circles sit the edge + /// gap from the pill's sides. A pill squeezed below its tabs' width keeps + /// that gap and narrows the gaps between neighbours instead, as long as + /// the circles still fit side by side. + Widget _edgeAligned(double width, Widget bar) { + final count = items.length; + var inset = _gap / 2; + if (count > 1) { + final slot = (width - _highlight - 2 * _gap) / (count - 1); + inset = slot >= _highlight ? (width - slot * count) / 2 : 0; + } + return Padding( + padding: EdgeInsets.symmetric(horizontal: math.max(0, inset)), + child: bar, + ); + } Widget _materialBar(BuildContext context) { final scheme = Theme.of(context).colorScheme; return NavigationBarTheme( - data: NavigationBarThemeData( + data: const NavigationBarThemeData( backgroundColor: Colors.transparent, elevation: 0, surfaceTintColor: Colors.transparent, - indicatorColor: scheme.secondaryContainer, + // The selected icon draws its own circle (the stock indicator is a + // fixed 64x32); the stock one stays for its circular ink response. + indicatorColor: Colors.transparent, + indicatorShape: CircleBorder(), height: materialHeight, // Icons only; the label remains each tab's accessible name and its // tooltip. @@ -150,7 +194,11 @@ class FloatingDestinationBar extends StatelessWidget { NavigationDestination( key: item.key, icon: item.icon, - selectedIcon: item.selectedIcon ?? item.icon, + selectedIcon: _SelectionCircle( + color: scheme.secondaryContainer, + ring: _materialRing, + child: item.selectedIcon ?? item.icon, + ), label: item.label, ), ], @@ -160,27 +208,27 @@ class FloatingDestinationBar extends StatelessWidget { /// The stock Cupertino bar, transparent inside the pill. Each tab shows its /// icon only, named by its label for accessibility; the item's key covers - /// the whole tab, and the selected tab's icon sits in a tinted capsule so + /// the whole tab, and the selected tab's icon sits in a tinted circle so /// the selection reads at a glance, not by colour alone. Widget _cupertinoBar(BuildContext context) { final active = CupertinoTheme.of(context).primaryColor; Widget tab(FloatingDestinationItem item, {required bool selected}) { - Widget icon = item.icon; - if (selected) { - icon = DecoratedBox( - decoration: ShapeDecoration( - color: active.withValues(alpha: 0.16), - shape: const StadiumBorder(), - ), - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 2), - child: item.selectedIcon ?? item.icon, - ), - ); - } + final icon = selected + ? _SelectionCircle( + color: active.withValues(alpha: 0.16), + ring: _cupertinoRing, + child: item.selectedIcon ?? item.icon, + ) + : item.icon; return KeyedSubtree( key: item.key, - child: Semantics(label: item.label, child: icon), + child: Semantics( + label: item.label, + // The host centres the icon above a 4px bottom inset; 4 above it + // centres the icon and its circle in the whole bar, so the circle + // is as far from the pill's top as from its bottom. + child: Padding(padding: const EdgeInsets.only(top: 4), child: icon), + ), ); } @@ -208,6 +256,26 @@ class FloatingDestinationBar extends StatelessWidget { } } +/// The selected tab's icon (and any badge on it) in a tinted circle, [ring] +/// wider than the icon on every side. +class _SelectionCircle extends StatelessWidget { + const _SelectionCircle({ + required this.color, + required this.ring, + required this.child, + }); + + final Color color; + final double ring; + final Widget child; + + @override + Widget build(BuildContext context) => DecoratedBox( + decoration: ShapeDecoration(color: color, shape: const CircleBorder()), + child: Padding(padding: EdgeInsets.all(ring), child: child), + ); +} + /// The platform-neutral data needed by [FloatingDestinationBar]. class FloatingDestinationItem { const FloatingDestinationItem({ diff --git a/app/notes/tab-bar-edge-gaps.md b/app/notes/tab-bar-edge-gaps.md new file mode 100644 index 00000000..8117b3eb --- /dev/null +++ b/app/notes/tab-bar-edge-gaps.md @@ -0,0 +1,29 @@ +# Floating tab bars: compact everywhere, circular selection, equal gaps + +Supersedes the "Sizes" bullets of `notes/tab-bars-v2.md` and its "at 560 the +bars are full width". + +- `FloatingDestinationBar` is compact at every width: sized to its tabs at + the bottom right (top start at `FloatingBarEdge.top`), on phones too. Taps + beside it reach the content. +- The selected icon sits in a tinted circle (Material 40 = 24 + 2x8 in + `secondaryContainer`, the stock indicator made transparent with a + `CircleBorder` ink; Cupertino 38 = 26 + 2x6 in the primary colour at 16%). +- One gap everywhere: circle to pill top/bottom, outer circle to pill side, + and between neighbours. Material 8 (pill 56 high, tab 48, 4 tabs = 200 + wide); Cupertino 6 (pill 50, tab 44, 4 tabs = 182). The pill's round ends + are concentric with the outer circles. `FloatingDestinationBar.pillWidth` + gives the width; a squeezed pill keeps the edge gap and narrows the inner + gaps. +- Cupertino: the icon gets 4 top padding to cancel the host's 4 bottom + inset, so the circle is vertically centred. + +Tests: `test/ui/adaptive/floating_bar_edge_gap_test.dart` (both hosts; 1200/4, +390/3, 390/4, 560/5, 320/5 tabs; first and last selected: side gap = top gap += bottom gap = neighbour gap within 1px; concentric ends; phone taps beside +the bar; 320 at 2x without overflow). Phone full-width assertions in shell, +run, stage and pipeline tab tests were updated to the compact width. + +Evidence: `/tmp/tab-edge-evidence/` — `{material,cupertino}-{light,dark}- +{pipelines,search}-{560,1200}.png` from `tool/floating_tabs_probe_entry.dart` +in headless Chrome (first and last tab selected). diff --git a/app/test/features/pipelines/pipeline_tabs_test.dart b/app/test/features/pipelines/pipeline_tabs_test.dart index 91980d52..bec026fa 100644 --- a/app/test/features/pipelines/pipeline_tabs_test.dart +++ b/app/test/features/pipelines/pipeline_tabs_test.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/pipelines/widgets/pipeline_tabs.dart'; import 'package:pipelines_app/features/pipelines/widgets/pipeline_detail_styles.dart'; +import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart'; import 'package:pipelines_app/ui/adaptive/glass_pill.dart'; void main() { @@ -66,14 +67,15 @@ void main() { findsOneWidget, ); final pill = tester.getRect(find.byType(GlassPill)); - if (width < 600) { - expect(pill.left, 16); - expect(pill.right, width - 16); - } else { - // Sized to its three tabs at the right edge. - expect(pill.right, width - 16); - expect(pill.width, lessThan(width * 0.6)); - } + // Sized to its three tabs at the right edge, on a phone as when wide. + expect(pill.right, width - 16); + expect( + pill.width, + FloatingDestinationBar.pillWidth( + cupertino: cupertino, + tabs: PipelineDetailTab.values.length, + ), + ); for (final tab in PipelineDetailTab.values) { final rect = tester.getRect( find.byKey(ValueKey('pipeline-detail-tab-${tab.name}')), diff --git a/app/test/features/runs/ui/run_detail_tabs_test.dart b/app/test/features/runs/ui/run_detail_tabs_test.dart index bbc24f26..d13bce53 100644 --- a/app/test/features/runs/ui/run_detail_tabs_test.dart +++ b/app/test/features/runs/ui/run_detail_tabs_test.dart @@ -5,6 +5,7 @@ import 'package:pipelines_app/features/runs/ui/run_more_menu.dart'; import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart'; import 'package:pipelines_app/features/runs/ui/run_detail_tab.dart'; import 'package:pipelines_app/features/runs/ui/run_detail_tab_strip.dart'; +import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart'; import 'package:pipelines_app/ui/adaptive/glass_pill.dart'; import 'run_detail_graph_support.dart'; @@ -91,8 +92,14 @@ void main() { find.descendant(of: strip, matching: find.byType(GlassPill)), ); final body = find.byKey(const Key('run-detail-tab-body-summary')); - // Full width minus the margins, floating above the bottom. - expect(pill.left, 16); + // Sized to its tabs at the right, floating above the bottom. + expect( + pill.width, + FloatingDestinationBar.pillWidth( + cupertino: platform != RunDetailTestPlatform.material, + tabs: renderedRunDetailTabs.length, + ), + ); expect(pill.right, 390 - 16); expect(pill.bottom, 844 - 16); // The tab's content reaches the bottom edge, behind the bar. diff --git a/app/test/features/runs/ui/run_detail_visit_sections_test.dart b/app/test/features/runs/ui/run_detail_visit_sections_test.dart index 1de88acb..93d6a00f 100644 --- a/app/test/features/runs/ui/run_detail_visit_sections_test.dart +++ b/app/test/features/runs/ui/run_detail_visit_sections_test.dart @@ -245,8 +245,8 @@ void main() { final strip = tester.getRect(find.byType(RunVisitSectionStrip)); expect(strip.bottom, size.height, reason: section.name); } - // The floating glass bar: full width on a phone, sized to its tabs - // at the right edge of a wide page. + // The floating glass bar: sized to its tabs at the right edge, on + // a phone as on a wide page. final pill = tester.getRect( find.descendant( of: find.byType(RunVisitSectionStrip), @@ -255,12 +255,8 @@ void main() { ); expect(pill.right, size.width - 16); expect(pill.bottom, size.height - 16); - if (size.width < 600) { - expect(pill.left, 16); - } else { - // (The test font draws every glyph a full em wide.) - expect(pill.width, lessThan(size.width * 0.7)); - } + // Sized to its tabs at the right on every width. + expect(pill.width, lessThan(size.width * 0.7)); }, ); } diff --git a/app/test/shell/floating_tab_bar_test.dart b/app/test/shell/floating_tab_bar_test.dart index b9aec69b..effc66aa 100644 --- a/app/test/shell/floating_tab_bar_test.dart +++ b/app/test/shell/floating_tab_bar_test.dart @@ -48,16 +48,25 @@ void main() { for (final cupertino in [false, true]) { final host = cupertino ? 'Cupertino' : 'Material'; - testWidgets('$host: phone bar spans the width minus its margins', ( - tester, - ) async { + testWidgets('$host: phone bar hugs its tabs at the bottom right too, and ' + 'taps beside it reach the content', (tester) async { + taps = 0; await setSize(tester, const Size(390, 844)); await tester.pumpWidget(shell(cupertino: cupertino)); final rect = tester.getRect(pill()); - expect(rect.left, 16); + expect( + rect.width, + FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4), + ); expect(rect.right, 390 - 16); expect(rect.bottom, 844 - 16); expect(find.byType(NavigationRail), findsNothing); + await tester.tapAt(Offset(rect.left - 40, rect.center.dy)); + await tester.pump(); + expect(taps, 1); + await tester.tap(find.byKey(const ValueKey('shell.destination.chat'))); + await tester.pumpAndSettle(); + expect(find.text('Chat — Not implemented'), findsOneWidget); }); testWidgets('$host: wide bar hugs its tabs at the right edge, content ' @@ -69,13 +78,17 @@ void main() { expect(rect.right, 1200 - 16); expect(rect.bottom, 800 - 16); expect(rect.width, lessThan(1200 * 0.6)); - // Four icon-only tabs (Settings opens from the Pipelines bar). + // Four icon-only tabs (Settings opens from the Pipelines bar) and one + // more edge gap, so the outer circles keep it from the sides. expect( rect.width, 4 * + (cupertino + ? FloatingDestinationBar.cupertinoTabWidth + : FloatingDestinationBar.materialTabWidth) + (cupertino - ? FloatingDestinationBar.cupertinoTabWidth - : FloatingDestinationBar.materialTabWidth), + ? FloatingDestinationBar.cupertinoEdgeGap + : FloatingDestinationBar.materialEdgeGap), ); // No rail or sidebar: the content starts at the left edge. expect(find.byType(NavigationRail), findsNothing); @@ -127,7 +140,11 @@ void main() { tester.view.physicalSize = const Size(390, 844); await tester.pump(); - expect(tester.getRect(pill()).width, 390 - 32); + expect( + tester.getRect(pill()).width, + FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4), + ); + expect(tester.getRect(pill()).right, 390 - 16); expect(tester.state(find.byType(StatefulBuilder)), same(state)); }); @@ -186,7 +203,12 @@ void main() { await tester.pumpWidget(shell(cupertino: cupertino)); await tester.pumpAndSettle(); expect(tester.takeException(), isNull); - expect(tester.getRect(pill()).width, 320 - 32); + // Sized to its four tabs at the right, as on any width. + expect( + tester.getRect(pill()).width, + FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4), + ); + expect(tester.getRect(pill()).right, 320 - 16); } }); } diff --git a/app/test/shell/shell_bar_test.dart b/app/test/shell/shell_bar_test.dart index 82702b9a..bc69a83a 100644 --- a/app/test/shell/shell_bar_test.dart +++ b/app/test/shell/shell_bar_test.dart @@ -90,7 +90,12 @@ void main() { of: find.byType(FloatingDestinationBar), matching: find.byType(GlassPill), ); - expect(tester.getSize(destinationPill).width, 358); + // Sized to its four tabs at the bottom right. + expect( + tester.getSize(destinationPill).width, + FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4), + ); + expect(tester.getRect(destinationPill).right, 390 - 16); await tester.tap(find.byKey(const ValueKey('shell.destination.chat'))); await tester.pump(); expect(find.text('Chat — Not implemented'), findsOneWidget); diff --git a/app/test/shell/split_destination_bar_test.dart b/app/test/shell/split_destination_bar_test.dart index abebf894..38d0d524 100644 --- a/app/test/shell/split_destination_bar_test.dart +++ b/app/test/shell/split_destination_bar_test.dart @@ -192,12 +192,16 @@ void main() { expect(pill.width, lessThan(1200 * 0.6)); }); - testWidgets('$host 390: the bar spans the phone', (tester) async { + testWidgets('$host 390: the bar hugs its tabs at the phone\'s bottom ' + 'right', (tester) async { await setSize(tester, const Size(390, 844)); await tester.pumpWidget(shell(cupertino: cupertino, split: false)); await tester.pump(); final pill = destinationPill(tester); - expect(pill.left, closeTo(kFloatingBarMargin, 0.5)); + expect( + pill.width, + FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4), + ); expect(pill.right, closeTo(390 - kFloatingBarMargin, 0.5)); }); diff --git a/app/test/ui/adaptive/floating_bar_edge_gap_test.dart b/app/test/ui/adaptive/floating_bar_edge_gap_test.dart new file mode 100644 index 00000000..a8a66cb5 --- /dev/null +++ b/app/test/ui/adaptive/floating_bar_edge_gap_test.dart @@ -0,0 +1,219 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart'; +import 'package:pipelines_app/ui/adaptive/glass_pill.dart'; + +/// The floating tab bar is sized to its tabs at the bottom right on every +/// width, and its selection circle keeps one gap everywhere: the first and +/// last circles sit as far from the pill's sides as from its top and bottom, +/// and neighbouring circles are that far apart too, on both hosts. +void main() { + const icons = [ + Icons.account_tree_outlined, + Icons.play_circle_outline, + Icons.chat_bubble_outline, + Icons.search, + Icons.settings_outlined, + ]; + + Key tabKey(int index) => ValueKey('tab-$index'); + + Widget bar({ + required bool cupertino, + required int count, + required int selected, + ValueChanged? onTap, + }) => FloatingDestinationBar( + cupertino: cupertino, + currentIndex: selected, + onTap: onTap ?? (_) {}, + items: [ + for (var index = 0; index < count; index += 1) + FloatingDestinationItem( + key: tabKey(index), + icon: Icon(icons[index]), + label: 'Tab $index', + ), + ], + ); + + Future pump( + WidgetTester tester, { + required bool cupertino, + required Size size, + required Widget child, + double textScale = 1, + }) async { + tester.view.physicalSize = size; + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + final body = MediaQuery( + data: MediaQueryData( + size: size, + textScaler: TextScaler.linear(textScale), + ), + child: child, + ); + await tester.pumpWidget( + cupertino + ? CupertinoApp(home: CupertinoPageScaffold(child: body)) + : MaterialApp(home: Scaffold(body: body)), + ); + await tester.pumpAndSettle(); + } + + Rect circle(WidgetTester tester, int index) => tester.getRect( + find + .descendant( + of: find.byKey(tabKey(index)), + matching: find.byWidgetPredicate( + (widget) => + widget is DecoratedBox && + widget.decoration is ShapeDecoration && + (widget.decoration as ShapeDecoration).shape is CircleBorder, + ), + ) + .first, + ); + + Rect pill(WidgetTester tester) => tester.getRect( + find.descendant( + of: find.byType(FloatingDestinationBar), + matching: find.byType(GlassPill), + ), + ); + + final placements = [ + (name: 'wide 1200, 4 tabs', size: const Size(1200, 800), count: 4), + (name: 'phone 390, 3 tabs', size: const Size(390, 844), count: 3), + (name: 'phone 390, 4 tabs', size: const Size(390, 844), count: 4), + (name: 'phone 560, 5 tabs', size: const Size(560, 844), count: 5), + (name: 'phone 320, 5 tabs', size: const Size(320, 640), count: 5), + ]; + + for (final cupertino in [false, true]) { + final host = cupertino ? 'Cupertino' : 'Material'; + for (final placement in placements) { + testWidgets('$host ${placement.name}: compact at the bottom right; the ' + 'outer circles keep the top gap from the sides and neighbours', ( + tester, + ) async { + final count = placement.count; + final size = placement.size; + final centres = []; + for (final selected in [0, count - 1]) { + await pump( + tester, + cupertino: cupertino, + size: size, + child: Align( + alignment: Alignment.bottomCenter, + child: bar( + cupertino: cupertino, + count: count, + selected: selected, + ), + ), + ); + final box = pill(tester); + expect(box.right, size.width - 16); + expect(box.bottom, size.height - 16); + final mark = circle(tester, selected); + expect(mark.width, mark.height); + final top = mark.top - box.top; + expect(box.bottom - mark.bottom, moreOrLessEquals(top, epsilon: 1)); + final side = selected == 0 + ? mark.left - box.left + : box.right - mark.right; + expect( + side, + moreOrLessEquals(top, epsilon: 1), + reason: 'side gap $side vs top gap $top', + ); + // The pill's round end is concentric with the outer circle. + expect(box.height / 2, moreOrLessEquals(top + mark.width / 2)); + } + // Unselected icons sit where their circle would: neighbours are + // evenly spaced, one edge gap apart. + for (var index = 0; index < count; index += 1) { + centres.add( + tester + .getCenter( + find.descendant( + of: find.byKey(tabKey(index)), + matching: find.byIcon(icons[index]), + ), + ) + .dx, + ); + } + final last = circle(tester, count - 1); + final gap = last.top - pill(tester).top; + for (var index = 1; index < count; index += 1) { + expect( + centres[index] - centres[index - 1] - last.width, + moreOrLessEquals(gap, epsilon: 1), + ); + } + expect(last.center.dx, moreOrLessEquals(centres.last, epsilon: 1)); + }); + } + + testWidgets('$host phone: taps beside the compact bar reach the content, ' + 'taps on it the tabs', (tester) async { + final tapped = []; + var content = 0; + await pump( + tester, + cupertino: cupertino, + size: const Size(390, 844), + child: Stack( + children: [ + Positioned.fill( + child: GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () => content++, + ), + ), + Align( + alignment: Alignment.bottomCenter, + child: bar( + cupertino: cupertino, + count: 3, + selected: 1, + onTap: tapped.add, + ), + ), + ], + ), + ); + final box = pill(tester); + expect(box.width, lessThan(390 / 2)); + await tester.tapAt(Offset(box.left - 40, box.center.dy)); + await tester.tapAt(box.centerLeft + const Offset(12, 0)); + await tester.tapAt(box.centerRight - const Offset(12, 0)); + await tester.pump(); + expect(content, 1); + expect(tapped, [0, 2]); + }); + + testWidgets('$host: 5 tabs at 320 with 2x text do not overflow', ( + tester, + ) async { + await pump( + tester, + cupertino: cupertino, + size: const Size(320, 640), + textScale: 2, + child: Align( + alignment: Alignment.bottomCenter, + child: bar(cupertino: cupertino, count: 5, selected: 4), + ), + ); + expect(tester.takeException(), isNull); + expect(pill(tester).right, 320 - 16); + expect(pill(tester).left, greaterThanOrEqualTo(16)); + }); + } +}