Keep pager controls clear of floating bars

This commit is contained in:
2026-11-01 02:05:06 +00:00
parent f422d26e32
commit 821d1a8836
4 changed files with 134 additions and 45 deletions
@@ -101,45 +101,48 @@ class ArtifactViewerBody extends StatelessWidget {
// no empty glass bar, and no bottom clearance reserved for one.
if (resolved == null && count <= 1) return swipe;
return FloatingBarOverlay(
bar: SafeArea(
top: false,
minimum: const EdgeInsets.all(8),
child: SizedBox(
height: 56,
child: GlassPill(
cupertino: usesCupertinoHost(context),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
child: Row(
key: const Key('artifact-viewer-actions'),
children: [
if (resolved != null && !resolved.external)
ArtifactFileActions(
key: ValueKey<String>(
'viewer-files-${page.group.stageKey}\u0000'
'${page.group.visit}\u0000${page.artifact.url}',
bar: Padding(
padding: withFloatingBarClearance(context, EdgeInsets.zero),
child: SafeArea(
top: false,
minimum: const EdgeInsets.all(8),
child: SizedBox(
height: 56,
child: GlassPill(
cupertino: usesCupertinoHost(context),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
child: Row(
key: const Key('artifact-viewer-actions'),
children: [
if (resolved != null && !resolved.external)
ArtifactFileActions(
key: ValueKey<String>(
'viewer-files-${page.group.stageKey}\u0000'
'${page.group.visit}\u0000${page.artifact.url}',
),
artifact: page.artifact,
resolved: resolved,
fetch: fetch,
bridge: fileBridge,
compact: true,
),
if (resolved != null)
_Actions(
resolved: resolved,
onOpen: onOpen,
onCopy: onCopy,
),
Expanded(
child: _Pager(
index: index,
count: count,
onPrevious: onPrevious,
onNext: onNext,
),
artifact: page.artifact,
resolved: resolved,
fetch: fetch,
bridge: fileBridge,
compact: true,
),
if (resolved != null)
_Actions(
resolved: resolved,
onOpen: onOpen,
onCopy: onCopy,
),
Expanded(
child: _Pager(
index: index,
count: count,
onPrevious: onPrevious,
onNext: onNext,
),
),
],
],
),
),
),
),
@@ -231,12 +231,24 @@ class _ChangesViewerState extends State<ChangesViewer> {
alignment: AlignmentDirectional.centerEnd,
heightFactor: 1,
widthFactor: 1,
child: Padding(
padding: const EdgeInsets.all(8),
child: IntrinsicWidth(
child: GlassPill(
cupertino: usesCupertinoHost(context),
child: pager,
child: MediaQuery.removePadding(
context: context,
removeBottom: true,
child: Padding(
// The inherited bottom inset belongs to the shell bar. Include it
// in this overlay's measured bar height so the pager is stacked
// above it rather than translating into a constrained layout.
padding: EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom,
),
child: Padding(
padding: const EdgeInsets.all(8),
child: IntrinsicWidth(
child: GlassPill(
cupertino: usesCupertinoHost(context),
child: pager,
),
),
),
),
),
@@ -45,6 +45,7 @@ Future<void> _pumpViewer(
ArtifactFetch? fetch,
Widget Function(BuildContext, String)? markdownBuilder,
ArtifactExternalOpen? openExternal,
double bottomClearance = 0,
}) async {
final page = ArtifactViewerPage(
groups: groups,
@@ -55,10 +56,14 @@ Future<void> _pumpViewer(
markdownBuilder ?? (context, value) => SelectableText(value),
openExternal: openExternal ?? (_) async => true,
);
final child = MediaQuery(
data: MediaQueryData(padding: EdgeInsets.only(bottom: bottomClearance)),
child: page,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: page)
: MaterialApp(home: Scaffold(body: page)),
? CupertinoApp(home: child)
: MaterialApp(home: Scaffold(body: child)),
);
await tester.pumpAndSettle();
}
@@ -686,6 +691,46 @@ void main() {
}
});
for (final cupertino in [false, true]) {
for (final size in [
const Size(390, 844),
const Size(880, 1000),
const Size(1100, 800),
]) {
testWidgets(
'${cupertino ? 'Cupertino' : 'Material'} pager clears stacked bar at $size',
(tester) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final first = recordedArtifact(
'a.png',
url: '/artifacts/1/1/a.png',
contentType: 'image/png',
);
final second = recordedArtifact(
'b.png',
url: '/artifacts/1/2/b.png',
contentType: 'image/png',
);
final groups = [
_group([first], visit: 1),
_group([second], visit: 2),
];
await _pumpViewer(
tester,
groups: groups,
selected: artifactVisitIdentity(groups[0], first),
cupertino: cupertino,
bottomClearance: 120,
);
final pager = tester.getRect(find.byKey(artifactNextKey));
expect(pager.bottom, lessThanOrEqualTo(size.height - 120));
},
);
}
}
testWidgets('Escape closes the viewer back to the gallery', (tester) async {
await tester.pumpWidget(
MaterialApp(
@@ -85,6 +85,35 @@ void main() {
expect(next.bottom, greaterThan(844 - 80));
});
for (final host in ['Material', 'Cupertino']) {
for (final size in [
const Size(390, 844),
const Size(880, 1000),
const Size(1100, 800),
]) {
testWidgets('$host pager clears an inherited stacked bar at $size', (
tester,
) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final child = ChangesViewer(steps: twoVisitRun());
final hosted = host == 'Material'
? materialHost(child)
: cupertinoHost(child);
await tester.pumpWidget(
MediaQuery(
data: const MediaQueryData(padding: EdgeInsets.only(bottom: 120)),
child: hosted,
),
);
await tester.pump();
final pager = tester.getRect(find.byKey(ChangesVisitPager.nextKey));
expect(pager.bottom, lessThanOrEqualTo(size.height - 120));
});
}
}
testWidgets('paging stops at both ends instead of wrapping', (tester) async {
await tester.pumpWidget(materialHost(ChangesViewer(steps: twoVisitRun())));