Animate and space floating tab bars
This commit is contained in:
@@ -78,17 +78,10 @@ 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) and one
|
||||
// more edge gap, so the outer circles keep it from the sides.
|
||||
// Four icon-only tabs, with the wider neighbour gaps derived by the bar.
|
||||
expect(
|
||||
rect.width,
|
||||
4 *
|
||||
(cupertino
|
||||
? FloatingDestinationBar.cupertinoTabWidth
|
||||
: FloatingDestinationBar.materialTabWidth) +
|
||||
(cupertino
|
||||
? FloatingDestinationBar.cupertinoEdgeGap
|
||||
: FloatingDestinationBar.materialEdgeGap),
|
||||
FloatingDestinationBar.pillWidth(cupertino: cupertino, tabs: 4),
|
||||
);
|
||||
// No rail or sidebar: the content starts at the left edge.
|
||||
expect(find.byType(NavigationRail), findsNothing);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -121,6 +123,85 @@ void main() {
|
||||
expect(mark.height, highlightSize);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'$host: tab entrance animates once and respects reduced motion',
|
||||
(tester) async {
|
||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||
const FakeAccessibilityFeatures(disableAnimations: false);
|
||||
addTearDown(() {
|
||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||
const FakeAccessibilityFeatures(disableAnimations: true);
|
||||
});
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
var selected = 0;
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
child: MediaQuery(
|
||||
data: const MediaQueryData(disableAnimations: false),
|
||||
child: StatefulBuilder(
|
||||
builder: (context, setState) => bar(
|
||||
cupertino: cupertino,
|
||||
count: 3,
|
||||
selected: selected,
|
||||
onTap: (index) => setState(() => selected = index),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: MaterialApp(
|
||||
home: Scaffold(
|
||||
body: MediaQuery(
|
||||
data: const MediaQueryData(disableAnimations: false),
|
||||
child: StatefulBuilder(
|
||||
builder: (context, setState) => bar(
|
||||
cupertino: cupertino,
|
||||
count: 3,
|
||||
selected: selected,
|
||||
onTap: (index) => setState(() => selected = index),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final entrance = find.descendant(
|
||||
of: find.byType(FloatingDestinationBar),
|
||||
matching: find.byType(FadeTransition),
|
||||
);
|
||||
expect(
|
||||
tester.widget<FadeTransition>(entrance.first).opacity.value,
|
||||
inInclusiveRange(0, 1),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 320));
|
||||
expect(tester.widget<FadeTransition>(entrance.first).opacity.value, 1);
|
||||
await tester.tap(find.byKey(tabKey(1)));
|
||||
await tester.pump();
|
||||
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(disableAnimations: true),
|
||||
child: cupertino
|
||||
? CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
child: bar(cupertino: cupertino, count: 3, selected: 0),
|
||||
),
|
||||
)
|
||||
: MaterialApp(
|
||||
home: Scaffold(
|
||||
body: bar(cupertino: cupertino, count: 3, selected: 0),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(tester.widget<FadeTransition>(entrance.first).opacity.value, 1);
|
||||
},
|
||||
);
|
||||
|
||||
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', (
|
||||
@@ -162,7 +243,7 @@ void main() {
|
||||
expect(box.height / 2, moreOrLessEquals(top + mark.width / 2));
|
||||
}
|
||||
// Unselected icons sit where their circle would: neighbours are
|
||||
// evenly spaced, one edge gap apart.
|
||||
// evenly spaced, with the larger named neighbour gap.
|
||||
for (var index = 0; index < count; index += 1) {
|
||||
centres.add(
|
||||
tester
|
||||
@@ -176,13 +257,37 @@ void main() {
|
||||
);
|
||||
}
|
||||
final last = circle(tester, count - 1);
|
||||
final gap = last.top - pill(tester).top;
|
||||
final box = pill(tester);
|
||||
final edgeGap = last.top - box.top;
|
||||
final requestedNeighbourGap = cupertino
|
||||
? FloatingDestinationBar.cupertinoNeighbourGap
|
||||
: FloatingDestinationBar.materialNeighbourGap;
|
||||
final neighbourGap = math.min(
|
||||
requestedNeighbourGap,
|
||||
(box.width -
|
||||
2 *
|
||||
(cupertino
|
||||
? FloatingDestinationBar.cupertinoEdgeGap
|
||||
: FloatingDestinationBar.materialEdgeGap) -
|
||||
count * last.width) /
|
||||
(count - 1),
|
||||
);
|
||||
for (var index = 1; index < count; index += 1) {
|
||||
expect(
|
||||
centres[index] - centres[index - 1] - last.width,
|
||||
moreOrLessEquals(gap, epsilon: 1),
|
||||
moreOrLessEquals(neighbourGap, epsilon: 1),
|
||||
);
|
||||
}
|
||||
expect(
|
||||
neighbourGap - edgeGap,
|
||||
moreOrLessEquals(
|
||||
neighbourGap -
|
||||
(cupertino
|
||||
? FloatingDestinationBar.cupertinoEdgeGap
|
||||
: FloatingDestinationBar.materialEdgeGap),
|
||||
epsilon: 1,
|
||||
),
|
||||
);
|
||||
expect(last.center.dx, moreOrLessEquals(centres.last, epsilon: 1));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user