4e0481fd8d
Full screen button in the viewer's bottom bar opens a root full-screen route with the same bar and top bar; exit by the bar, Close, Escape or back. It renders the already fetched bytes, never the system browser. The external Open action is now labelled Open in browser. Native web views claim their gestures (vertical drags inline, every pointer in full screen) so the page swipe no longer starves them. On the web, full screen adds zoom buttons that scale the live sandboxed frame. Links: in-page anchors scroll, http(s)/mailto open outside, everything else is inert. Capture kit: --touch, swipe=, pinch=, tabs=; html=1 fixture artifact.
159 lines
5.4 KiB
Dart
159 lines
5.4 KiB
Dart
import 'dart:math' as math;
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/adaptive/glass_bar.dart';
|
|
import '../../../ui/adaptive/host.dart';
|
|
import '../../../ui/navigation/chevron_pager.dart';
|
|
import '../actions/artifact_file_actions.dart';
|
|
import '../actions/artifact_file_bridge.dart';
|
|
import '../domain/artifact_url.dart';
|
|
import '../domain/gallery_navigation.dart';
|
|
import 'artifact_viewer_fetch.dart';
|
|
|
|
const artifactPreviousKey = ValueKey<String>('artifact-previous');
|
|
const artifactNextKey = ValueKey<String>('artifact-next');
|
|
const artifactFullscreenKey = ValueKey<String>('artifact-fullscreen');
|
|
|
|
/// The viewer's bottom controls: file transfer, Open, Copy link, Full screen
|
|
/// and the pager, in one glass bar above the bottom safe area.
|
|
///
|
|
/// The inline viewer and the full-screen view draw this same bar; in full
|
|
/// screen the Full screen control reads Exit full screen and leaves it.
|
|
class ArtifactViewerBar extends StatelessWidget {
|
|
const ArtifactViewerBar({
|
|
super.key,
|
|
required this.page,
|
|
required this.resolved,
|
|
required this.index,
|
|
required this.count,
|
|
required this.fetch,
|
|
required this.fileBridge,
|
|
required this.onOpen,
|
|
required this.onCopy,
|
|
required this.onPrevious,
|
|
required this.onNext,
|
|
this.fullscreen = false,
|
|
this.onFullscreen,
|
|
});
|
|
|
|
final PagedArtifact page;
|
|
final ResolvedArtifactUrl? resolved;
|
|
final int index;
|
|
final int count;
|
|
final ArtifactFetch fetch;
|
|
final ArtifactFileBridge fileBridge;
|
|
final VoidCallback onOpen;
|
|
final VoidCallback onCopy;
|
|
final VoidCallback onPrevious;
|
|
final VoidCallback onNext;
|
|
|
|
/// Whether this bar is the full-screen view's.
|
|
final bool fullscreen;
|
|
|
|
/// Enters (inline) or leaves (in full screen) the full-screen view; absent,
|
|
/// the control is not drawn.
|
|
final VoidCallback? onFullscreen;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cupertino = usesCupertinoHost(context);
|
|
final actions = _actions(resolved, onFullscreen);
|
|
final pagerMin = count > 1
|
|
? 2 * GlassBarMetrics.controlExtent(cupertino)
|
|
: 0.0;
|
|
final pager = ChevronPager(
|
|
index: index,
|
|
count: count,
|
|
previousLabel: 'Previous artifact',
|
|
nextLabel: 'Next artifact',
|
|
previousKey: artifactPreviousKey,
|
|
nextKey: artifactNextKey,
|
|
onPrevious: pagedIndex(index, -1, count) != index ? onPrevious : null,
|
|
onNext: pagedIndex(index, 1, count) != index ? onNext : null,
|
|
);
|
|
return SafeArea(
|
|
// The SafeArea already lifts the bar by the inherited bottom inset (a
|
|
// shell bar below the pane); adding that clearance again floated the
|
|
// bar far above it.
|
|
top: false,
|
|
minimum: const EdgeInsets.all(8),
|
|
// Without a pager the bar is as wide as its actions, so its last
|
|
// control keeps the same gap from the bar's end as the first.
|
|
child: Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
heightFactor: 1,
|
|
child: GlassControlBar(
|
|
cupertino: cupertino,
|
|
child: LayoutBuilder(
|
|
builder: (context, constraints) => Row(
|
|
key: const Key('artifact-viewer-actions'),
|
|
mainAxisSize: count > 1 ? MainAxisSize.max : MainAxisSize.min,
|
|
children: [
|
|
// On a narrow window or at large text the actions scroll
|
|
// sideways, so the chevrons beside them stay whole.
|
|
ConstrainedBox(
|
|
constraints: BoxConstraints(
|
|
maxWidth: math.max(0, constraints.maxWidth - pagerMin),
|
|
),
|
|
child: SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: actions,
|
|
),
|
|
),
|
|
),
|
|
if (count > 1) Expanded(child: pager),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
List<Widget> _actions(ResolvedArtifactUrl? resolved, VoidCallback? toggle) =>
|
|
[
|
|
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) ...[
|
|
ArtifactIconAction(
|
|
key: const Key('artifact-open'),
|
|
label: 'Open in browser',
|
|
icon: Icons.open_in_new,
|
|
cupertinoIcon: CupertinoIcons.arrow_up_right_square,
|
|
onPressed: onOpen,
|
|
),
|
|
ArtifactIconAction(
|
|
key: const Key('artifact-copy-link'),
|
|
label: 'Copy link',
|
|
icon: Icons.link,
|
|
cupertinoIcon: CupertinoIcons.link,
|
|
onPressed: onCopy,
|
|
),
|
|
],
|
|
if (toggle != null)
|
|
ArtifactIconAction(
|
|
key: artifactFullscreenKey,
|
|
label: fullscreen ? 'Exit full screen' : 'Full screen',
|
|
icon: fullscreen ? Icons.fullscreen_exit : Icons.fullscreen,
|
|
cupertinoIcon: fullscreen
|
|
? CupertinoIcons.fullscreen_exit
|
|
: CupertinoIcons.fullscreen,
|
|
onPressed: toggle,
|
|
),
|
|
];
|
|
}
|