From ec3f633d2bde96b67b7a0f36d48a4ab4311c7a28 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 23 Oct 2026 23:00:56 +0100 Subject: [PATCH] feat(app): the artifact viewer page stays still; previews fill and zoom or scroll inside their frame; facts behind a Details button --- .../artifacts/ui/artifact_html_view.dart | 10 +- .../artifacts/ui/artifact_viewer_body.dart | 114 ++++++++++++++---- .../artifacts/ui/artifact_viewer_content.dart | 91 +++++++++++--- .../ui/artifact_gallery_documents_test.dart | 2 + .../ui/artifact_viewer_page_test.dart | 25 +++- 5 files changed, 198 insertions(+), 44 deletions(-) diff --git a/app/lib/features/artifacts/ui/artifact_html_view.dart b/app/lib/features/artifacts/ui/artifact_html_view.dart index eb0dd065..4b2831b2 100644 --- a/app/lib/features/artifacts/ui/artifact_html_view.dart +++ b/app/lib/features/artifacts/ui/artifact_html_view.dart @@ -13,8 +13,8 @@ typedef ArtifactHtmlBuilder = /// empty `sandbox` blocks scripts, forms, popups and navigation; on Android and /// iOS in a web view with JavaScript disabled and navigation refused. The /// document never runs code with the app's origin or credentials. -Widget defaultArtifactHtml(BuildContext context, String html) => SizedBox( - key: const Key('artifact-html-preview'), - height: MediaQuery.sizeOf(context).height * 0.7, - child: impl.InertHtmlView(html: html), -); +Widget defaultArtifactHtml(BuildContext context, String html) => + SizedBox.expand( + key: const Key('artifact-html-preview'), + child: impl.InertHtmlView(html: html), + ); diff --git a/app/lib/features/artifacts/ui/artifact_viewer_body.dart b/app/lib/features/artifacts/ui/artifact_viewer_body.dart index 3772f4cb..3a653639 100644 --- a/app/lib/features/artifacts/ui/artifact_viewer_body.dart +++ b/app/lib/features/artifacts/ui/artifact_viewer_body.dart @@ -62,30 +62,26 @@ class ArtifactViewerBody extends StatelessWidget { @override Widget build(BuildContext context) { final resolved = plan.resolved; - final content = SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Padding( - padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 4), - child: ArtifactSelectionFacts( - group: page.group, - artifact: page.artifact, - step: null, - resolved: plan.resolved, - ), + // The page never scrolls: a thin strip on top, the preview filling the + // middle (it zooms or scrolls itself), the controls along the bottom. + final content = Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + _InfoStrip( + label: artifactViewerPositionLabel( + index, + count, + page.artifact.contentType, ), - Padding( - padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 16, 4), - child: Text( - artifactViewerPositionLabel( - index, - count, - page.artifact.contentType, - ), - ), + facts: ArtifactSelectionFacts( + group: page.group, + artifact: page.artifact, + step: null, + resolved: plan.resolved, ), - ArtifactPreviewBody( + ), + Expanded( + child: ArtifactPreviewBody( plan: plan, loading: loading, markdownBuilder: markdownBuilder, @@ -93,8 +89,8 @@ class ArtifactViewerBody extends StatelessWidget { bytes: bytes, error: error, ), - ], - ), + ), + ], ); final hasPrevious = pagedIndex(index, -1, count) != index; final hasNext = pagedIndex(index, 1, count) != index; @@ -332,3 +328,73 @@ class _Pager extends StatelessWidget { ); } } + +/// The viewer's top edge: where this artifact sits in the list, and an +/// information button for its recorded facts. +class _InfoStrip extends StatelessWidget { + const _InfoStrip({required this.label, required this.facts}); + + final String label; + final Widget facts; + + void _show(BuildContext context) { + if (usesCupertinoHost(context)) { + showCupertinoModalPopup( + context: context, + builder: (context) => CupertinoPopupSurface( + child: SafeArea( + child: SingleChildScrollView( + padding: const EdgeInsets.all(16), + child: facts, + ), + ), + ), + ); + return; + } + showModalBottomSheet( + context: context, + showDragHandle: true, + builder: (context) => SafeArea( + child: SingleChildScrollView( + padding: const EdgeInsets.fromLTRB(16, 0, 16, 16), + child: facts, + ), + ), + ); + } + + @override + Widget build(BuildContext context) { + final muted = usesCupertinoHost(context) + ? CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith( + color: CupertinoColors.secondaryLabel.resolveFrom(context), + ) + : Theme.of(context).textTheme.bodySmall?.copyWith( + color: Theme.of(context).colorScheme.onSurfaceVariant, + ); + return Padding( + padding: const EdgeInsetsDirectional.only(start: 16, end: 4), + child: Row( + children: [ + Expanded( + child: Text( + label, + key: const Key('artifact-viewer-position'), + style: muted, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ), + ArtifactIconAction( + key: const Key('artifact-info'), + label: 'Details', + icon: Icons.info_outline, + cupertinoIcon: CupertinoIcons.info, + onPressed: () => _show(context), + ), + ], + ), + ); + } +} diff --git a/app/lib/features/artifacts/ui/artifact_viewer_content.dart b/app/lib/features/artifacts/ui/artifact_viewer_content.dart index 180fe5cd..3b0f28b1 100644 --- a/app/lib/features/artifacts/ui/artifact_viewer_content.dart +++ b/app/lib/features/artifacts/ui/artifact_viewer_content.dart @@ -66,7 +66,8 @@ class ArtifactPreviewBody extends StatelessWidget { case ArtifactPreviewKind.image: final data = bytes; if (data == null) return const _Message('The image is empty.'); - return Center( + // Fitted to the frame; pinch to zoom and pan inside it. + return _ZoomableImage( child: Image.memory( data, fit: BoxFit.contain, @@ -76,23 +77,32 @@ class ArtifactPreviewBody extends StatelessWidget { ); case ArtifactPreviewKind.text: // Logs, JSON and source keep their columns: a monospace body. - return _PreviewPadding( - child: SelectableText( - text ?? '', - key: const Key('artifact-text-preview'), - style: const TextStyle(fontFamily: appMonospaceFamily), + return _Scrolling( + child: _PreviewPadding( + child: SelectableText( + text ?? '', + key: const Key('artifact-text-preview'), + style: const TextStyle(fontFamily: appMonospaceFamily), + ), ), ); case ArtifactPreviewKind.markdown: - return _PreviewPadding(child: markdownBuilder(context, text ?? '')); + return _Scrolling( + child: _PreviewPadding(child: markdownBuilder(context, text ?? '')), + ); case ArtifactPreviewKind.html: - return _PreviewPadding(child: htmlBuilder(context, text ?? '')); + // The document fills the frame and scrolls itself. + return htmlBuilder(context, text ?? ''); case ArtifactPreviewKind.table: - return ArtifactTableView(text: text ?? '', delimiter: plan.delimiter); + return _Scrolling( + child: ArtifactTableView(text: text ?? '', delimiter: plan.delimiter), + ); case ArtifactPreviewKind.video: - return ArtifactVideoPlayer( - uri: plan.resolved!.uri, - controllerFactory: videoControllerFactory, + return Center( + child: ArtifactVideoPlayer( + uri: plan.resolved!.uri, + controllerFactory: videoControllerFactory, + ), ); case ArtifactPreviewKind.unsupported: case ArtifactPreviewKind.unavailable: @@ -122,8 +132,61 @@ class _Loading extends StatelessWidget { } } -/// Preview text at its natural height; the viewer body owns the page scroll so -/// a long document and its actions scroll together instead of nested scrolls. +/// A long document scrolls inside the preview frame; the page itself stays +/// still, with its controls at the edges. +class _Scrolling extends StatelessWidget { + const _Scrolling({required this.child}); + + final Widget child; + + @override + Widget build(BuildContext context) => SingleChildScrollView( + key: const Key('artifact-preview-scroll'), + child: child, + ); +} + +/// An image fitted to the frame that can be pinched to zoom; panning only +/// starts once zoomed, so a swipe at normal size still turns the page. +class _ZoomableImage extends StatefulWidget { + const _ZoomableImage({required this.child}); + + final Widget child; + + @override + State<_ZoomableImage> createState() => _ZoomableImageState(); +} + +class _ZoomableImageState extends State<_ZoomableImage> { + final TransformationController _transform = TransformationController(); + bool _zoomed = false; + + @override + void initState() { + super.initState(); + _transform.addListener(() { + final zoomed = _transform.value.getMaxScaleOnAxis() > 1.01; + if (zoomed != _zoomed) setState(() => _zoomed = zoomed); + }); + } + + @override + void dispose() { + _transform.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) => InteractiveViewer( + key: const Key('artifact-image-zoom'), + transformationController: _transform, + panEnabled: _zoomed, + maxScale: 8, + child: SizedBox.expand(child: widget.child), + ); +} + +/// Preview text with room around it inside its frame. class _PreviewPadding extends StatelessWidget { const _PreviewPadding({required this.child}); diff --git a/app/test/features/artifacts/ui/artifact_gallery_documents_test.dart b/app/test/features/artifacts/ui/artifact_gallery_documents_test.dart index 0dadca69..368bd496 100644 --- a/app/test/features/artifacts/ui/artifact_gallery_documents_test.dart +++ b/app/test/features/artifacts/ui/artifact_gallery_documents_test.dart @@ -118,6 +118,8 @@ void main() { await tester.pumpAndSettle(); expect(find.byType(ArtifactViewerPage), findsOneWidget); expect(find.text('# Recorded input'), findsOneWidget); + await tester.tap(find.byKey(const Key('artifact-info'))); + await tester.pumpAndSettle(); expect(find.text('review · visit 1'), findsOneWidget); expect(find.text('text/markdown · 120\u00a0B'), findsOneWidget); }); diff --git a/app/test/features/artifacts/ui/artifact_viewer_page_test.dart b/app/test/features/artifacts/ui/artifact_viewer_page_test.dart index 2a9110de..9d1acd0d 100644 --- a/app/test/features/artifacts/ui/artifact_viewer_page_test.dart +++ b/app/test/features/artifacts/ui/artifact_viewer_page_test.dart @@ -108,6 +108,17 @@ Future _openMarkdownFromGallery( await tester.pumpAndSettle(); } +/// The recorded facts sit behind the viewer's Details button. +Future showFacts(WidgetTester tester) async { + await tester.tap(find.byKey(const Key('artifact-info'))); + await tester.pumpAndSettle(); +} + +Future hideFacts(WidgetTester tester) async { + await tester.tapAt(const Offset(5, 5)); + await tester.pumpAndSettle(); +} + void main() { testWidgets('an image is previewed in-app without opening a tab', ( tester, @@ -154,7 +165,14 @@ void main() { Uri.parse('http://127.0.0.1:8081/artifacts/1/1/shot.png'), }); expect(find.byType(Image), findsOneWidget); + // The page itself does not scroll; the image zooms inside its frame. + expect(find.byKey(const Key('artifact-image-zoom')), findsOneWidget); + expect( + find.ancestor(of: find.byType(Image), matching: find.byType(Scrollable)), + findsNothing, + ); expect(find.text('1 of 1 · image/png'), findsOneWidget); + await showFacts(tester); expect(find.text('image/png · 1.0\u00a0KiB'), findsOneWidget); expect(opened, isEmpty); expect(find.byType(AlertDialog), findsNothing); @@ -180,6 +198,7 @@ void main() { expect(find.byType(SelectableText), findsOneWidget); expect(find.text('build ok\n'), findsOneWidget); + await showFacts(tester); expect(find.text('text/plain · 0\u00a0B'), findsOneWidget); }); @@ -366,7 +385,9 @@ void main() { await tester.tap(find.byKey(artifactNextKey)); await tester.pumpAndSettle(); expect(find.text('2 of 3 · image/png'), findsOneWidget); + await showFacts(tester); expect(find.text('review · visit 2'), findsOneWidget); + await hideFacts(tester); expect( tester.widget(find.byKey(artifactPreviousKey)).onPressed, isNotNull, @@ -475,8 +496,9 @@ void main() { expect(find.text('final n = 1;'), findsOneWidget); expect(find.text('# Report'), findsNothing); expect(find.text('A paragraph with bold and code.'), findsOneWidget); - // The recorded facts stay visible above the preview. + // The position stays on the top edge; the facts are one tap away. expect(find.text('1 of 1 · text/markdown'), findsOneWidget); + await showFacts(tester); expect(find.text('text/markdown · 4.0\u00a0KiB'), findsOneWidget); expect(find.text('review · visit 1'), findsOneWidget); }); @@ -496,6 +518,7 @@ void main() { expect(find.text('Report'), findsOneWidget); expect(find.text('dart'), findsOneWidget); expect(find.text('1 of 1 · artifact'), findsOneWidget); + await showFacts(tester); expect(find.text('type not recorded · 4.0\u00a0KiB'), findsOneWidget); });