Tabs: the selected button grows about 20%, neighbours keep their gaps
The selected tab's whole button (62 px Material, 60 px Cupertino, from 52/50) and its icon grow with the selection in the layout, so the other buttons move over and every gap stays the same; the previous selection shrinks back. The row is as tall as the selected button with the others centred on it.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/motion/motion.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||
|
||||
@@ -116,7 +115,12 @@ void main() {
|
||||
);
|
||||
for (var index = 0; index < 3; index += 1) {
|
||||
final circle = button(tester, index);
|
||||
expect(circle.size, Size(diameter, diameter));
|
||||
// Tab 0 is selected: its whole button is larger than the others.
|
||||
final across = index == 0
|
||||
? FloatingDestinationBar.selectedButtonSize(cupertino: cupertino)
|
||||
: diameter;
|
||||
expect(circle.width, moreOrLessEquals(across));
|
||||
expect(circle.height, moreOrLessEquals(across));
|
||||
expect(
|
||||
tester
|
||||
.widget<GlassPill>(
|
||||
@@ -129,9 +133,12 @@ void main() {
|
||||
isA<CircleBorder>(),
|
||||
);
|
||||
final icon = tester.getRect(find.byIcon(icons[index]));
|
||||
// Tab 0 is selected: its icon is a little larger than the others.
|
||||
final side = index == 0
|
||||
? iconSize * Motion.tabSelectedIconScale
|
||||
? iconSize *
|
||||
FloatingDestinationBar.selectedButtonSize(
|
||||
cupertino: cupertino,
|
||||
) /
|
||||
FloatingDestinationBar.buttonSize(cupertino: cupertino)
|
||||
: iconSize;
|
||||
expect(icon.width, moreOrLessEquals(side));
|
||||
expect(icon.height, moreOrLessEquals(side));
|
||||
@@ -156,10 +163,18 @@ void main() {
|
||||
final box = row(tester);
|
||||
expect(box.right, size.width - 16);
|
||||
expect(box.bottom, size.height - 16);
|
||||
expect(box.height, diameter);
|
||||
// As tall as the selected (larger) button.
|
||||
expect(
|
||||
box.height,
|
||||
moreOrLessEquals(
|
||||
FloatingDestinationBar.selectedButtonSize(cupertino: cupertino),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
box.width,
|
||||
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: count),
|
||||
moreOrLessEquals(
|
||||
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: count),
|
||||
),
|
||||
);
|
||||
expect(button(tester, 0).left, box.left);
|
||||
expect(button(tester, count - 1).right, box.right);
|
||||
@@ -168,7 +183,11 @@ void main() {
|
||||
button(tester, index).left - button(tester, index - 1).right,
|
||||
moreOrLessEquals(gap),
|
||||
);
|
||||
expect(button(tester, index).top, box.top);
|
||||
// Every button is centred on the row, whatever its size.
|
||||
expect(
|
||||
button(tester, index).center.dy,
|
||||
moreOrLessEquals(box.center.dy),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -229,9 +248,16 @@ void main() {
|
||||
final box = row(tester);
|
||||
expect(box.right, 320 - 16);
|
||||
expect(box.left, greaterThanOrEqualTo(16));
|
||||
final narrowed = (288 - 5 * diameter) / 4;
|
||||
// Tab 4 is selected and larger; the gaps narrow around it.
|
||||
final selected = FloatingDestinationBar.selectedButtonSize(
|
||||
cupertino: cupertino,
|
||||
);
|
||||
final narrowed = (288 - 4 * diameter - selected) / 4;
|
||||
for (var index = 1; index < 5; index += 1) {
|
||||
expect(button(tester, index).width, diameter);
|
||||
expect(
|
||||
button(tester, index).width,
|
||||
moreOrLessEquals(index == 4 ? selected : diameter),
|
||||
);
|
||||
expect(
|
||||
button(tester, index).left - button(tester, index - 1).right,
|
||||
moreOrLessEquals(narrowed < gap ? narrowed : gap),
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/motion/motion.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';
|
||||
@@ -117,7 +116,10 @@ void main() {
|
||||
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));
|
||||
final rest = index == 0
|
||||
? FloatingDestinationBar.selectedButtonSize(cupertino: cupertino)
|
||||
: size;
|
||||
expect(widthOf(tester, tab), moreOrLessEquals(rest * 0.6));
|
||||
}
|
||||
await tester.pump(const Duration(milliseconds: 130));
|
||||
final first = widthOf(tester, find.byKey(tabKey(0)));
|
||||
@@ -129,7 +131,13 @@ void main() {
|
||||
for (var index = 0; index < 3; index += 1) {
|
||||
final tab = find.byKey(tabKey(index));
|
||||
expect(opacityOf(tester, tab), 1);
|
||||
expect(widthOf(tester, tab), size);
|
||||
// Tab 0 is selected, so it settles at the larger size.
|
||||
expect(
|
||||
widthOf(tester, tab),
|
||||
index == 0
|
||||
? FloatingDestinationBar.selectedButtonSize(cupertino: cupertino)
|
||||
: size,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -145,13 +153,12 @@ 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 press may shrink the tapped button, and only a
|
||||
// little; a replayed pop starts at 0.6.
|
||||
// The selection grows and shrinks buttons between their two
|
||||
// sizes and the press sinks the tapped one a little; a replayed
|
||||
// pop would start at 0.6.
|
||||
expect(
|
||||
widthOf(tester, tab),
|
||||
index == target
|
||||
? greaterThan(size * 0.9)
|
||||
: moreOrLessEquals(size),
|
||||
greaterThan(size * 0.9),
|
||||
reason: 'tab $index popped again',
|
||||
);
|
||||
}
|
||||
@@ -222,7 +229,11 @@ void main() {
|
||||
// At rest the selected icon is a little larger than the others.
|
||||
expect(
|
||||
iconWidth(tester, 2),
|
||||
moreOrLessEquals(iconSize * Motion.tabSelectedIconScale),
|
||||
moreOrLessEquals(
|
||||
iconSize *
|
||||
FloatingDestinationBar.selectedButtonSize(cupertino: cupertino) /
|
||||
FloatingDestinationBar.buttonSize(cupertino: cupertino),
|
||||
),
|
||||
);
|
||||
expect(iconWidth(tester, 0), moreOrLessEquals(iconSize));
|
||||
expect(iconWidth(tester, 1), moreOrLessEquals(iconSize));
|
||||
@@ -251,10 +262,18 @@ void main() {
|
||||
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);
|
||||
// Tab 0 is selected, so it is the larger button; the press leaves it.
|
||||
expect(
|
||||
widthOf(tester, find.byKey(tabKey(0))),
|
||||
FloatingDestinationBar.selectedButtonSize(cupertino: cupertino),
|
||||
);
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(widthOf(tester, tab), size);
|
||||
// The tap selected it: it springs back to the selected size.
|
||||
expect(
|
||||
widthOf(tester, tab),
|
||||
FloatingDestinationBar.selectedButtonSize(cupertino: cupertino),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('$host: under reduced motion the tint jumps and the buttons '
|
||||
@@ -273,7 +292,11 @@ void main() {
|
||||
// No bounce, and the selected icon jumps straight to its larger size.
|
||||
expect(
|
||||
iconWidth(tester, 2),
|
||||
moreOrLessEquals(iconSize * Motion.tabSelectedIconScale),
|
||||
moreOrLessEquals(
|
||||
iconSize *
|
||||
FloatingDestinationBar.selectedButtonSize(cupertino: cupertino) /
|
||||
FloatingDestinationBar.buttonSize(cupertino: cupertino),
|
||||
),
|
||||
);
|
||||
expect(iconWidth(tester, 0), moreOrLessEquals(iconSize));
|
||||
});
|
||||
@@ -313,7 +336,13 @@ void main() {
|
||||
reason: '${tab.name} faded switching to ${next.name}',
|
||||
);
|
||||
if (tab != next) {
|
||||
expect(widthOf(tester, finder), size, reason: tab.name);
|
||||
// The previous selection shrinks back to its size; nothing
|
||||
// pops again from 0.6.
|
||||
expect(
|
||||
widthOf(tester, finder),
|
||||
greaterThan(size * 0.9),
|
||||
reason: tab.name,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ void main() {
|
||||
final pill = tester.getRect(find.byKey(FloatingDestinationBar.rowKey));
|
||||
expect(pill.top, 64);
|
||||
// The pill is the bar's own height: leftover media padding is not added.
|
||||
expect(pill.height, FloatingDestinationBar.materialButtonSize);
|
||||
expect(pill.height, FloatingDestinationBar.materialSelectedButtonSize);
|
||||
// Wide: sized to its tabs at the leading edge, under the title.
|
||||
expect(pill.left, FloatingDestinationBar.topMargin);
|
||||
expect(pill.width, lessThan(400));
|
||||
|
||||
Reference in New Issue
Block a user