feat(app): the artifact viewer page stays still; previews fill and zoom or scroll inside their frame; facts behind a Details button
This commit is contained in:
@@ -13,8 +13,8 @@ typedef ArtifactHtmlBuilder =
|
|||||||
/// empty `sandbox` blocks scripts, forms, popups and navigation; on Android and
|
/// empty `sandbox` blocks scripts, forms, popups and navigation; on Android and
|
||||||
/// iOS in a web view with JavaScript disabled and navigation refused. The
|
/// iOS in a web view with JavaScript disabled and navigation refused. The
|
||||||
/// document never runs code with the app's origin or credentials.
|
/// document never runs code with the app's origin or credentials.
|
||||||
Widget defaultArtifactHtml(BuildContext context, String html) => SizedBox(
|
Widget defaultArtifactHtml(BuildContext context, String html) =>
|
||||||
key: const Key('artifact-html-preview'),
|
SizedBox.expand(
|
||||||
height: MediaQuery.sizeOf(context).height * 0.7,
|
key: const Key('artifact-html-preview'),
|
||||||
child: impl.InertHtmlView(html: html),
|
child: impl.InertHtmlView(html: html),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -62,30 +62,26 @@ class ArtifactViewerBody extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final resolved = plan.resolved;
|
final resolved = plan.resolved;
|
||||||
final content = SingleChildScrollView(
|
// The page never scrolls: a thin strip on top, the preview filling the
|
||||||
child: Column(
|
// middle (it zooms or scrolls itself), the controls along the bottom.
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
final content = Column(
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
Padding(
|
children: [
|
||||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 4),
|
_InfoStrip(
|
||||||
child: ArtifactSelectionFacts(
|
label: artifactViewerPositionLabel(
|
||||||
group: page.group,
|
index,
|
||||||
artifact: page.artifact,
|
count,
|
||||||
step: null,
|
page.artifact.contentType,
|
||||||
resolved: plan.resolved,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
Padding(
|
facts: ArtifactSelectionFacts(
|
||||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 16, 4),
|
group: page.group,
|
||||||
child: Text(
|
artifact: page.artifact,
|
||||||
artifactViewerPositionLabel(
|
step: null,
|
||||||
index,
|
resolved: plan.resolved,
|
||||||
count,
|
|
||||||
page.artifact.contentType,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ArtifactPreviewBody(
|
),
|
||||||
|
Expanded(
|
||||||
|
child: ArtifactPreviewBody(
|
||||||
plan: plan,
|
plan: plan,
|
||||||
loading: loading,
|
loading: loading,
|
||||||
markdownBuilder: markdownBuilder,
|
markdownBuilder: markdownBuilder,
|
||||||
@@ -93,8 +89,8 @@ class ArtifactViewerBody extends StatelessWidget {
|
|||||||
bytes: bytes,
|
bytes: bytes,
|
||||||
error: error,
|
error: error,
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
);
|
);
|
||||||
final hasPrevious = pagedIndex(index, -1, count) != index;
|
final hasPrevious = pagedIndex(index, -1, count) != index;
|
||||||
final hasNext = 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<void>(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => CupertinoPopupSurface(
|
||||||
|
child: SafeArea(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: facts,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
showModalBottomSheet<void>(
|
||||||
|
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),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ class ArtifactPreviewBody extends StatelessWidget {
|
|||||||
case ArtifactPreviewKind.image:
|
case ArtifactPreviewKind.image:
|
||||||
final data = bytes;
|
final data = bytes;
|
||||||
if (data == null) return const _Message('The image is empty.');
|
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(
|
child: Image.memory(
|
||||||
data,
|
data,
|
||||||
fit: BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
@@ -76,23 +77,32 @@ class ArtifactPreviewBody extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
case ArtifactPreviewKind.text:
|
case ArtifactPreviewKind.text:
|
||||||
// Logs, JSON and source keep their columns: a monospace body.
|
// Logs, JSON and source keep their columns: a monospace body.
|
||||||
return _PreviewPadding(
|
return _Scrolling(
|
||||||
child: SelectableText(
|
child: _PreviewPadding(
|
||||||
text ?? '',
|
child: SelectableText(
|
||||||
key: const Key('artifact-text-preview'),
|
text ?? '',
|
||||||
style: const TextStyle(fontFamily: appMonospaceFamily),
|
key: const Key('artifact-text-preview'),
|
||||||
|
style: const TextStyle(fontFamily: appMonospaceFamily),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
case ArtifactPreviewKind.markdown:
|
case ArtifactPreviewKind.markdown:
|
||||||
return _PreviewPadding(child: markdownBuilder(context, text ?? ''));
|
return _Scrolling(
|
||||||
|
child: _PreviewPadding(child: markdownBuilder(context, text ?? '')),
|
||||||
|
);
|
||||||
case ArtifactPreviewKind.html:
|
case ArtifactPreviewKind.html:
|
||||||
return _PreviewPadding(child: htmlBuilder(context, text ?? ''));
|
// The document fills the frame and scrolls itself.
|
||||||
|
return htmlBuilder(context, text ?? '');
|
||||||
case ArtifactPreviewKind.table:
|
case ArtifactPreviewKind.table:
|
||||||
return ArtifactTableView(text: text ?? '', delimiter: plan.delimiter);
|
return _Scrolling(
|
||||||
|
child: ArtifactTableView(text: text ?? '', delimiter: plan.delimiter),
|
||||||
|
);
|
||||||
case ArtifactPreviewKind.video:
|
case ArtifactPreviewKind.video:
|
||||||
return ArtifactVideoPlayer(
|
return Center(
|
||||||
uri: plan.resolved!.uri,
|
child: ArtifactVideoPlayer(
|
||||||
controllerFactory: videoControllerFactory,
|
uri: plan.resolved!.uri,
|
||||||
|
controllerFactory: videoControllerFactory,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
case ArtifactPreviewKind.unsupported:
|
case ArtifactPreviewKind.unsupported:
|
||||||
case ArtifactPreviewKind.unavailable:
|
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 scrolls inside the preview frame; the page itself stays
|
||||||
/// a long document and its actions scroll together instead of nested scrolls.
|
/// 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 {
|
class _PreviewPadding extends StatelessWidget {
|
||||||
const _PreviewPadding({required this.child});
|
const _PreviewPadding({required this.child});
|
||||||
|
|
||||||
|
|||||||
@@ -118,6 +118,8 @@ void main() {
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
||||||
expect(find.text('# Recorded input'), 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('review · visit 1'), findsOneWidget);
|
||||||
expect(find.text('text/markdown · 120\u00a0B'), findsOneWidget);
|
expect(find.text('text/markdown · 120\u00a0B'), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -108,6 +108,17 @@ Future<void> _openMarkdownFromGallery(
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The recorded facts sit behind the viewer's Details button.
|
||||||
|
Future<void> showFacts(WidgetTester tester) async {
|
||||||
|
await tester.tap(find.byKey(const Key('artifact-info')));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> hideFacts(WidgetTester tester) async {
|
||||||
|
await tester.tapAt(const Offset(5, 5));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('an image is previewed in-app without opening a tab', (
|
testWidgets('an image is previewed in-app without opening a tab', (
|
||||||
tester,
|
tester,
|
||||||
@@ -154,7 +165,14 @@ void main() {
|
|||||||
Uri.parse('http://127.0.0.1:8081/artifacts/1/1/shot.png'),
|
Uri.parse('http://127.0.0.1:8081/artifacts/1/1/shot.png'),
|
||||||
});
|
});
|
||||||
expect(find.byType(Image), findsOneWidget);
|
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);
|
expect(find.text('1 of 1 · image/png'), findsOneWidget);
|
||||||
|
await showFacts(tester);
|
||||||
expect(find.text('image/png · 1.0\u00a0KiB'), findsOneWidget);
|
expect(find.text('image/png · 1.0\u00a0KiB'), findsOneWidget);
|
||||||
expect(opened, isEmpty);
|
expect(opened, isEmpty);
|
||||||
expect(find.byType(AlertDialog), findsNothing);
|
expect(find.byType(AlertDialog), findsNothing);
|
||||||
@@ -180,6 +198,7 @@ void main() {
|
|||||||
|
|
||||||
expect(find.byType(SelectableText), findsOneWidget);
|
expect(find.byType(SelectableText), findsOneWidget);
|
||||||
expect(find.text('build ok\n'), findsOneWidget);
|
expect(find.text('build ok\n'), findsOneWidget);
|
||||||
|
await showFacts(tester);
|
||||||
expect(find.text('text/plain · 0\u00a0B'), findsOneWidget);
|
expect(find.text('text/plain · 0\u00a0B'), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -366,7 +385,9 @@ void main() {
|
|||||||
await tester.tap(find.byKey(artifactNextKey));
|
await tester.tap(find.byKey(artifactNextKey));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(find.text('2 of 3 · image/png'), findsOneWidget);
|
expect(find.text('2 of 3 · image/png'), findsOneWidget);
|
||||||
|
await showFacts(tester);
|
||||||
expect(find.text('review · visit 2'), findsOneWidget);
|
expect(find.text('review · visit 2'), findsOneWidget);
|
||||||
|
await hideFacts(tester);
|
||||||
expect(
|
expect(
|
||||||
tester.widget<IconButton>(find.byKey(artifactPreviousKey)).onPressed,
|
tester.widget<IconButton>(find.byKey(artifactPreviousKey)).onPressed,
|
||||||
isNotNull,
|
isNotNull,
|
||||||
@@ -475,8 +496,9 @@ void main() {
|
|||||||
expect(find.text('final n = 1;'), findsOneWidget);
|
expect(find.text('final n = 1;'), findsOneWidget);
|
||||||
expect(find.text('# Report'), findsNothing);
|
expect(find.text('# Report'), findsNothing);
|
||||||
expect(find.text('A paragraph with bold and code.'), findsOneWidget);
|
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);
|
expect(find.text('1 of 1 · text/markdown'), findsOneWidget);
|
||||||
|
await showFacts(tester);
|
||||||
expect(find.text('text/markdown · 4.0\u00a0KiB'), findsOneWidget);
|
expect(find.text('text/markdown · 4.0\u00a0KiB'), findsOneWidget);
|
||||||
expect(find.text('review · visit 1'), findsOneWidget);
|
expect(find.text('review · visit 1'), findsOneWidget);
|
||||||
});
|
});
|
||||||
@@ -496,6 +518,7 @@ void main() {
|
|||||||
expect(find.text('Report'), findsOneWidget);
|
expect(find.text('Report'), findsOneWidget);
|
||||||
expect(find.text('dart'), findsOneWidget);
|
expect(find.text('dart'), findsOneWidget);
|
||||||
expect(find.text('1 of 1 · artifact'), findsOneWidget);
|
expect(find.text('1 of 1 · artifact'), findsOneWidget);
|
||||||
|
await showFacts(tester);
|
||||||
expect(find.text('type not recorded · 4.0\u00a0KiB'), findsOneWidget);
|
expect(find.text('type not recorded · 4.0\u00a0KiB'), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user