diff --git a/app/lib/shell/adaptive_shell.dart b/app/lib/shell/adaptive_shell.dart index 41bedfbe..9af52537 100644 --- a/app/lib/shell/adaptive_shell.dart +++ b/app/lib/shell/adaptive_shell.dart @@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../ui/adaptive/segmented_bar.dart'; +import '../ui/adaptive/floating_destination_bar.dart'; import 'attention_badge.dart'; import 'destination.dart'; import 'shell_bar.dart'; @@ -161,20 +162,16 @@ class _AdaptiveShellState extends State { : Column( children: [ Expanded(child: _destinationStack(contents, index)), - // Match CupertinoTabScaffold's native tab-label policy; - // content elsewhere still follows the user's scaler. + // Keep the host's native tab semantics while giving + // the selector the same floating glass treatment as + // the top bar. MediaQuery.withNoTextScaling( - child: CupertinoTabBar( + child: FloatingDestinationBar( + cupertino: true, currentIndex: index, onTap: (value) => _select(AppDestination.values[value]), - items: _items((destination) { - final item = destinationDetails(destination); - return BottomNavigationBarItem( - icon: _icon(destination, item.cupertinoIcon), - label: item.label, - ); - }), + items: _destinationItems(cupertino: true), ), ), ], @@ -211,19 +208,14 @@ class _AdaptiveShellState extends State { ], ), ), + extendBody: true, bottomNavigationBar: wide ? null - : NavigationBar( - selectedIndex: index, - onDestinationSelected: (value) => - _select(AppDestination.values[value]), - destinations: _items((destination) { - final item = destinationDetails(destination); - return NavigationDestination( - icon: _icon(destination, item.icon), - label: item.label, - ); - }), + : FloatingDestinationBar( + cupertino: false, + currentIndex: index, + onTap: (value) => _select(AppDestination.values[value]), + items: _destinationItems(), ), ); }, @@ -231,6 +223,15 @@ class _AdaptiveShellState extends State { ); } + List _destinationItems({bool cupertino = false}) => + AppDestination.values.map((destination) { + final item = destinationDetails(destination); + return FloatingDestinationItem( + icon: _icon(destination, cupertino ? item.cupertinoIcon : item.icon), + label: item.label, + ); + }).toList(); + /// The open screen's own bar: its Back, title and actions, or the tab's /// name with Search. SegmentedBar _segmentedBar(ShellBarSpec? spec, String label) { diff --git a/app/lib/ui/adaptive/floating_destination_bar.dart b/app/lib/ui/adaptive/floating_destination_bar.dart new file mode 100644 index 00000000..00d87dc0 --- /dev/null +++ b/app/lib/ui/adaptive/floating_destination_bar.dart @@ -0,0 +1,91 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import 'glass_pill.dart'; + +/// A compact destination switcher which floats above the bottom edge instead +/// of becoming a full-width system bar. The controls inside remain the +/// platform navigation controls, so their labels, semantics and selection +/// behaviour are not recreated by the glass treatment. +class FloatingDestinationBar extends StatelessWidget { + const FloatingDestinationBar({ + super.key, + required this.cupertino, + required this.currentIndex, + required this.onTap, + required this.items, + }); + + final bool cupertino; + final int currentIndex; + final ValueChanged onTap; + final List items; + + @override + Widget build(BuildContext context) { + final width = MediaQuery.sizeOf(context).width; + final bar = cupertino ? _cupertinoBar() : _materialBar(context); + return SafeArea( + top: false, + minimum: const EdgeInsets.fromLTRB(16, 0, 16, 8), + child: Align( + alignment: Alignment.bottomCenter, + child: ConstrainedBox( + constraints: BoxConstraints(maxWidth: width - 32), + child: GlassPill(cupertino: cupertino, child: bar), + ), + ), + ); + } + + Widget _materialBar(BuildContext context) { + final scheme = Theme.of(context).colorScheme; + return NavigationBarTheme( + data: NavigationBarThemeData( + backgroundColor: Colors.transparent, + elevation: 0, + surfaceTintColor: Colors.transparent, + indicatorColor: scheme.secondaryContainer, + ), + child: NavigationBar( + selectedIndex: currentIndex, + onDestinationSelected: onTap, + destinations: [ + for (final item in items) + NavigationDestination( + icon: item.icon, + selectedIcon: item.selectedIcon ?? item.icon, + label: item.label, + ), + ], + ), + ); + } + + Widget _cupertinoBar() => CupertinoTabBar( + backgroundColor: CupertinoColors.transparent, + currentIndex: currentIndex, + onTap: onTap, + items: [ + for (final item in items) + BottomNavigationBarItem( + icon: item.icon, + activeIcon: item.selectedIcon ?? item.icon, + label: item.label, + ), + ], + ); +} + +/// The platform-neutral data needed by [FloatingDestinationBar]. +class FloatingDestinationItem { + const FloatingDestinationItem({ + required this.icon, + required this.label, + this.selectedIcon, + }); + + final Widget icon; + final String label; + final Widget? selectedIcon; +} diff --git a/app/test/shell/shell_bar_test.dart b/app/test/shell/shell_bar_test.dart index 31479abe..10471189 100644 --- a/app/test/shell/shell_bar_test.dart +++ b/app/test/shell/shell_bar_test.dart @@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/shell/adaptive_shell.dart'; import 'package:pipelines_app/shell/destination.dart'; import 'package:pipelines_app/shell/shell_bar.dart'; +import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart'; Widget _app({required bool cupertino, required bool open, VoidCallback? back}) { final shell = AdaptiveShell( @@ -58,6 +59,7 @@ void main() { expect(AppDestination.values, hasLength(5)); expect(find.text('Search'), findsOneWidget); expect(find.byKey(const ValueKey('shell.search')), findsNothing); + expect(find.byType(FloatingDestinationBar), findsOneWidget); }); }