π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Route still-photo long presses through image viewer
Neeraj Gupta8762bbf881d8
diff --git a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dartindex e93c3b8fea..5e223404da 100644--- a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart@@ -422,8 +422,6 @@ class _BodyState extends State<_Body> {},backgroundDecoration: const BoxDecoration(color: Colors.black),qrDetectionsNotifier: _qrHelper?.qrDetectionsNotifier,- );- return GestureDetector(onLongPressStart:flagService.ocrOverlayEnabled &&widget.config.mode != DetailPageMode.minimalistic &&@@ -431,6 +429,8 @@ class _BodyState extends State<_Body> {? (details) => _inlineTextDetectionController.startTextSelectionAt(details.globalPosition): null,+ );+ return GestureDetector(onTap: () {file.fileType != FileType.video? InheritedDetailPageState.of(context).toggleFullScreenByUser()diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/file_widget.dartindex c65cd97350..c528a8b23c 100644--- a/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart@@ -17,6 +17,7 @@ class FileWidget extends StatelessWidget {final bool? isFromMemories;final Function({required int memoryDuration})? onFinalFileLoad;final ValueNotifier<List<QrDetection>>? qrDetectionsNotifier;+ final GestureLongPressStartCallback? onLongPressStart;const FileWidget(this.file, {@@ -28,6 +29,7 @@ class FileWidget extends StatelessWidget {this.isFromMemories = false,this.onFinalFileLoad,this.qrDetectionsNotifier,+ this.onLongPressStart,super.key,});@@ -48,6 +50,7 @@ class FileWidget extends StatelessWidget {key: key ?? ValueKey(fileKey),onFinalFileLoad: onFinalFileLoad,qrDetectionsNotifier: qrDetectionsNotifier,+ onLongPressStart: onLongPressStart,);} else if (file.fileType == FileType.video) {// use old video widget on iOS simulator as the new one crashes whilediff --git a/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart b/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dartindex f939f3d098..29aa15459e 100644--- a/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart@@ -28,6 +28,7 @@ class ZoomableLiveImageNew extends StatefulWidget {final bool isFromMemories;final Function({required int memoryDuration})? onFinalFileLoad;final ValueNotifier<List<QrDetection>>? qrDetectionsNotifier;+ final GestureLongPressStartCallback? onLongPressStart;const ZoomableLiveImageNew(this.enteFile, {@@ -38,6 +39,7 @@ class ZoomableLiveImageNew extends StatefulWidget {this.isFromMemories = false,this.onFinalFileLoad,this.qrDetectionsNotifier,+ this.onLongPressStart,});@override@@ -182,10 +184,11 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>);if (!widget.isFromMemories) {- return GestureDetector(- onLongPressStart: (details) =>+ return buildLiveImageLongPressGesture(+ onTextSelectionStart: widget.onLongPressStart,+ onPlaybackStart: (details) =>_onLongPressEvent(true, details.localPosition),- onLongPressEnd: (_) => _onLongPressEvent(false),+ onPlaybackEnd: (_) => _onLongPressEvent(false),child: content,);}@@ -357,3 +360,16 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>});}}++GestureDetector buildLiveImageLongPressGesture({+ required Widget child,+ required GestureLongPressStartCallback onPlaybackStart,+ required GestureLongPressEndCallback onPlaybackEnd,+ GestureLongPressStartCallback? onTextSelectionStart,+}) {+ return GestureDetector(+ onLongPressStart: onTextSelectionStart ?? onPlaybackStart,+ onLongPressEnd: onTextSelectionStart == null ? onPlaybackEnd : null,+ child: child,+ );+}diff --git a/mobile/apps/photos/test/ui/viewer/file/zoomable_live_image_new_test.dart b/mobile/apps/photos/test/ui/viewer/file/zoomable_live_image_new_test.dartnew file mode 100644index 0000000000..829886b256--- /dev/null+++ b/mobile/apps/photos/test/ui/viewer/file/zoomable_live_image_new_test.dart@@ -0,0 +1,77 @@+import "package:flutter/material.dart";+import "package:flutter_test/flutter_test.dart";+import "package:mockito/mockito.dart";+import "package:photos/models/file/file.dart";+import "package:photos/models/file/file_type.dart";+import "package:photos/ui/viewer/file/file_widget.dart";+import "package:photos/ui/viewer/file/zoomable_live_image_new.dart";++void main() {+ test("FileWidget forwards still-photo long presses", () {+ final file = EnteFile()+ ..generatedID = 1+ ..fileType = FileType.image;+ void onLongPressStart(LongPressStartDetails _) {}++ final built = FileWidget(+ file,+ tagPrefix: "test",+ onLongPressStart: onLongPressStart,+ ).build(_MockBuildContext());++ expect(built, isA<ZoomableLiveImageNew>());+ expect(+ (built as ZoomableLiveImageNew).onLongPressStart,+ same(onLongPressStart),+ );+ });++ testWidgets("text selection owns the long press when provided", (+ tester,+ ) async {+ var textSelectionStarts = 0;+ var playbackStarts = 0;+ var playbackEnds = 0;++ await tester.pumpWidget(+ MaterialApp(+ home: buildLiveImageLongPressGesture(+ onTextSelectionStart: (_) => textSelectionStarts++,+ onPlaybackStart: (_) => playbackStarts++,+ onPlaybackEnd: (_) => playbackEnds++,+ child: const ColoredBox(key: Key("image"), color: Colors.black),+ ),+ ),+ );++ await tester.longPress(find.byKey(const Key("image")));++ expect(textSelectionStarts, 1);+ expect(playbackStarts, 0);+ expect(playbackEnds, 0);+ });++ testWidgets("live-photo playback keeps its long-press lifecycle", (+ tester,+ ) async {+ var playbackStarts = 0;+ var playbackEnds = 0;++ await tester.pumpWidget(+ MaterialApp(+ home: buildLiveImageLongPressGesture(+ onPlaybackStart: (_) => playbackStarts++,+ onPlaybackEnd: (_) => playbackEnds++,+ child: const ColoredBox(key: Key("image"), color: Colors.black),+ ),+ ),+ );++ await tester.longPress(find.byKey(const Key("image")));++ expect(playbackStarts, 1);+ expect(playbackEnds, 1);+ });+}++class _MockBuildContext extends Mock implements BuildContext {}