Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Consolidate viewer sharing actions

ashil-pilot02dee32148d0
diff --git a/mobile/apps/photos/changes/file-viewer-sharing.md b/mobile/apps/photos/changes/file-viewer-sharing.md
new file mode 100644
index 0000000000..042c7ac987
--- /dev/null
+++ b/mobile/apps/photos/changes/file-viewer-sharing.md
@@ -0,0 +1 @@
+- Share a photo or video, or send a link, from the Share button in the viewer.
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
index 477a9d9038..a717a8b1aa 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
@@ -5,7 +5,6 @@ import "package:ente_components/ente_components.dart";
import "package:ente_lock_screen/local_authentication_service.dart";
import "package:ente_strings/ente_strings.dart";
import 'package:flutter/material.dart';
-import "package:flutter/services.dart";
import "package:flutter_svg/flutter_svg.dart";
import "package:hugeicons/hugeicons.dart";
import "package:local_auth/local_auth.dart";
@@ -29,7 +28,6 @@ import 'package:photos/services/hidden_service.dart';
import "package:photos/services/video_preview_service.dart";
import "package:photos/states/detail_page_state.dart";
import "package:photos/theme/colors.dart";
-import "package:photos/ui/actions/collection/collection_sharing_actions.dart";
import "package:photos/ui/actions/file/file_actions.dart";
import 'package:photos/ui/collections/collection_action_sheet.dart';
import "package:photos/ui/common/photo_library_add_permission.dart";
@@ -42,7 +40,6 @@ import "package:photos/ui/viewer/file_details/favorite_widget.dart";
import "package:photos/ui/viewer/file_details/upload_icon_widget.dart";
import 'package:photos/utils/dialog_util.dart';
import "package:photos/utils/magic_util.dart";
-import "package:photos/utils/share_util.dart";
String _formatPlaybackSpeed(double speed) {
return speed == 1.0 ? "1x" : "${speed}x";
@@ -345,15 +342,6 @@ class FileAppBarState extends State<FileAppBar> {
hugeIcon: HugeIcons.strokeRoundedDownload01,
),
);
- if (isOwnedByUser && !isFileHidden) {
- items.add(
- _fileMenuOption(
- context.strings.sendLink,
- value: 14,
- hugeIcon: HugeIcons.strokeRoundedNavigation03,
- ),
- );
- }
}
if (widget.showEditAction &&
(widget.file.fileType == FileType.image ||
@@ -549,8 +537,6 @@ class FileAppBarState extends State<FileAppBar> {
) async {
if (value == 1) {
await _download(widget.file);
- } else if (value == 14) {
- await _sendLink(widget.file);
} else if (value == 2) {
await _toggleFileArchiveStatus(widget.file);
} else if (value == 3) {
@@ -730,44 +716,6 @@ class FileAppBarState extends State<FileAppBar> {
}
}
- Future<void> _sendLink(EnteFile file) async {
- if (!file.isUploaded || !file.isOwner) {
- showShortToast(
- context,
- context.strings.canOnlyCreateLinkForFilesOwnedByYou,
- );
- return;
- }
- final dialog = createProgressDialog(
- context,
- context.strings.creatingLink,
- isDismissible: true,
- );
- await dialog.show();
- if (!mounted) {
- await dialog.hide();
- return;
- }
- final Collection? sharedLinkCollection = await CollectionActions(
- CollectionsService.instance,
- ).createSharedCollectionLink(context, [file]);
- if (!mounted) {
- await dialog.hide();
- return;
- }
- if (sharedLinkCollection == null) {
- await dialog.hide();
- return;
- }
- final String url = CollectionsService.instance.getPublicUrl(
- sharedLinkCollection,
- );
- await dialog.hide();
- unawaited(Clipboard.setData(ClipboardData(text: url)));
- if (!mounted) return;
- await shareLinkWithDescription(url, context: context);
- }
-
Future<void> _setAs(EnteFile file) async {
final dialog = createProgressDialog(context, context.strings.pleaseWait);
await dialog.show();
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
index 43e7d09f08..ff47077451 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
@@ -1,10 +1,10 @@
import "dart:async";
-import "dart:io";
import "package:ente_strings/ente_strings.dart";
import "package:ente_ui/utils/toast_util.dart";
import "package:flutter/cupertino.dart";
import "package:flutter/material.dart";
+import "package:flutter/services.dart";
import "package:flutter_svg/flutter_svg.dart";
import "package:hugeicons/hugeicons.dart";
import "package:photo_manager/photo_manager.dart";
@@ -19,9 +19,11 @@ import 'package:photos/module/metadata/panorama.dart';
import "package:photos/service_locator.dart";
import "package:photos/services/collections_service.dart";
import "package:photos/states/detail_page_state.dart";
+import "package:photos/ui/actions/collection/collection_sharing_actions.dart";
import "package:photos/ui/actions/file/file_actions.dart";
import "package:photos/ui/collections/collection_action_sheet.dart";
import "package:photos/ui/viewer/actions/suggest_delete_sheet.dart";
+import "package:photos/ui/viewer/file/file_share_button.dart";
import "package:photos/utils/delete_file_util.dart";
import "package:photos/utils/dialog_util.dart";
import "package:photos/utils/share_util.dart";
@@ -96,6 +98,7 @@ class FileBottomBarState extends State<FileBottomBar> {
}
Widget _getBottomBar() {
+ final file = widget.file;
final isInSharedCollection =
InheritedDetailPageState.maybeOf(
context,
@@ -150,22 +153,15 @@ class FileBottomBarState extends State<FileBottomBar> {
}
children.add(
- Tooltip(
- message: context.strings.share,
- child: Padding(
- padding: const EdgeInsets.only(top: 12),
- child: IconButton(
- key: shareButtonKey,
- icon: Platform.isAndroid
- ? const HugeIcon(
- icon: HugeIcons.strokeRoundedShare08,
- color: Colors.white,
- )
- : const Icon(CupertinoIcons.share, color: Colors.white),
- onPressed: () {
- share(context, [widget.file], shareButtonKey: shareButtonKey);
- },
- ),
+ Padding(
+ padding: const EdgeInsets.only(top: 12),
+ child: FileShareButton(
+ key: shareButtonKey,
+ canSendLink: file.isUploaded && file.isOwner && !isFileHidden,
+ isVideo: file.isVideo,
+ onSendFile: () =>
+ share(context, [file], shareButtonKey: shareButtonKey),
+ onSendLink: () => _sendLink(file),
),
),
);
@@ -233,6 +229,44 @@ class FileBottomBarState extends State<FileBottomBar> {
);
}
+ Future<void> _sendLink(EnteFile file) async {
+ if (!file.isUploaded || !file.isOwner) {
+ showShortToast(
+ context,
+ context.strings.canOnlyCreateLinkForFilesOwnedByYou,
+ );
+ return;
+ }
+ final dialog = createProgressDialog(
+ context,
+ context.strings.creatingLink,
+ isDismissible: true,
+ );
+ await dialog.show();
+ if (!mounted) {
+ await dialog.hide();
+ return;
+ }
+ final Collection? sharedLinkCollection = await CollectionActions(
+ CollectionsService.instance,
+ ).createSharedCollectionLink(context, [file]);
+ if (!mounted) {
+ await dialog.hide();
+ return;
+ }
+ if (sharedLinkCollection == null) {
+ await dialog.hide();
+ return;
+ }
+ final String url = CollectionsService.instance.getPublicUrl(
+ sharedLinkCollection,
+ );
+ await dialog.hide();
+ unawaited(Clipboard.setData(ClipboardData(text: url)));
+ if (!mounted) return;
+ await shareLinkWithDescription(url, context: context, key: shareButtonKey);
+ }
+
void _addTrashOptions(List<Widget> children) {
children.add(
Tooltip(
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_share_button.dart b/mobile/apps/photos/lib/ui/viewer/file/file_share_button.dart
new file mode 100644
index 0000000000..e34aaac5b4
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_share_button.dart
@@ -0,0 +1,441 @@
+import "dart:async";
+import "dart:io";
+import "dart:math" as math;
+
+import "package:ente_components/ente_components.dart";
+import "package:ente_strings/ente_strings.dart";
+import "package:flutter/cupertino.dart";
+import "package:flutter/material.dart";
+import "package:hugeicons/hugeicons.dart";
+
+enum _FileShareAction { file, link }
+
+class FileShareButton extends StatefulWidget {
+ const FileShareButton({
+ required this.canSendLink,
+ required this.isVideo,
+ required this.onSendFile,
+ required this.onSendLink,
+ super.key,
+ });
+
+ final bool canSendLink;
+ final bool isVideo;
+ final FutureOr<void> Function() onSendFile;
+ final FutureOr<void> Function() onSendLink;
+
+ @override
+ State<FileShareButton> createState() => _FileShareButtonState();
+}
+
+class _FileShareButtonState extends State<FileShareButton> {
+ _FileShareRoute? _route;
+
+ @override
+ void dispose() {
+ final route = _route;
+ if (route != null) {
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (route.isActive) route.navigator?.removeRoute(route);
+ });
+ }
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return IconButton(
+ tooltip: context.strings.share,
+ icon: Platform.isAndroid
+ ? const HugeIcon(
+ icon: HugeIcons.strokeRoundedShare08,
+ color: Colors.white,
+ )
+ : const Icon(CupertinoIcons.share, color: Colors.white),
+ onPressed: _share,
+ );
+ }
+
+ Future<void> _share() async {
+ if (_route != null) return;
+ final sendFile = widget.onSendFile;
+ final sendLink = widget.onSendLink;
+ if (!widget.canSendLink) {
+ await sendFile();
+ return;
+ }
+
+ final navigator = Navigator.of(context);
+ Rect anchorRect() {
+ final button = context.findRenderObject()! as RenderBox;
+ final overlay =
+ navigator.overlay!.context.findRenderObject()! as RenderBox;
+ return button.localToGlobal(Offset.zero, ancestor: overlay) & button.size;
+ }
+
+ final initialAnchor = anchorRect();
+ final route = _FileShareRoute(
+ anchorRect: () => mounted ? anchorRect() : initialAnchor,
+ fileLabel: widget.isVideo
+ ? context.strings.sendVideo
+ : context.strings.sendPhoto,
+ linkLabel: context.strings.sendLink,
+ shareLabel: context.strings.share,
+ closeLabel: context.strings.close,
+ isVideo: widget.isVideo,
+ reduceMotion: MediaQuery.disableAnimationsOf(context),
+ themes: InheritedTheme.capture(from: context, to: navigator.context),
+ );
+ _route = route;
+ final action = await navigator.push(route);
+ // Native sharing must wait until the popup's overlay has been removed.
+ await route.completed;
+ _route = null;
+ if (!mounted) return;
+ switch (action) {
+ case _FileShareAction.file:
+ await sendFile();
+ case _FileShareAction.link:
+ await sendLink();
+ case null:
+ break;
+ }
+ }
+}
+
+class _FileShareRoute extends PopupRoute<_FileShareAction> {
+ _FileShareRoute({
+ required this.anchorRect,
+ required this.fileLabel,
+ required this.linkLabel,
+ required this.shareLabel,
+ required this.closeLabel,
+ required this.isVideo,
+ required this.reduceMotion,
+ required this.themes,
+ });
+
+ final Rect Function() anchorRect;
+ final String fileLabel;
+ final String linkLabel;
+ final String shareLabel;
+ final String closeLabel;
+ final bool isVideo;
+ final bool reduceMotion;
+ final CapturedThemes themes;
+
+ @override
+ Color? get barrierColor => null;
+ @override
+ bool get barrierDismissible => true;
+ @override
+ String get barrierLabel => closeLabel;
+ @override
+ Duration get transitionDuration =>
+ Duration(milliseconds: reduceMotion ? 120 : 260);
+ @override
+ Duration get reverseTransitionDuration =>
+ Duration(milliseconds: reduceMotion ? 120 : 140);
+
+ void _select([_FileShareAction? action]) {
+ if (isCurrent) navigator!.pop(action);
+ }
+
+ @override
+ Widget buildPage(
+ BuildContext context,
+ Animation<double> animation,
+ Animation<double> secondaryAnimation,
+ ) {
+ return themes.wrap(
+ LayoutBuilder(
+ builder: (context, constraints) {
+ final mediaQuery = MediaQuery.of(context);
+ final anchor = anchorRect();
+ return Semantics(
+ scopesRoute: true,
+ namesRoute: true,
+ label: shareLabel,
+ explicitChildNodes: true,
+ child: Stack(
+ children: [
+ CustomSingleChildLayout(
+ delegate: _ShareDockLayout(anchor, mediaQuery.padding),
+ child: _ShareDockTransition(
+ animation: animation,
+ reduceMotion: reduceMotion,
+ child: _ShareDock(
+ fileLabel: fileLabel,
+ linkLabel: linkLabel,
+ isVideo: isVideo,
+ maxHalfWidth:
+ (constraints.maxWidth -
+ mediaQuery.padding.horizontal) *
+ 0.35,
+ onSelected: _select,
+ ),
+ ),
+ ),
+ Positioned.fromRect(
+ rect: anchor,
+ child: Semantics(
+ button: true,
+ label: closeLabel,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: _select,
+ child: const SizedBox.expand(),
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ },
+ ),
+ );
+ }
+}
+
+class _ShareDockTransition extends StatelessWidget {
+ const _ShareDockTransition({
+ required this.animation,
+ required this.reduceMotion,
+ required this.child,
+ });
+
+ final Animation<double> animation;
+ final bool reduceMotion;
+ final Widget child;
+
+ static const _riseCurve = Cubic(0.2, 0.7, 0.3, 1);
+ static final _scale = Tween<double>(
+ begin: 0.96,
+ end: 1,
+ ).chain(CurveTween(curve: _riseCurve));
+ static final _offset = Tween<double>(
+ begin: 14,
+ end: 0,
+ ).chain(CurveTween(curve: _riseCurve));
+
+ @override
+ Widget build(BuildContext context) {
+ if (reduceMotion) {
+ return FadeTransition(opacity: animation, child: child);
+ }
+ return DualTransitionBuilder(
+ animation: animation,
+ forwardBuilder: (context, entrance, child) => FadeTransition(
+ opacity: entrance.drive(
+ CurveTween(curve: const Interval(0, 0.68, curve: _riseCurve)),
+ ),
+ child: AnimatedBuilder(
+ animation: entrance,
+ builder: (context, child) => Transform.translate(
+ offset: Offset(0, _offset.transform(entrance.value)),
+ child: Transform.scale(
+ scale: _scale.transform(entrance.value),
+ alignment: Alignment.bottomCenter,
+ child: child,
+ ),
+ ),
+ child: child,
+ ),
+ ),
+ reverseBuilder: (context, exit, child) {
+ final closing = exit.drive(CurveTween(curve: Curves.easeIn));
+ return FadeTransition(
+ opacity: ReverseAnimation(closing),
+ child: AnimatedBuilder(
+ animation: closing,
+ builder: (context, child) => Transform.translate(
+ offset: Offset(0, 6 * closing.value),
+ child: Transform.scale(
+ scale: 1 - 0.02 * closing.value,
+ alignment: Alignment.bottomCenter,
+ child: child,
+ ),
+ ),
+ child: child,
+ ),
+ );
+ },
+ child: child,
+ );
+ }
+}
+
+class _ShareDockLayout extends SingleChildLayoutDelegate {
+ const _ShareDockLayout(this.anchor, this.padding);
+
+ final Rect anchor;
+ final EdgeInsets padding;
+
+ @override
+ BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
+ return BoxConstraints(
+ maxWidth: math.max(0, constraints.maxWidth - padding.horizontal - 32),
+ maxHeight: math.max(0, anchor.top - padding.top - 24),
+ );
+ }
+
+ @override
+ Offset getPositionForChild(Size size, Size childSize) {
+ return Offset(
+ (anchor.center.dx - childSize.width / 2).clamp(
+ padding.left + 16,
+ size.width - padding.right - childSize.width - 16,
+ ),
+ anchor.top - childSize.height - 12,
+ );
+ }
+
+ @override
+ bool shouldRelayout(_ShareDockLayout oldDelegate) =>
+ anchor != oldDelegate.anchor || padding != oldDelegate.padding;
+}
+
+class _ShareDock extends StatelessWidget {
+ const _ShareDock({
+ required this.fileLabel,
+ required this.linkLabel,
+ required this.isVideo,
+ required this.maxHalfWidth,
+ required this.onSelected,
+ });
+
+ final String fileLabel;
+ final String linkLabel;
+ final bool isVideo;
+ final double maxHalfWidth;
+ final ValueChanged<_FileShareAction> onSelected;
+
+ static final _labelStyle = TextStyles.body.copyWith(color: Colors.white);
+
+ @override
+ Widget build(BuildContext context) {
+ return LayoutBuilder(
+ builder: (context, constraints) {
+ final textScaler = MediaQuery.textScalerOf(context);
+ final painter = TextPainter(
+ textDirection: Directionality.of(context),
+ textScaler: textScaler,
+ );
+ var contentWidth = 26.0;
+ for (final label in [fileLabel, linkLabel]) {
+ painter.text = TextSpan(text: label, style: _labelStyle);
+ painter.layout();
+ contentWidth = math.max(contentWidth, painter.width);
+ }
+ final halfWidth = math.min(
+ maxHalfWidth,
+ math.max(kMinInteractiveDimension, contentWidth + 24),
+ );
+ final dockWidth = math.min(constraints.maxWidth, halfWidth * 2 + 17);
+ var stacked = false;
+ if (textScaler.scale(_labelStyle.fontSize!) >=
+ _labelStyle.fontSize! * 2) {
+ painter.maxLines = 2;
+ for (final label in [fileLabel, linkLabel]) {
+ painter.text = TextSpan(text: label, style: _labelStyle);
+ painter.layout(maxWidth: math.max(0, (dockWidth - 17) / 2 - 24));
+ stacked |= painter.didExceedMaxLines;
+ }
+ }
+ painter.dispose();
+
+ final file = _action(
+ label: fileLabel,
+ icon: isVideo
+ ? HugeIcons.strokeRoundedVideo01
+ : HugeIcons.strokeRoundedImage01,
+ action: _FileShareAction.file,
+ stacked: stacked,
+ );
+ final link = _action(
+ label: linkLabel,
+ icon: HugeIcons.strokeRoundedLink02,
+ action: _FileShareAction.link,
+ stacked: stacked,
+ );
+ final dividerColor = Colors.white.withValues(alpha: 0.16);
+ return SizedBox(
+ width: stacked ? math.min(360, constraints.maxWidth) : dockWidth,
+ child: Material(
+ key: const ValueKey("file-share-dock"),
+ color: ColorTokens.dark.fillLight.withValues(alpha: 0.96),
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(24),
+ side: BorderSide(color: Colors.white.withValues(alpha: 0.22)),
+ ),
+ clipBehavior: Clip.antiAlias,
+ child: SingleChildScrollView(
+ padding: const EdgeInsets.all(8),
+ child: stacked
+ ? Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ file,
+ Divider(height: 1, thickness: 1, color: dividerColor),
+ link,
+ ],
+ )
+ : IntrinsicHeight(
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Expanded(child: file),
+ VerticalDivider(
+ width: 1,
+ thickness: 1,
+ color: dividerColor,
+ ),
+ Expanded(child: link),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ },
+ );
+ }
+
+ Widget _action({
+ required String label,
+ required List<List<dynamic>> icon,
+ required _FileShareAction action,
+ required bool stacked,
+ }) {
+ final iconWidget = HugeIcon(icon: icon, color: Colors.white, size: 26);
+ final text = Text(
+ label,
+ style: _labelStyle,
+ textAlign: stacked ? TextAlign.start : TextAlign.center,
+ );
+ return InkWell(
+ key: ValueKey("file-share-${action.name}"),
+ borderRadius: BorderRadius.circular(16),
+ onTap: () => onSelected(action),
+ child: ConstrainedBox(
+ constraints: BoxConstraints(minHeight: stacked ? 64 : 88),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 16),
+ child: stacked
+ ? Row(
+ children: [
+ iconWidget,
+ const SizedBox(width: 16),
+ Expanded(child: text),
+ ],
+ )
+ : Column(
+ mainAxisSize: MainAxisSize.min,
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [iconWidget, const SizedBox(height: 10), text],
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/apps/photos/test/ui/viewer/file/file_share_button_test.dart b/mobile/apps/photos/test/ui/viewer/file/file_share_button_test.dart
new file mode 100644
index 0000000000..7ba986e625
--- /dev/null
+++ b/mobile/apps/photos/test/ui/viewer/file/file_share_button_test.dart
@@ -0,0 +1,325 @@
+import "package:ente_components/ente_components.dart";
+import "package:ente_strings/ente_strings.dart";
+import "package:ente_strings/l10n/strings_localizations_en.dart";
+import "package:flutter/foundation.dart";
+import "package:flutter/material.dart";
+import "package:flutter/semantics.dart";
+import "package:flutter/services.dart";
+import "package:flutter_test/flutter_test.dart";
+import "package:photos/ui/viewer/file/file_share_button.dart";
+
+const _dockKey = ValueKey("file-share-dock");
+const _fileKey = ValueKey("file-share-file");
+const _linkKey = ValueKey("file-share-link");
+
+class _LongStrings extends StringsLocalizationsEn {
+ @override
+ String get sendVideo => "Eine Kopie dieses Videos an eine andere App senden";
+ @override
+ String get sendLink =>
+ "Einen Link zu diesem Video mit anderen Personen teilen";
+}
+
+class _LongStringsDelegate extends LocalizationsDelegate<StringsLocalizations> {
+ const _LongStringsDelegate();
+ @override
+ bool isSupported(Locale locale) => true;
+ @override
+ Future<StringsLocalizations> load(Locale locale) =>
+ SynchronousFuture(_LongStrings());
+ @override
+ bool shouldReload(_LongStringsDelegate old) => false;
+}
+
+Future<void> _pumpShareButton(
+ WidgetTester tester, {
+ required VoidCallback onSendFile,
+ required VoidCallback onSendLink,
+ VoidCallback? onBackgroundTap,
+ bool canSendLink = true,
+ bool isVideo = false,
+ double textScale = 1,
+ bool longLabels = false,
+ bool reduceMotion = false,
+ TextDirection direction = TextDirection.ltr,
+ Size size = const Size(390, 844),
+}) async {
+ await tester.binding.setSurfaceSize(size);
+ addTearDown(() => tester.binding.setSurfaceSize(null));
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: ComponentTheme.darkTheme(),
+ localizationsDelegates: [
+ if (longLabels) const _LongStringsDelegate(),
+ ...StringsLocalizations.localizationsDelegates,
+ ],
+ supportedLocales: const [Locale("en")],
+ builder: (context, child) => MediaQuery(
+ data: MediaQuery.of(context).copyWith(
+ textScaler: TextScaler.linear(textScale),
+ disableAnimations: reduceMotion,
+ ),
+ child: Directionality(textDirection: direction, child: child!),
+ ),
+ home: Scaffold(
+ body: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onBackgroundTap,
+ child: Align(
+ alignment: Alignment.bottomCenter,
+ child: SafeArea(
+ child: FileShareButton(
+ canSendLink: canSendLink,
+ isVideo: isVideo,
+ onSendFile: onSendFile,
+ onSendLink: onSendLink,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+}
+
+void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+ setUpAll(() async {
+ final font = FontLoader("packages/ente_components/Inter")
+ ..addFont(
+ rootBundle.load("packages/ente_components/fonts/Inter-Medium.ttf"),
+ );
+ await font.load();
+ });
+
+ testWidgets("dock opens without overshoot and shares only after closing", (
+ tester,
+ ) async {
+ var filesSent = 0;
+ var linksSent = 0;
+ await _pumpShareButton(
+ tester,
+ onSendFile: () {
+ expect(find.byKey(_dockKey), findsNothing);
+ filesSent++;
+ },
+ onSendLink: () {
+ expect(find.byKey(_dockKey), findsNothing);
+ linksSent++;
+ },
+ );
+
+ final button = find.byType(FileShareButton);
+ final buttonRect = tester.getRect(button);
+ await tester.tap(button);
+ await tester.pump();
+ final openingRect = tester.getRect(find.byKey(_dockKey));
+ await tester.pump(const Duration(milliseconds: 40));
+ final risingRect = tester.getRect(find.byKey(_dockKey));
+ expect(risingRect.width, greaterThan(openingRect.width));
+ expect(risingRect.bottom, lessThan(openingRect.bottom));
+ expect(tester.getRect(button), buttonRect);
+ await tester.pump(const Duration(milliseconds: 69));
+ final approachingRect = tester.getRect(find.byKey(_dockKey));
+ await tester.pumpAndSettle();
+ final settledRect = tester.getRect(find.byKey(_dockKey));
+ expect(approachingRect.width, greaterThanOrEqualTo(risingRect.width));
+ expect(approachingRect.width, lessThanOrEqualTo(settledRect.width));
+ expect(approachingRect.bottom, lessThanOrEqualTo(risingRect.bottom));
+ expect(approachingRect.bottom, greaterThanOrEqualTo(settledRect.bottom));
+ final fileRect = tester.getRect(find.byKey(_fileKey));
+ final linkRect = tester.getRect(find.byKey(_linkKey));
+ expect(linkRect.bottom, lessThan(buttonRect.top));
+ expect(fileRect.center.dy, linkRect.center.dy);
+ expect(fileRect.size, linkRect.size);
+ expect(fileRect.width, lessThan(390 * 0.35));
+ expect(tester.getRect(find.byKey(_dockKey)).width, lessThan(390 * 0.7));
+ expect(fileRect.height, greaterThanOrEqualTo(kMinInteractiveDimension));
+
+ await tester.binding.setSurfaceSize(const Size(844, 390));
+ await tester.pumpAndSettle();
+ final rotatedButton = tester.getRect(button);
+ final rotatedDock = tester.getRect(find.byKey(_dockKey));
+ expect(rotatedDock.bottom, lessThan(rotatedButton.top));
+ expect(rotatedDock.center.dx, closeTo(rotatedButton.center.dx, 1));
+ expect(rotatedDock.width, closeTo(settledRect.width, 1));
+
+ await tester.tap(find.text("Send photo"));
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 50));
+ expect(filesSent, 0);
+ await tester.pumpAndSettle();
+ expect(filesSent, 1);
+ expect(linksSent, 0);
+
+ await tester.tap(button);
+ await tester.pumpAndSettle();
+ await tester.tap(find.text("Send link"));
+ await tester.pumpAndSettle();
+ expect(filesSent, 1);
+ expect(linksSent, 1);
+ });
+
+ testWidgets("dismissal cancels without sharing or activating the viewer", (
+ tester,
+ ) async {
+ final semantics = tester.ensureSemantics();
+ var actions = 0;
+ var backgroundTaps = 0;
+ await _pumpShareButton(
+ tester,
+ onSendFile: () => actions++,
+ onSendLink: () => actions++,
+ onBackgroundTap: () => backgroundTaps++,
+ );
+ final button = find.byType(FileShareButton);
+ final anchor = tester.getCenter(button);
+ for (final cancel in <Future<void> Function()>[
+ () => tester.tapAt(const Offset(20, 20)),
+ () => tester.tapAt(anchor),
+ () async {
+ await tester.binding.handlePopRoute();
+ },
+ () => tester.sendKeyEvent(LogicalKeyboardKey.escape),
+ () async {
+ tester.semantics.dismiss(
+ find.semantics.byAction(SemanticsAction.dismiss),
+ );
+ },
+ ]) {
+ await tester.tap(button);
+ await tester.pumpAndSettle();
+ await cancel();
+ await tester.pumpAndSettle();
+ expect(find.byKey(_dockKey), findsNothing);
+ expect(actions, 0);
+ expect(backgroundTaps, 0);
+ }
+
+ await tester.tap(button);
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 70));
+ final openingRect = tester.getRect(find.byKey(_dockKey));
+ await tester.tapAt(anchor);
+ await tester.pump();
+ expect(tester.getRect(find.byKey(_dockKey)), openingRect);
+ await tester.pumpAndSettle();
+ expect(find.byKey(_dockKey), findsNothing);
+ expect(actions, 0);
+ expect(backgroundTaps, 0);
+ semantics.dispose();
+ });
+
+ testWidgets("Reduce Motion fades without shifting or scaling the dock", (
+ tester,
+ ) async {
+ await _pumpShareButton(
+ tester,
+ reduceMotion: true,
+ onSendFile: () {},
+ onSendLink: () {},
+ );
+ await tester.tap(find.byType(FileShareButton));
+ await tester.pump();
+ final openingRect = tester.getRect(find.byKey(_dockKey));
+ await tester.pump(const Duration(milliseconds: 60));
+ final fade = find.ancestor(
+ of: find.byKey(_dockKey),
+ matching: find.byType(FadeTransition),
+ );
+ expect(
+ tester.widget<FadeTransition>(fade).opacity.value,
+ allOf(greaterThan(0), lessThan(1)),
+ );
+ expect(tester.getRect(find.byKey(_dockKey)), openingRect);
+ await tester.pumpAndSettle();
+ expect(tester.getRect(find.byKey(_dockKey)), openingRect);
+ await tester.tapAt(const Offset(20, 20));
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 60));
+ expect(tester.getRect(find.byKey(_dockKey)), openingRect);
+ await tester.pumpAndSettle();
+ expect(find.byKey(_dockKey), findsNothing);
+ });
+
+ testWidgets("shares directly when a link is unavailable", (tester) async {
+ var filesSent = 0;
+ var linksSent = 0;
+ await _pumpShareButton(
+ tester,
+ canSendLink: false,
+ onSendFile: () => filesSent++,
+ onSendLink: () => linksSent++,
+ );
+ await tester.tap(find.byType(FileShareButton));
+ await tester.pumpAndSettle();
+ expect(filesSent, 1);
+ expect(linksSent, 0);
+ expect(find.byKey(_dockKey), findsNothing);
+ });
+
+ testWidgets("long labels stack, wrap, and stay usable at large text in RTL", (
+ tester,
+ ) async {
+ var filesSent = 0;
+ var linksSent = 0;
+ await _pumpShareButton(
+ tester,
+ isVideo: true,
+ longLabels: true,
+ size: const Size(320, 568),
+ onSendFile: () => filesSent++,
+ onSendLink: () => linksSent++,
+ );
+ await tester.tap(find.byType(FileShareButton));
+ await tester.pumpAndSettle();
+ final wrappedFile = tester.getRect(find.byKey(_fileKey));
+ final wrappedLink = tester.getRect(find.byKey(_linkKey));
+ expect(wrappedFile.size, wrappedLink.size);
+ expect(wrappedFile.center.dy, wrappedLink.center.dy);
+ expect(wrappedFile.width, closeTo(320 * 0.35, 0.01));
+ expect(
+ tester.getSize(find.text(_LongStrings().sendVideo)).height,
+ greaterThan(20),
+ );
+ expect(tester.takeException(), isNull);
+ await tester.tapAt(const Offset(20, 20));
+ await tester.pumpAndSettle();
+ await _pumpShareButton(
+ tester,
+ isVideo: true,
+ longLabels: true,
+ textScale: 3,
+ direction: TextDirection.rtl,
+ size: const Size(320, 568),
+ onSendFile: () => filesSent++,
+ onSendLink: () => linksSent++,
+ );
+ final button = find.byType(FileShareButton);
+ await tester.tap(button);
+ await tester.pumpAndSettle();
+ final fileRect = tester.getRect(find.byKey(_fileKey));
+ final linkRect = tester.getRect(find.byKey(_linkKey));
+ expect(find.text(_LongStrings().sendVideo), findsOneWidget);
+ expect(linkRect.top, greaterThanOrEqualTo(fileRect.bottom));
+ final dockRect = tester.getRect(find.byKey(_dockKey));
+ expect(dockRect.left, greaterThanOrEqualTo(16));
+ expect(dockRect.right, lessThanOrEqualTo(304));
+ expect(dockRect.top, greaterThanOrEqualTo(12));
+ expect(dockRect.bottom, lessThan(tester.getRect(button).top));
+ expect(tester.takeException(), isNull);
+ await tester.scrollUntilVisible(
+ find.byKey(_linkKey),
+ 100,
+ scrollable: find.descendant(
+ of: find.byKey(_dockKey),
+ matching: find.byType(Scrollable),
+ ),
+ );
+ await tester.tap(find.text(_LongStrings().sendLink));
+ await tester.pumpAndSettle();
+ expect(linksSent, 1);
+ expect(filesSent, 0);
+ });
+}
diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
index 9c710fd00f..3536c9c4b8 100644
--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb
+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
@@ -3976,6 +3976,10 @@
"sendInvite": "Send invite",
"sendLink": "Send link",
"sendLogsDescription": "This will send across logs to help us debug your issue. While we take precautions to ensure that sensitive information is not logged, we encourage you to view these logs before sharing them.",
+ "sendPhoto": "Send photo",
+ "@sendPhoto": {
+ "description": "Share a copy of the current photo using the system share sheet, as opposed to sending a viewing link"
+ },
"sendQrCode": "Send QR code",
"sendToEmail": "Send to {email}",
"@sendToEmail": {
@@ -3986,6 +3990,10 @@
}
}
},
+ "sendVideo": "Send video",
+ "@sendVideo": {
+ "description": "Share a copy of the current video using the system share sheet, as opposed to sending a viewing link"
+ },
"serverEndpoint": "Server endpoint",
"@serverEndpoint": {
"description": "Label for server endpoint setting"