feat(app): artifact viewer controls float over the content and hide when idle

This commit is contained in:
2026-10-23 19:31:42 +01:00
parent 7b0a1a721f
commit 5acf2145ff
2 changed files with 217 additions and 58 deletions
@@ -1,3 +1,4 @@
import 'dart:async';
import '../../../ui/navigation/chevron_pager.dart';
import 'dart:typed_data';
@@ -60,69 +61,74 @@ class ArtifactViewerBody extends StatelessWidget {
@override
Widget build(BuildContext context) {
final resolved = plan.resolved;
final controls = <Widget>[
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,
),
if (resolved != null)
_Actions(resolved: resolved, onOpen: onOpen, onCopy: onCopy),
];
final content = SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Room for the controls bar, so it never covers the first line.
if (controls.isNotEmpty) const SizedBox(height: 56),
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 4),
child: ArtifactSelectionFacts(
group: page.group,
artifact: page.artifact,
step: null,
resolved: plan.resolved,
),
),
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 16, 4),
child: Text(
artifactViewerPositionLabel(
index,
count,
page.artifact.contentType,
),
),
),
if (status != null)
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 4),
child: Semantics(liveRegion: true, child: Text(status!)),
),
ArtifactPreviewBody(
plan: plan,
loading: loading,
markdownBuilder: markdownBuilder,
text: text,
bytes: bytes,
error: error,
),
],
),
);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: 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,
),
child: controls.isEmpty
? content
: ArtifactControlsOverlay(
key: ValueKey<String>('viewer-overlay-${page.artifact.url}'),
controls: controls,
child: content,
),
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 16, 4),
child: Text(
artifactViewerPositionLabel(
index,
count,
page.artifact.contentType,
),
),
),
if (status != null)
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 4),
child: Semantics(liveRegion: true, child: Text(status!)),
),
ArtifactPreviewBody(
plan: plan,
loading: loading,
markdownBuilder: markdownBuilder,
text: text,
bytes: bytes,
error: error,
),
if (plan.resolved != null && !plan.resolved!.external)
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 16, 4),
child: ArtifactFileActions(
key: ValueKey<String>(
'viewer-files-${page.group.stageKey}\u0000'
'${page.group.visit}\u0000${page.artifact.url}',
),
artifact: page.artifact,
resolved: plan.resolved!,
fetch: fetch,
bridge: fileBridge,
),
),
if (plan.resolved != null)
_Actions(
resolved: plan.resolved!,
onOpen: onOpen,
onCopy: onCopy,
),
],
),
),
),
_Pager(
index: index,
@@ -135,6 +141,116 @@ class ArtifactViewerBody extends StatelessWidget {
}
}
/// Open, Copy and the file actions float over the top of the content: shown
/// when the page opens and whenever the content is touched, hidden again after
/// a few seconds without use, so nothing needs scrolling to reach them.
class ArtifactControlsOverlay extends StatefulWidget {
const ArtifactControlsOverlay({
super.key,
required this.controls,
required this.child,
this.hideAfter = const Duration(seconds: 3),
});
final List<Widget> controls;
final Widget child;
final Duration hideAfter;
@override
State<ArtifactControlsOverlay> createState() =>
_ArtifactControlsOverlayState();
}
class _ArtifactControlsOverlayState extends State<ArtifactControlsOverlay> {
bool _shown = true;
Timer? _hide;
@override
void initState() {
super.initState();
_schedule();
}
@override
void dispose() {
_hide?.cancel();
super.dispose();
}
void _schedule() {
_hide?.cancel();
_hide = Timer(widget.hideAfter, () {
if (mounted) setState(() => _shown = false);
});
}
void _show() {
if (!_shown) setState(() => _shown = true);
_schedule();
}
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final surface = cupertino
? CupertinoColors.systemBackground
.resolveFrom(context)
.withValues(alpha: 0.92)
: Theme.of(
context,
).colorScheme.surfaceContainerHigh.withValues(alpha: 0.94);
return Stack(
children: [
// Any touch on the content brings the controls back.
Positioned.fill(
child: Listener(
behavior: HitTestBehavior.translucent,
onPointerDown: (_) => _show(),
child: widget.child,
),
),
Positioned(
left: 8,
right: 8,
top: 8,
child: IgnorePointer(
ignoring: !_shown,
child: AnimatedOpacity(
key: const Key('artifact-viewer-controls'),
opacity: _shown ? 1 : 0,
duration: const Duration(milliseconds: 200),
child: Listener(
// Using a control keeps the bar up.
onPointerDown: (_) => _schedule(),
child: DecoratedBox(
decoration: BoxDecoration(
color: surface,
borderRadius: BorderRadius.circular(12),
boxShadow: const [
BoxShadow(color: Color(0x22000000), blurRadius: 6),
],
),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 4,
vertical: 2,
),
child: Wrap(
alignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
children: widget.controls,
),
),
),
),
),
),
),
],
);
}
}
class _Actions extends StatelessWidget {
const _Actions({
required this.resolved,
@@ -0,0 +1,43 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_body.dart';
void main() {
testWidgets('controls float over the content, hide when idle and return on '
'touch', (tester) async {
var opened = 0;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ArtifactControlsOverlay(
controls: [
TextButton(onPressed: () => opened++, child: const Text('Open')),
],
child: const SizedBox.expand(child: Text('content')),
),
),
),
);
double opacity() => tester
.widget<AnimatedOpacity>(
find.byKey(const Key('artifact-viewer-controls')),
)
.opacity;
// Shown on open, on top of the content without scrolling.
expect(opacity(), 1);
await tester.tap(find.text('Open'));
expect(opened, 1);
await tester.pump(const Duration(seconds: 4));
await tester.pumpAndSettle();
expect(opacity(), 0);
// Hidden controls take no taps.
await tester.tap(find.text('Open'), warnIfMissed: false);
expect(opened, 1);
await tester.tap(find.text('content'));
await tester.pump();
expect(opacity(), 1);
});
}