Keep chat controls readable and expose labeled app navigation
This commit is contained in:
@@ -7,6 +7,7 @@ import '../motion/motion.dart';
|
||||
import 'floating_bar_layout.dart';
|
||||
import 'floating_tab_button.dart';
|
||||
import 'floating_tab_motion.dart';
|
||||
import 'floating_destination_labels.dart';
|
||||
|
||||
/// A tab bar which floats above the bottom edge as a row of separate round
|
||||
/// frosted [GlassPill] buttons, one per tab, instead of a full-width system
|
||||
@@ -37,10 +38,14 @@ class FloatingDestinationBar extends StatefulWidget {
|
||||
required this.items,
|
||||
this.edge = FloatingBarEdge.bottom,
|
||||
this.alignment,
|
||||
this.showLabels = false,
|
||||
});
|
||||
|
||||
final bool cupertino;
|
||||
|
||||
/// Main app navigation keeps names visible; dense page tabs can stay icons.
|
||||
final bool showLabels;
|
||||
|
||||
/// Where the row sits in the width it is given, at [FloatingBarEdge.bottom]:
|
||||
/// the trailing end by default. The shell centres its tabs under the list
|
||||
/// pane while a list shows beside an open item.
|
||||
@@ -194,6 +199,17 @@ class _FloatingDestinationBarState extends State<FloatingDestinationBar>
|
||||
}
|
||||
|
||||
Widget _row(BuildContext context, double width) {
|
||||
if (widget.showLabels) {
|
||||
return FloatingDestinationLabels(
|
||||
key: FloatingDestinationBar.rowKey,
|
||||
cupertino: cupertino,
|
||||
labels: [for (final item in items) item.label],
|
||||
selected: currentIndex,
|
||||
buttonBuilder: (index) => _button(context, index),
|
||||
onTap: widget.onTap,
|
||||
backdrop: _backdrop,
|
||||
);
|
||||
}
|
||||
final gap = _gap(width);
|
||||
// As tall as the selected (largest) button; the others are centred on
|
||||
// it, and every gap stays the same while a button grows or shrinks.
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import 'dart:ui' show SemanticsRole;
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Content-driven main navigation captions keep names visible without scaling
|
||||
/// down touch targets. Narrow lists and large text wrap into another row.
|
||||
class FloatingDestinationLabels extends StatelessWidget {
|
||||
const FloatingDestinationLabels({
|
||||
super.key,
|
||||
required this.cupertino,
|
||||
required this.labels,
|
||||
required this.selected,
|
||||
required this.buttonBuilder,
|
||||
required this.onTap,
|
||||
required this.backdrop,
|
||||
});
|
||||
final bool cupertino;
|
||||
final List<String> labels;
|
||||
final int selected;
|
||||
final Widget Function(int) buttonBuilder;
|
||||
final ValueChanged<int> onTap;
|
||||
final BackdropKey backdrop;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color = cupertino
|
||||
? CupertinoColors.label.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurface;
|
||||
final surface = cupertino
|
||||
? CupertinoColors.secondarySystemBackground.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainer;
|
||||
final style = cupertino
|
||||
? CupertinoTheme.of(context).textTheme.tabLabelTextStyle
|
||||
: Theme.of(context).textTheme.labelSmall!;
|
||||
return Semantics(
|
||||
role: SemanticsRole.tabBar,
|
||||
container: true,
|
||||
explicitChildNodes: true,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: BackdropGroup(
|
||||
backdropKey: backdrop,
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
for (var index = 0; index < labels.length; index++)
|
||||
GestureDetector(
|
||||
key: ValueKey('destination-label-${labels[index]}'),
|
||||
excludeFromSemantics: true,
|
||||
onTap: () => onTap(index),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
buttonBuilder(index),
|
||||
ExcludeSemantics(
|
||||
child: Text(
|
||||
labels[index],
|
||||
style: style.copyWith(
|
||||
color: color,
|
||||
fontWeight: index == selected
|
||||
? FontWeight.w600
|
||||
: style.fontWeight,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -12,14 +12,24 @@ class SegmentedBarOverlay extends StatelessWidget {
|
||||
super.key,
|
||||
required this.bar,
|
||||
required this.child,
|
||||
this.reserveSpace = false,
|
||||
});
|
||||
|
||||
final Widget bar;
|
||||
final Widget child;
|
||||
|
||||
/// Gives reading content its own viewport below the measured bar.
|
||||
final bool reserveSpace;
|
||||
|
||||
static double reservedHeightOf(BuildContext context) =>
|
||||
context
|
||||
.dependOnInheritedWidgetOfExactType<_ReservedBarHeight>()
|
||||
?.height ??
|
||||
0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => CustomMultiChildLayout(
|
||||
delegate: _OverlayLayout(),
|
||||
delegate: _OverlayLayout(reserveSpace),
|
||||
children: [
|
||||
// Painted first, so the bar draws (and takes taps) above it.
|
||||
LayoutId(
|
||||
@@ -32,9 +42,14 @@ class SegmentedBarOverlay extends StatelessWidget {
|
||||
final media = MediaQuery.of(context);
|
||||
return MediaQuery(
|
||||
data: media.copyWith(
|
||||
padding: media.padding.copyWith(top: barHeight),
|
||||
padding: media.padding.copyWith(
|
||||
top: reserveSpace ? 0 : barHeight,
|
||||
),
|
||||
),
|
||||
child: _ReservedBarHeight(
|
||||
height: reserveSpace ? barHeight : 0,
|
||||
child: child,
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -70,6 +85,8 @@ class _ContentConstraints extends BoxConstraints {
|
||||
}
|
||||
|
||||
class _OverlayLayout extends MultiChildLayoutDelegate {
|
||||
_OverlayLayout(this.reserveSpace);
|
||||
final bool reserveSpace;
|
||||
@override
|
||||
void performLayout(Size size) {
|
||||
final bar = layoutChild(
|
||||
@@ -82,11 +99,26 @@ class _OverlayLayout extends MultiChildLayoutDelegate {
|
||||
positionChild(_Slot.bar, Offset.zero);
|
||||
layoutChild(
|
||||
_Slot.content,
|
||||
_ContentConstraints(size, barHeight: bar.height),
|
||||
_ContentConstraints(
|
||||
Size(
|
||||
size.width,
|
||||
(size.height - (reserveSpace ? bar.height : 0)).clamp(0, size.height),
|
||||
),
|
||||
barHeight: bar.height,
|
||||
),
|
||||
);
|
||||
positionChild(_Slot.content, Offset.zero);
|
||||
positionChild(_Slot.content, Offset(0, reserveSpace ? bar.height : 0));
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRelayout(_OverlayLayout oldDelegate) => false;
|
||||
bool shouldRelayout(_OverlayLayout oldDelegate) =>
|
||||
reserveSpace != oldDelegate.reserveSpace;
|
||||
}
|
||||
|
||||
class _ReservedBarHeight extends InheritedWidget {
|
||||
const _ReservedBarHeight({required this.height, required super.child});
|
||||
final double height;
|
||||
@override
|
||||
bool updateShouldNotify(_ReservedBarHeight oldWidget) =>
|
||||
height != oldWidget.height;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user