feat(app): artifact viewer actions are bottom icons; swipe pages; native download, share and open in browser
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import '../domain/artifact_url.dart';
|
||||
import 'artifact_external_open_stub.dart'
|
||||
if (dart.library.js_interop) 'artifact_external_open_web.dart'
|
||||
if (dart.library.io) 'artifact_external_open_io.dart'
|
||||
as impl;
|
||||
|
||||
/// Opens an already validated artifact url with the host's external handler.
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
/// Phones and desktops: the link opens in the system browser, which renders
|
||||
/// what it can and offers to download the rest.
|
||||
Future<bool> openArtifactExternally(Uri uri) async {
|
||||
try {
|
||||
return await launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -62,27 +62,10 @@ 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(
|
||||
@@ -102,11 +85,6 @@ class ArtifactViewerBody extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (status != null)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 4),
|
||||
child: Semantics(liveRegion: true, child: Text(status!)),
|
||||
),
|
||||
ArtifactPreviewBody(
|
||||
plan: plan,
|
||||
loading: loading,
|
||||
@@ -118,23 +96,60 @@ class ArtifactViewerBody extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
);
|
||||
final hasPrevious = pagedIndex(index, -1, count) != index;
|
||||
final hasNext = pagedIndex(index, 1, count) != index;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(
|
||||
child: controls.isEmpty
|
||||
? content
|
||||
: ArtifactControlsOverlay(
|
||||
key: ValueKey<String>('viewer-overlay-${page.artifact.url}'),
|
||||
controls: controls,
|
||||
child: content,
|
||||
),
|
||||
// A horizontal swipe moves to the previous or next artifact.
|
||||
child: GestureDetector(
|
||||
key: const Key('artifact-viewer-swipe'),
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onHorizontalDragEnd: (details) {
|
||||
final velocity = details.primaryVelocity ?? 0;
|
||||
if (velocity < -250 && hasNext) onNext();
|
||||
if (velocity > 250 && hasPrevious) onPrevious();
|
||||
},
|
||||
child: content,
|
||||
),
|
||||
),
|
||||
_Pager(
|
||||
index: index,
|
||||
count: count,
|
||||
onPrevious: onPrevious,
|
||||
onNext: onNext,
|
||||
// Every action as an icon at the bottom, beside the pager.
|
||||
SafeArea(
|
||||
top: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
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: Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: _Pager(
|
||||
index: index,
|
||||
count: count,
|
||||
onPrevious: onPrevious,
|
||||
onNext: onNext,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -263,40 +278,25 @@ class _Actions extends StatelessWidget {
|
||||
final VoidCallback onCopy;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (usesCupertinoHost(context)) {
|
||||
return SafeArea(
|
||||
top: false,
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
spacing: 8,
|
||||
children: [
|
||||
CupertinoButton(onPressed: onOpen, child: const Text('Open')),
|
||||
CupertinoButton(onPressed: onCopy, child: const Text('Copy link')),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return SafeArea(
|
||||
top: false,
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
spacing: 8,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: onOpen,
|
||||
icon: const Icon(Icons.open_in_new),
|
||||
label: const Text('Open'),
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: onCopy,
|
||||
icon: const Icon(Icons.content_copy),
|
||||
label: const Text('Copy link'),
|
||||
),
|
||||
],
|
||||
Widget build(BuildContext context) => Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ArtifactIconAction(
|
||||
key: const Key('artifact-open'),
|
||||
label: 'Open',
|
||||
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,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
const artifactPreviousKey = ValueKey<String>('artifact-previous');
|
||||
@@ -320,18 +320,15 @@ class _Pager extends StatelessWidget {
|
||||
if (count <= 1) return const SizedBox.shrink();
|
||||
final hasPrevious = pagedIndex(index, -1, count) != index;
|
||||
final hasNext = pagedIndex(index, 1, count) != index;
|
||||
return SafeArea(
|
||||
top: false,
|
||||
child: ChevronPager(
|
||||
index: index,
|
||||
count: count,
|
||||
previousLabel: 'Previous artifact',
|
||||
nextLabel: 'Next artifact',
|
||||
previousKey: artifactPreviousKey,
|
||||
nextKey: artifactNextKey,
|
||||
onPrevious: hasPrevious ? onPrevious : null,
|
||||
onNext: hasNext ? onNext : null,
|
||||
),
|
||||
return ChevronPager(
|
||||
index: index,
|
||||
count: count,
|
||||
previousLabel: 'Previous artifact',
|
||||
nextLabel: 'Next artifact',
|
||||
previousKey: artifactPreviousKey,
|
||||
nextKey: artifactNextKey,
|
||||
onPrevious: hasPrevious ? onPrevious : null,
|
||||
onNext: hasNext ? onNext : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user