Show each floating tab as its own round glass button
Replace the single glass pill (host NavigationBar/CupertinoTabBar with one gliding highlight) with a row of separate circular GlassPill buttons, 52/50 px with 12/10 px gaps, at the same bottom-right place. The selected button fills with the host selection tint and cross-fades; each button pops in on its own, staggered, only when the bar appears or its tabs change; presses sink like the top bar's. Tab semantics, keys, tooltips and badges are kept; the row shares one BackdropGroup for its blurs.
This commit is contained in:
@@ -4,10 +4,13 @@ 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/ui/adaptive/floating_destination_bar.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/floating_tab_button.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||
|
||||
/// The floating tab bar's motion: the tabs pop in only when the bar appears
|
||||
/// or its set of tabs changes, and one selection highlight glides (and
|
||||
/// stretches on the way) to a newly selected tab, whose icon bounces.
|
||||
/// The floating tab bar's motion: each button pops in on its own, staggered,
|
||||
/// only when the bar appears or its set of tabs changes; the selection tint
|
||||
/// cross-fades to a newly selected button, whose icon bounces; a press sinks
|
||||
/// the button and it springs back.
|
||||
void main() {
|
||||
const icons = [
|
||||
Icons.account_tree_outlined,
|
||||
@@ -30,15 +33,16 @@ void main() {
|
||||
void animate(WidgetTester tester, {required bool on}) {
|
||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||
FakeAccessibilityFeatures(disableAnimations: !on);
|
||||
addTearDown(() {
|
||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||
const FakeAccessibilityFeatures(disableAnimations: true);
|
||||
});
|
||||
addTearDown(tester.platformDispatcher.clearAccessibilityFeaturesTestValue);
|
||||
tester.view.physicalSize = const Size(560, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
}
|
||||
|
||||
Widget app(bool cupertino, Widget body) => cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: body))
|
||||
: MaterialApp(home: Scaffold(body: body));
|
||||
|
||||
/// A bar of [count] tabs whose tap selects.
|
||||
Future<void> pumpBar(
|
||||
WidgetTester tester, {
|
||||
@@ -46,74 +50,92 @@ void main() {
|
||||
int count = 3,
|
||||
}) async {
|
||||
var selected = 0;
|
||||
final body = StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
return Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: FloatingDestinationBar(
|
||||
cupertino: cupertino,
|
||||
currentIndex: selected,
|
||||
onTap: (index) => setState(() => selected = index),
|
||||
items: items(count),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: body))
|
||||
: MaterialApp(home: Scaffold(body: body)),
|
||||
app(
|
||||
cupertino,
|
||||
StatefulBuilder(
|
||||
builder: (context, setState) => Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: FloatingDestinationBar(
|
||||
cupertino: cupertino,
|
||||
currentIndex: selected,
|
||||
onTap: (index) => setState(() => selected = index),
|
||||
items: items(count),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// The opacity of [tab]'s entrance fade.
|
||||
double opacityOf(WidgetTester tester, Finder tab) => tester
|
||||
.widget<FadeTransition>(
|
||||
find
|
||||
.descendant(
|
||||
of: tab,
|
||||
matching: find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is FadeTransition && widget.child is AnimatedBuilder,
|
||||
),
|
||||
)
|
||||
.last,
|
||||
)
|
||||
.opacity
|
||||
.value;
|
||||
Finder glass(Finder tab) =>
|
||||
find.descendant(of: tab, matching: find.byType(GlassPill));
|
||||
|
||||
double iconWidth(WidgetTester tester, Finder tab, IconData icon) => tester
|
||||
.getRect(find.descendant(of: tab, matching: find.byIcon(icon)))
|
||||
/// The opacity of [tab]'s entrance fade (its glass reveal).
|
||||
double opacityOf(WidgetTester tester, Finder tab) =>
|
||||
GlassReveal.maybeOf(tester.element(glass(tab)))?.value ?? 1;
|
||||
|
||||
/// [tab]'s drawn width (its entrance and press scale it).
|
||||
double widthOf(WidgetTester tester, Finder tab) =>
|
||||
tester.getRect(glass(tab)).width;
|
||||
|
||||
double iconWidth(WidgetTester tester, int index) => tester
|
||||
.getRect(
|
||||
find.descendant(
|
||||
of: find.byKey(tabKey(index)),
|
||||
matching: find.byIcon(icons[index]),
|
||||
),
|
||||
)
|
||||
.width;
|
||||
|
||||
Rect highlight(WidgetTester tester) => tester.getRect(
|
||||
find.descendant(
|
||||
of: find.byKey(FloatingDestinationBar.highlightKey),
|
||||
matching: find.byType(DecoratedBox),
|
||||
),
|
||||
);
|
||||
|
||||
Offset iconCentre(WidgetTester tester, int index) => tester.getCenter(
|
||||
find.descendant(
|
||||
of: find.byKey(tabKey(index)),
|
||||
matching: find.byIcon(icons[index]),
|
||||
),
|
||||
);
|
||||
/// The alpha of tab [index]'s selection fill.
|
||||
double fillAlpha(WidgetTester tester, int index) {
|
||||
final fill = tester.widget(
|
||||
find.descendant(
|
||||
of: find.byKey(tabKey(index)),
|
||||
matching: find.byKey(FloatingTabButton.fillKey),
|
||||
),
|
||||
);
|
||||
final decoration = fill is Ink
|
||||
? fill.decoration
|
||||
: (fill as DecoratedBox).decoration;
|
||||
return (decoration! as ShapeDecoration).color!.a;
|
||||
}
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
final size = FloatingDestinationBar.buttonSize(cupertino: cupertino);
|
||||
final iconSize = cupertino
|
||||
? FloatingDestinationBar.cupertinoIconSize
|
||||
: FloatingDestinationBar.materialIconSize;
|
||||
final size = cupertino
|
||||
? FloatingDestinationBar.cupertinoHighlightSize
|
||||
: FloatingDestinationBar.materialHighlightSize;
|
||||
|
||||
testWidgets('$host: the entrance does not replay when the selection '
|
||||
'changes, and plays again for a new set of tabs', (tester) async {
|
||||
testWidgets('$host: each button pops in on its own, staggered, from '
|
||||
'0.6 to full size', (tester) async {
|
||||
animate(tester, on: true);
|
||||
await pumpBar(tester, cupertino: cupertino);
|
||||
for (var index = 0; index < 3; index += 1) {
|
||||
final tab = find.byKey(tabKey(index));
|
||||
expect(opacityOf(tester, tab), 0);
|
||||
expect(widthOf(tester, tab), moreOrLessEquals(size * 0.6));
|
||||
}
|
||||
await tester.pump(const Duration(milliseconds: 130));
|
||||
final first = widthOf(tester, find.byKey(tabKey(0)));
|
||||
final last = widthOf(tester, find.byKey(tabKey(2)));
|
||||
expect(first, greaterThan(last + 4), reason: 'staggered');
|
||||
expect(opacityOf(tester, find.byKey(tabKey(0))), greaterThan(0.9));
|
||||
expect(opacityOf(tester, find.byKey(tabKey(2))), lessThan(0.2));
|
||||
await tester.pumpAndSettle();
|
||||
for (var index = 0; index < 3; index += 1) {
|
||||
final tab = find.byKey(tabKey(index));
|
||||
expect(opacityOf(tester, tab), 1);
|
||||
expect(widthOf(tester, tab), size);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('$host: the entrance does not replay when the selection '
|
||||
'changes', (tester) async {
|
||||
animate(tester, on: true);
|
||||
await pumpBar(tester, cupertino: cupertino);
|
||||
expect(opacityOf(tester, find.byKey(tabKey(0))), 0);
|
||||
await tester.pumpAndSettle();
|
||||
for (final target in [1, 2, 0]) {
|
||||
await tester.tap(find.byKey(tabKey(target)));
|
||||
@@ -122,14 +144,18 @@ void main() {
|
||||
for (var index = 0; index < 3; index += 1) {
|
||||
final tab = find.byKey(tabKey(index));
|
||||
expect(opacityOf(tester, tab), 1, reason: 'tab $index faded');
|
||||
// Only the bounce may grow an icon; a replayed pop shrinks it.
|
||||
// Only the press may shrink the tapped button, and only a
|
||||
// little; a replayed pop starts at 0.6.
|
||||
expect(
|
||||
iconWidth(tester, tab, icons[index]),
|
||||
greaterThanOrEqualTo(iconSize - 0.01),
|
||||
widthOf(tester, tab),
|
||||
index == target
|
||||
? greaterThan(size * 0.9)
|
||||
: moreOrLessEquals(size),
|
||||
reason: 'tab $index popped again',
|
||||
);
|
||||
}
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -137,24 +163,24 @@ void main() {
|
||||
animate(tester, on: true);
|
||||
var count = 3;
|
||||
late StateSetter update;
|
||||
Widget build() => StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
update = setState;
|
||||
return Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: FloatingDestinationBar(
|
||||
cupertino: cupertino,
|
||||
currentIndex: 0,
|
||||
onTap: (_) {},
|
||||
items: items(count),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: build()))
|
||||
: MaterialApp(home: Scaffold(body: build())),
|
||||
app(
|
||||
cupertino,
|
||||
StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
update = setState;
|
||||
return Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: FloatingDestinationBar(
|
||||
cupertino: cupertino,
|
||||
currentIndex: 0,
|
||||
onTap: (_) {},
|
||||
items: items(count),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(opacityOf(tester, find.byKey(tabKey(2))), 1);
|
||||
@@ -164,84 +190,80 @@ void main() {
|
||||
expect(opacityOf(tester, find.byKey(tabKey(2))), 0);
|
||||
await tester.pumpAndSettle();
|
||||
expect(opacityOf(tester, find.byKey(tabKey(3))), 1);
|
||||
expect(widthOf(tester, find.byKey(tabKey(3))), size);
|
||||
});
|
||||
|
||||
testWidgets('$host: the highlight rests on the selected tab as the old '
|
||||
'circle did, glides and stretches between tabs, and the new icon '
|
||||
'bounces', (tester) async {
|
||||
testWidgets('$host: the selection tint cross-fades to the new button, '
|
||||
'whose icon takes the selected colour and bounces', (tester) async {
|
||||
animate(tester, on: true);
|
||||
await pumpBar(tester, cupertino: cupertino);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
highlight(tester),
|
||||
rectMoreOrLessEquals(
|
||||
Rect.fromCenter(
|
||||
center: iconCentre(tester, 0),
|
||||
width: size,
|
||||
height: size,
|
||||
),
|
||||
epsilon: 0.01,
|
||||
),
|
||||
);
|
||||
expect(find.byKey(FloatingDestinationBar.highlightKey), findsOneWidget);
|
||||
final tint = fillAlpha(tester, 0);
|
||||
expect(tint, greaterThan(0.1));
|
||||
expect(fillAlpha(tester, 1), 0);
|
||||
expect(fillAlpha(tester, 2), 0);
|
||||
|
||||
await tester.tap(find.byKey(tabKey(2)));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 60));
|
||||
final from = iconCentre(tester, 0).dx;
|
||||
final to = iconCentre(tester, 2).dx;
|
||||
final moving = highlight(tester);
|
||||
expect(moving.center.dx, greaterThan(from + 1));
|
||||
expect(moving.center.dx, lessThan(to - 1));
|
||||
expect(moving.height, moreOrLessEquals(size));
|
||||
expect(moving.width, greaterThan(size * 1.1));
|
||||
expect(moving.width, lessThanOrEqualTo(size * 1.25 + 0.01));
|
||||
await tester.pump(const Duration(milliseconds: 80));
|
||||
expect(fillAlpha(tester, 2), inExclusiveRange(0, tint));
|
||||
expect(fillAlpha(tester, 0), inExclusiveRange(0, tint));
|
||||
// The icon grows within its button (which the tap's press sinks).
|
||||
expect(
|
||||
iconWidth(tester, find.byKey(tabKey(2)), icons[2]),
|
||||
greaterThan(iconSize * 1.02),
|
||||
iconWidth(tester, 2) * size / widthOf(tester, find.byKey(tabKey(2))),
|
||||
greaterThan(iconSize * 1.04),
|
||||
);
|
||||
expect(iconWidth(tester, 1), moreOrLessEquals(iconSize));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
expect(fillAlpha(tester, 2), tint);
|
||||
expect(fillAlpha(tester, 0), 0);
|
||||
expect(iconWidth(tester, 2), moreOrLessEquals(iconSize));
|
||||
final context = tester.element(find.byKey(tabKey(2)));
|
||||
final selectedColour = cupertino
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.onSecondaryContainer;
|
||||
expect(
|
||||
highlight(tester),
|
||||
rectMoreOrLessEquals(
|
||||
Rect.fromCenter(
|
||||
center: iconCentre(tester, 2),
|
||||
width: size,
|
||||
height: size,
|
||||
),
|
||||
epsilon: 0.01,
|
||||
),
|
||||
IconTheme.of(tester.element(find.byIcon(icons[2]))).color,
|
||||
isSameColorAs(selectedColour),
|
||||
);
|
||||
expect(
|
||||
iconWidth(tester, find.byKey(tabKey(2)), icons[2]),
|
||||
moreOrLessEquals(iconSize),
|
||||
IconTheme.of(tester.element(find.byIcon(icons[0]))).color,
|
||||
isNot(isSameColorAs(selectedColour)),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('$host: under reduced motion the highlight jumps and the '
|
||||
'icons neither pop nor bounce', (tester) async {
|
||||
testWidgets('$host: a press sinks the button and it springs back', (
|
||||
tester,
|
||||
) async {
|
||||
animate(tester, on: true);
|
||||
await pumpBar(tester, cupertino: cupertino);
|
||||
await tester.pumpAndSettle();
|
||||
final tab = find.byKey(tabKey(1));
|
||||
final gesture = await tester.startGesture(tester.getCenter(tab));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 120));
|
||||
expect(widthOf(tester, tab), lessThan(size * 0.97));
|
||||
expect(widthOf(tester, find.byKey(tabKey(0))), size);
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(widthOf(tester, tab), size);
|
||||
});
|
||||
|
||||
testWidgets('$host: under reduced motion the tint jumps and the buttons '
|
||||
'neither pop nor bounce', (tester) async {
|
||||
animate(tester, on: false);
|
||||
await pumpBar(tester, cupertino: cupertino);
|
||||
await tester.pump();
|
||||
expect(opacityOf(tester, find.byKey(tabKey(1))), 1);
|
||||
expect(widthOf(tester, find.byKey(tabKey(1))), size);
|
||||
final tint = fillAlpha(tester, 0);
|
||||
await tester.tap(find.byKey(tabKey(2)));
|
||||
await tester.pump();
|
||||
expect(
|
||||
highlight(tester),
|
||||
rectMoreOrLessEquals(
|
||||
Rect.fromCenter(
|
||||
center: iconCentre(tester, 2),
|
||||
width: size,
|
||||
height: size,
|
||||
),
|
||||
epsilon: 0.01,
|
||||
),
|
||||
);
|
||||
expect(
|
||||
iconWidth(tester, find.byKey(tabKey(2)), icons[2]),
|
||||
moreOrLessEquals(iconSize),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(fillAlpha(tester, 2), tint);
|
||||
expect(fillAlpha(tester, 0), 0);
|
||||
expect(iconWidth(tester, 2), moreOrLessEquals(iconSize));
|
||||
});
|
||||
|
||||
testWidgets('$host: switching the shell tabs never replays the main '
|
||||
@@ -270,14 +292,17 @@ void main() {
|
||||
for (var frame = 0; frame < 12; frame += 1) {
|
||||
await tester.pump(const Duration(milliseconds: 25));
|
||||
for (final tab in shellTabDestinations) {
|
||||
final finder = find.byKey(
|
||||
ValueKey('shell.destination.${tab.name}'),
|
||||
);
|
||||
expect(
|
||||
opacityOf(
|
||||
tester,
|
||||
find.byKey(ValueKey('shell.destination.${tab.name}')),
|
||||
),
|
||||
opacityOf(tester, finder),
|
||||
1,
|
||||
reason: '${tab.name} faded switching to ${next.name}',
|
||||
);
|
||||
if (tab != next) {
|
||||
expect(widthOf(tester, finder), size, reason: tab.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
Reference in New Issue
Block a user