💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat(photos): refine memories viewer interactions
ashilknd61ce0361ade
diff --git a/mobile/apps/photos/changes/memory-viewer-interactions.md b/mobile/apps/photos/changes/memory-viewer-interactions.mdnew file mode 100644index 0000000000..01eb511c46--- /dev/null+++ b/mobile/apps/photos/changes/memory-viewer-interactions.md@@ -0,0 +1 @@+- Refined memory viewer controls, comments, and swipe-up file details.diff --git a/mobile/apps/photos/lib/ui/home/memories/custom_listener.dart b/mobile/apps/photos/lib/ui/home/memories/custom_listener.dartindex 72bbcf5a0e..2a055f54fb 100644--- a/mobile/apps/photos/lib/ui/home/memories/custom_listener.dart+++ b/mobile/apps/photos/lib/ui/home/memories/custom_listener.dart@@ -28,6 +28,8 @@ class ActivePointers with ChangeNotifier {class MemoriesPointerGestureListener extends StatefulWidget {final Widget child;final Function(PointerEvent)? onTap;+ final VoidCallback? onSwipeUp;+ final bool Function()? canSwipeUp;// final VoidCallback? onLongPress;// final VoidCallback? onLongPressUp;@@ -37,6 +39,9 @@ class MemoriesPointerGestureListener extends StatefulWidget {/// Maximum movement (in logical pixels) before we consider it a drag.final double touchSlop;+ /// Minimum upward displacement before a gesture opens file details.+ final double swipeUpThreshold;+/// Notifier that indicates whether there are active pointers.final ValueNotifier<bool>? hasPointerNotifier;static const double kTouchSlop = 18.0; // Default touch slop value@@ -45,11 +50,14 @@ class MemoriesPointerGestureListener extends StatefulWidget {super.key,required this.child,this.onTap,+ this.onSwipeUp,+ this.canSwipeUp,// this.onLongPress,// this.onLongPressUp,this.hasPointerNotifier,this.longPressDuration = const Duration(milliseconds: 500),this.touchSlop = kTouchSlop, // from flutter/gestures/constants.dart+ this.swipeUpThreshold = 48,});@override@@ -62,6 +70,7 @@ class MemoriesPointerGestureListenerStateTimer? _longPressTimer;bool _longPressFired = false;Offset? _downPosition;+ int? _trackedPointer;bool hasPointerMoved = false;final _activePointers = ActivePointers();@@ -79,6 +88,12 @@ class MemoriesPointerGestureListenerStatevoid _handlePointerDown(PointerDownEvent event) {_addPointer(event.pointer);+ if (_trackedPointer != null) {+ _longPressTimer?.cancel();+ _longPressTimer = null;+ return;+ }+ _trackedPointer = event.pointer;_downPosition = event.localPosition;_longPressFired = false;_longPressTimer?.cancel();@@ -89,34 +104,58 @@ class MemoriesPointerGestureListenerState}void _handlePointerMove(PointerMoveEvent event) {- if (_longPressTimer != null && _downPosition != null) {+ if (event.pointer == _trackedPointer && _downPosition != null) {final distance = (event.localPosition - _downPosition!).distance;if (distance > widget.touchSlop) {// user started dragging – cancel long‐presshasPointerMoved = true;- _longPressTimer!.cancel();+ _longPressTimer?.cancel();_longPressTimer = null;}}}void _handlePointerUp(PointerUpEvent event) {+ if (event.pointer != _trackedPointer) {+ _removePointer(event.pointer);+ return;+ }+_longPressTimer?.cancel();_longPressTimer = null;+ final wasPartOfMultitouch =+ _activePointers.activePointerWasPartOfMultitouch;+ final displacement = _downPosition == null+ ? Offset.zero+ : event.localPosition - _downPosition!;+ final isSwipeUp =+ widget.onSwipeUp != null &&+ (widget.canSwipeUp?.call() ?? true) &&+ !wasPartOfMultitouch &&+ displacement.dy <= -widget.swipeUpThreshold &&+ displacement.dy.abs() > displacement.dx.abs();++ // Release the pointer before callbacks so opening a sheet can take over+ // the viewer's pause state without the release immediately resuming it.+ _removePointer(event.pointer);if (_longPressFired) {// widget.onLongPressUp?.call();+ } else if (isSwipeUp) {+ widget.onSwipeUp?.call();} else {- if (!_activePointers.activePointerWasPartOfMultitouch &&- !hasPointerMoved) {+ if (!wasPartOfMultitouch && !hasPointerMoved) {widget.onTap?.call(event);}}- _removePointer(event.pointer);_reset();}void _handlePointerCancel(PointerCancelEvent event) {+ if (event.pointer != _trackedPointer) {+ _removePointer(event.pointer);+ return;+ }_longPressTimer?.cancel();_longPressTimer = null;_longPressFired = false;@@ -154,5 +193,7 @@ class MemoriesPointerGestureListenerStatevoid _reset() {hasPointerMoved = false;+ _downPosition = null;+ _trackedPointer = null;}}diff --git a/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart b/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dartindex 790f713be1..2efae00887 100644--- a/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart+++ b/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart@@ -4,7 +4,6 @@ import "dart:ui";import "package:connectivity_plus/connectivity_plus.dart";import "package:ente_components/theme/text_styles.dart" as component;-import "package:ente_icons/ente_icons.dart";import "package:ente_pure_utils/ente_pure_utils.dart";import "package:flutter/foundation.dart" show ValueListenable;import "package:flutter/material.dart";@@ -362,6 +361,7 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {// invalidates the prior delayed forward.Object? _kenBurnsStartToken;bool _isAnimationPaused = false;+ bool _isMediaZoomed = false;final _socialControlsVisible = ValueNotifier<bool>(false);/// Used to check if any pointer is on the screen.@@ -527,6 +527,7 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {void _goToNext(FullScreenMemoryData inheritedData) {if (inheritedData.memories.isEmpty) return;+ _isMediaZoomed = false;hasFinalFileLoaded = false;final currentIndex = _clampedMemoryIndex(inheritedData.indexNotifier.value,@@ -547,6 +548,7 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {void _goToPrevious(FullScreenMemoryData inheritedData) {if (inheritedData.memories.isEmpty) return;+ _isMediaZoomed = false;hasFinalFileLoaded = false;final currentIndex = _clampedMemoryIndex(inheritedData.indexNotifier.value,@@ -568,6 +570,7 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {void _onPageChange(FullScreenMemoryData inheritedData, int index) {if (!_isValidMemoryIndex(index, inheritedData.memories.length)) return;+ _isMediaZoomed = false;_setSocialControlsVisible(false);isAtFirstOrLastFile = false;unawaited(@@ -667,6 +670,15 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {_goToNext(inheritedData);}},+ onSwipeUp: () {+ if (!(ModalRoute.of(context)?.isCurrent ?? false)) return;+ unawaited(+ _runWithViewerPaused(+ () => showDetailsSheet(context, currentFile),+ ),+ );+ },+ canSwipeUp: () => !_isMediaZoomed,hasPointerNotifier: hasPointerOnScreenNotifier,child: AnimatedOpacity(opacity: _firstPhotoOpacity,@@ -701,6 +713,9 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {color: Colors.transparent,),isFromMemories: true,+ shouldDisableScroll: (isZoomed) {+ _isMediaZoomed = isZoomed;+ },playbackCallback: (shouldEnable, _) {_toggleAnimation(pause: !shouldEnable);},@@ -827,8 +842,8 @@ class BottomIcons extends StatelessWidget {if (currentFile.isUploaded && !isHidden)_MemoryActionButton(tooltip: l10n.addToAlbum,- icon: const Icon(- EnteIcons.addToAlbum,+ icon: const HugeIcon(+ icon: HugeIcons.strokeRoundedAddSquare,color: Colors.white,size: 24,),@@ -1006,7 +1021,7 @@ class _MemoryTopChrome extends StatelessWidget {dimension: 48,child: IconButton(tooltip: AppLocalizations.of(context).close,- padding: const EdgeInsets.all(15),+ padding: const EdgeInsets.all(8),style: IconButton.styleFrom(minimumSize: const Size.square(48),maximumSize: const Size.square(48),@@ -1016,10 +1031,10 @@ class _MemoryTopChrome extends StatelessWidget {),),onPressed: onClose,- icon: const Icon(- Icons.close,+ icon: const HugeIcon(+ icon: HugeIcons.strokeRoundedCancel01,color: Colors.white,- size: 18,+ size: 32,),),),@@ -1042,16 +1057,31 @@ class _MemoryTopChrome extends StatelessWidget {.copyWith(color: Colors.white),),),- Text(- SmartMemoriesService.getDateFormatted(- creationTime: currentFile.creationTime!,- context: context,- ),- maxLines: 1,- overflow: TextOverflow.ellipsis,- style: component.TextStyles.mini.copyWith(- color: Colors.white,- ),+ Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ Flexible(+ child: Text(+ SmartMemoriesService.getDateFormatted(+ creationTime:+ currentFile.creationTime!,+ context: context,+ ),+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: component.TextStyles.mini+ .copyWith(color: Colors.white),+ ),+ ),+ const SizedBox(width: 8),+ const SizedBox(+ width: 4,+ height: 8,+ child: CustomPaint(+ painter: _MemoryDateChevronPainter(),+ ),+ ),+ ],),],),@@ -1064,6 +1094,8 @@ class _MemoryTopChrome extends StatelessWidget {child: Center(child: FavoriteWidget(currentFile,+ iconSize: 24,+ tapTargetSize: 48,key: ValueKey(currentFile.uploadedFileID ??currentFile.localID,@@ -1085,6 +1117,28 @@ class _MemoryTopChrome extends StatelessWidget {}}+class _MemoryDateChevronPainter extends CustomPainter {+ const _MemoryDateChevronPainter();++ @override+ void paint(Canvas canvas, Size size) {+ final paint = Paint()+ ..color = Colors.white+ ..style = PaintingStyle.stroke+ ..strokeWidth = 1.25+ ..strokeCap = StrokeCap.round+ ..strokeJoin = StrokeJoin.round;+ final path = Path()+ ..moveTo(0.5, 0.5)+ ..lineTo(size.width - 0.5, size.height / 2)+ ..lineTo(0.5, size.height - 0.5);+ canvas.drawPath(path, paint);+ }++ @override+ bool shouldRepaint(covariant CustomPainter oldDelegate) => false;+}+class _MemoryViewerScrims extends StatelessWidget {final ValueListenable<bool> socialControlsVisible;diff --git a/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart b/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dartindex 26ec33ed5a..902a467284 100644--- a/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart+++ b/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart@@ -1,4 +1,5 @@import "dart:async";+import "dart:math" as math;import "package:collection/collection.dart";import "package:ente_components/theme/text_styles.dart" as component;@@ -26,6 +27,7 @@ final _logger = Logger("FileSocialOverlay");const _likedColor = Color(0xFF08C225);const _socialControlsSize = 40.0;+const _socialIconSize = 32.0;const _bottomActionBarHeight = 80.0;const _socialToActionBarGap = 14.0;@@ -366,7 +368,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {child: SizedBox.square(dimension: _socialControlsSize,child: IconButton(- padding: const EdgeInsets.all(8),+ padding: const EdgeInsets.all(4),style: IconButton.styleFrom(minimumSize: const Size.square(_socialControlsSize),maximumSize: const Size.square(_socialControlsSize),@@ -377,6 +379,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {icon: Icon(_hasLiked ? EnteIcons.likeFilled : EnteIcons.likeStroke,color: _hasLiked ? _likedColor : Colors.white,+ size: _socialIconSize,),),),@@ -388,7 +391,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {child: SizedBox.square(dimension: _socialControlsSize,child: IconButton(- padding: const EdgeInsets.all(8),+ padding: const EdgeInsets.all(4),style: IconButton.styleFrom(minimumSize: const Size.square(_socialControlsSize),maximumSize: const Size.square(_socialControlsSize),@@ -415,7 +418,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {onTap: () => unawaited(_openComments(comment: comment)),child: ConstrainedBox(constraints: BoxConstraints(- maxWidth: MediaQuery.sizeOf(context).width * 0.55,+ maxWidth: math.min(MediaQuery.sizeOf(context).width * 0.5, 200),),child: Stack(clipBehavior: Clip.none,@@ -446,12 +449,21 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {),),Positioned(- left: -10,- top: -10,- child: UserAvatarWidget(- author,- type: AvatarType.small,- currentUserID: currentUserID,+ left: -3,+ top: -6,+ child: Container(+ width: 22,+ height: 22,+ padding: const EdgeInsets.all(1),+ decoration: const BoxDecoration(+ color: Colors.white,+ shape: BoxShape.circle,+ ),+ child: UserAvatarWidget(+ author,+ type: AvatarType.small,+ currentUserID: currentUserID,+ ),),),],@@ -464,30 +476,33 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {return Stack(clipBehavior: Clip.none,children: [- const Icon(EnteIcons.commentBubbleStroke, color: Colors.white),+ const Icon(+ EnteIcons.commentBubbleStroke,+ color: Colors.white,+ size: _socialIconSize,+ ),if (_commentCount > 0)Positioned(- right: -4,- top: -4,+ right: -5,+ top: -5,child: Container(- padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 1),- decoration: BoxDecoration(+ constraints: const BoxConstraints(minWidth: 18, minHeight: 18),+ padding: const EdgeInsets.symmetric(horizontal: 6),+ decoration: const BoxDecoration(color: Colors.white,- borderRadius: const BorderRadius.all(Radius.circular(16)),- border: Border.all(- color: Colors.black,- width: 2,- strokeAlign: BorderSide.strokeAlignOutside,- ),+ borderRadius: BorderRadius.all(Radius.circular(19)),),- child: Text(- _commentCount > 99 ? "99+" : _commentCount.toString(),- style: const TextStyle(- color: Colors.black,- fontSize: 8,- fontWeight: FontWeight.w500,+ child: Center(+ child: Text(+ _commentCount > 99 ? "99+" : _commentCount.toString(),+ style: const TextStyle(+ color: Colors.black,+ fontSize: 10,+ height: 1.2,+ fontWeight: FontWeight.w700,+ ),+ textAlign: TextAlign.center,),- textAlign: TextAlign.center,),),),diff --git a/mobile/apps/photos/lib/ui/viewer/file_details/favorite_widget.dart b/mobile/apps/photos/lib/ui/viewer/file_details/favorite_widget.dartindex 124f1a8c36..947e1ab072 100644--- a/mobile/apps/photos/lib/ui/viewer/file_details/favorite_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/file_details/favorite_widget.dart@@ -11,8 +11,15 @@ import "package:rive/rive.dart" as rive;class FavoriteWidget extends StatefulWidget {final EnteFile file;+ final double? iconSize;+ final double? tapTargetSize;- const FavoriteWidget(this.file, {super.key});+ const FavoriteWidget(+ this.file, {+ this.iconSize,+ this.tapTargetSize,+ super.key,+ });@overrideState<StatefulWidget> createState() => _FavoriteWidgetState();@@ -165,35 +172,47 @@ class _FavoriteWidgetState extends State<FavoriteWidget> {Widget build(BuildContext context) {// Show blank while initial state is being fetchedif (_isFavorite == null || _isLoading) {- return const SizedBox(width: 22, height: 22);+ final placeholderSize = widget.tapTargetSize ?? 22;+ return SizedBox.square(dimension: placeholderSize);}+ final riveWidget = rive.RiveWidgetBuilder(+ fileLoader: _riveFileLoader,+ stateMachineSelector: const rive.StateMachineNamed("State Machine 1"),+ onLoaded: _handleRiveLoaded,+ builder: (BuildContext context, rive.RiveState state) {+ if (state is rive.RiveLoaded) {+ return rive.RiveWidget(+ controller: state.controller,+ fit: rive.Fit.contain,+ );+ }+ if (state is rive.RiveFailed) {+ _logger.warning("Failed to load Rive file: ${state.error}");+ }+ return const SizedBox.shrink();+ },+ );+return GestureDetector(onTap: _onTap,behavior: HitTestBehavior.opaque,- child: Container(- padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 4),- width: 34,- height: 30,- child: rive.RiveWidgetBuilder(- fileLoader: _riveFileLoader,- stateMachineSelector: const rive.StateMachineNamed("State Machine 1"),- onLoaded: _handleRiveLoaded,- builder: (BuildContext context, rive.RiveState state) {- if (state is rive.RiveLoaded) {- return rive.RiveWidget(- controller: state.controller,- fit: rive.Fit.contain,- );- }- if (state is rive.RiveFailed) {- _logger.warning("Failed to load Rive file: ${state.error}");- }- // Loading state- return const SizedBox.shrink();- },- ),- ),+ child: widget.iconSize != null || widget.tapTargetSize != null+ ? SizedBox.square(+ dimension: widget.tapTargetSize ?? widget.iconSize!,+ child: Center(+ child: SizedBox.square(+ dimension: widget.iconSize ?? widget.tapTargetSize!,+ child: riveWidget,+ ),+ ),+ )+ : Container(+ padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 4),+ width: 34,+ height: 30,+ child: riveWidget,+ ),);}}diff --git a/mobile/apps/photos/test/ui/home/memories/custom_listener_test.dart b/mobile/apps/photos/test/ui/home/memories/custom_listener_test.dartnew file mode 100644index 0000000000..15654bb11f--- /dev/null+++ b/mobile/apps/photos/test/ui/home/memories/custom_listener_test.dart@@ -0,0 +1,68 @@+import "package:flutter/widgets.dart";+import "package:flutter_test/flutter_test.dart";+import "package:photos/ui/home/memories/custom_listener.dart";++void main() {+ const targetKey = ValueKey("gesture-target");++ Future<void> pumpListener(+ WidgetTester tester, {+ required VoidCallback onSwipeUp,+ bool Function()? canSwipeUp,+ }) async {+ await tester.pumpWidget(+ Directionality(+ textDirection: TextDirection.ltr,+ child: Center(+ child: SizedBox.square(+ dimension: 200,+ child: MemoriesPointerGestureListener(+ onSwipeUp: onSwipeUp,+ canSwipeUp: canSwipeUp,+ child: const ColoredBox(key: targetKey, color: Color(0xFF000000)),+ ),+ ),+ ),+ ),+ );+ }++ testWidgets("opens details after an upward-dominant swipe", (tester) async {+ var swipeCount = 0;+ await pumpListener(tester, onSwipeUp: () => swipeCount++);++ await tester.drag(find.byKey(targetKey), const Offset(10, -60));++ expect(swipeCount, 1);+ });++ testWidgets("does not open details while media is zoomed", (tester) async {+ var swipeCount = 0;+ await pumpListener(+ tester,+ onSwipeUp: () => swipeCount++,+ canSwipeUp: () => false,+ );++ await tester.drag(find.byKey(targetKey), const Offset(0, -60));++ expect(swipeCount, 0);+ });++ testWidgets("disqualifies the full gesture after multitouch", (tester) async {+ var swipeCount = 0;+ await pumpListener(tester, onSwipeUp: () => swipeCount++);+ final center = tester.getCenter(find.byKey(targetKey));+ final firstPointer = await tester.startGesture(center, pointer: 1);+ final secondPointer = await tester.startGesture(+ center + const Offset(10, 0),+ pointer: 2,+ );++ await secondPointer.up();+ await firstPointer.moveBy(const Offset(0, -60));+ await firstPointer.up();++ expect(swipeCount, 0);+ });+}