Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mobile][photos] Cover gallery hero handoff regressions

r4khul5b510bfa0d64
diff --git a/mobile/apps/photos/test/ui/viewer/file/image_zoom/image_zoom_viewer_test.dart b/mobile/apps/photos/test/ui/viewer/file/image_zoom/image_zoom_viewer_test.dart
index 0f39311865..26a1050144 100644
--- a/mobile/apps/photos/test/ui/viewer/file/image_zoom/image_zoom_viewer_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/file/image_zoom/image_zoom_viewer_test.dart
@@ -1,3 +1,4 @@
+import "dart:async";
import "dart:math" as math;
import "dart:ui" as ui;
@@ -6,6 +7,8 @@ import "package:flutter/gestures.dart";
import "package:flutter/material.dart";
import "package:flutter/rendering.dart";
import "package:flutter_test/flutter_test.dart";
+import "package:photos/ui/viewer/file/gallery_photo_page_route.dart";
+import "package:photos/ui/viewer/file/hero_image.dart";
import "package:photos/ui/viewer/file/image_zoom/image_zoom_viewer.dart";
const _viewportSize = Size(400, 400);
@@ -55,6 +58,214 @@ void main() {
expect(readyCount, 1);
});
+ for (final decodeDuringFlight in [true, false]) {
+ testWidgets(
+ "a scrolled photo stays visible (early decode: $decodeDuringFlight)",
+ (tester) async {
+ final delayedImage = _DelayedImageProvider();
+ ImageProvider? imageProvider;
+ late StateSetter updateViewer;
+ await tester.pumpWidget(
+ MaterialApp(
+ home: ListView(
+ children: [
+ const SizedBox(height: 400),
+ Align(
+ alignment: Alignment.topLeft,
+ child: Hero(
+ tag: "photo",
+ createRectTween: imageHeroRectTween,
+ flightShuttleBuilder: imageHeroFlightShuttleBuilder,
+ child: Image(
+ image: _DeterministicImageProvider(largerLandscapeImage),
+ width: 160,
+ height: 100,
+ fit: BoxFit.cover,
+ ),
+ ),
+ ),
+ const SizedBox(height: 1000),
+ ],
+ ),
+ ),
+ );
+ await tester.pump();
+ await tester.drag(find.byType(ListView), const Offset(0, -300));
+ await tester.pump();
+ final sourceRect = tester.getRect(find.byType(Hero));
+ final navigator = Navigator.of(tester.element(find.byType(Hero)));
+ navigator.push(
+ GalleryPhotoPageRoute<void>(
+ tag: "photo",
+ sourceImage: largerLandscapeImage,
+ page: StatefulBuilder(
+ builder: (context, setState) {
+ updateViewer = setState;
+ return ImageZoomViewer(
+ imageProvider: imageProvider,
+ heroTag: "photo",
+ loadingBuilder: _emptyLoadingBuilder,
+ );
+ },
+ ),
+ ),
+ );
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 40));
+ final viewer = find.byType(ImageZoomViewer);
+ final viewerHero = find.descendant(
+ of: viewer,
+ matching: find.byType(Hero),
+ );
+ final heroState = tester.state(viewerHero);
+ final destinationRect = tester.getRect(viewerHero);
+ final sourceImage = ImageHeroSource.maybeOf(
+ tester.element(viewer),
+ "photo",
+ )!.image!;
+ final flightImage = tester
+ .widget<RawImage>(find.byType(RawImage))
+ .image!;
+ expect(destinationRect.size.aspectRatio, closeTo(1.5, 0.0001));
+ expect(flightImage.isCloneOf(largerLandscapeImage), isTrue);
+ expect(tester.getRect(find.byType(HeroFlightImage)), isNot(sourceRect));
+ expect(
+ tester.getRect(find.byType(HeroFlightImage)),
+ isNot(destinationRect),
+ );
+
+ updateViewer(() => imageProvider = delayedImage);
+ await tester.pump();
+ if (decodeDuringFlight) {
+ delayedImage.complete(landscapeImage);
+ await tester.pump(const Duration(milliseconds: 20));
+ expect(tester.state(viewerHero), same(heroState));
+ expect(tester.getRect(viewerHero), destinationRect);
+ expect(
+ find.descendant(of: viewer, matching: find.byType(Image)),
+ findsNothing,
+ );
+ expect(
+ tester.widget<RawImage>(find.byType(RawImage)).image,
+ same(flightImage),
+ );
+ }
+ await tester.pumpAndSettle();
+ if (!decodeDuringFlight) {
+ delayedImage.fail();
+ await tester.pump();
+ expect(
+ tester.widget<RawImage>(find.byType(RawImage)).image,
+ same(sourceImage),
+ );
+ updateViewer(
+ () => imageProvider = _DeterministicImageProvider(landscapeImage),
+ );
+ await tester.pumpAndSettle();
+ }
+ expect(tester.state(viewerHero), same(heroState));
+ expect(find.byType(Image), findsOneWidget);
+ navigator.pop();
+ await tester.pumpAndSettle();
+ expect(flightImage.debugDisposed, isTrue);
+ expect(sourceImage.debugDisposed, isTrue);
+ expect(largerLandscapeImage.debugDisposed, isFalse);
+ expect(tester.takeException(), isNull);
+ },
+ );
+ }
+
+ testWidgets(
+ "a cold flight keeps its thumbnail mounted without duplicating it",
+ (tester) async {
+ final thumbnailKey = GlobalKey();
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Hero(
+ tag: "cold-photo",
+ placeholderBuilder: imageHeroPlaceholderBuilder,
+ flightShuttleBuilder: imageHeroFlightShuttleBuilder,
+ child: SizedBox(key: thumbnailKey, width: 160, height: 100),
+ ),
+ ),
+ );
+ final thumbnailElement = thumbnailKey.currentContext;
+ final navigator = Navigator.of(tester.element(find.byType(Hero)));
+ navigator.push(
+ GalleryPhotoPageRoute<void>(
+ tag: "cold-photo",
+ page: const Hero(
+ tag: "cold-photo",
+ flightShuttleBuilder: imageHeroFlightShuttleBuilder,
+ child: SizedBox(width: 400, height: 250),
+ ),
+ ),
+ );
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 100));
+ expect(find.byType(HeroFlightImage), findsOneWidget);
+ expect(thumbnailKey.currentContext, same(thumbnailElement));
+ expect(find.byKey(thumbnailKey, skipOffstage: false), findsOneWidget);
+ await tester.pumpAndSettle();
+ navigator.pop();
+ await tester.pumpAndSettle();
+ expect(thumbnailKey.currentContext, same(thumbnailElement));
+ expect(tester.takeException(), isNull);
+ },
+ );
+
+ for (final galleryRoute in [false, true]) {
+ testWidgets("scopes the loading Hero to gallery routes: $galleryRoute", (
+ tester,
+ ) async {
+ final delayedImage = _DelayedImageProvider();
+ Widget viewer = ImageZoomViewer(
+ imageProvider: delayedImage,
+ heroTag: "photo",
+ loadingBuilder: (_, _) => const Text("Loading photo"),
+ );
+ if (galleryRoute) {
+ viewer = ImageHeroSource(
+ tag: "another-photo",
+ image: largerLandscapeImage,
+ child: viewer,
+ );
+ }
+ await tester.pumpWidget(MaterialApp(home: viewer));
+ expect(find.text("Loading photo"), findsOneWidget);
+ expect(find.byType(Hero), galleryRoute ? findsOneWidget : findsNothing);
+ expect(find.byType(RawImage), findsNothing);
+ delayedImage.complete(landscapeImage);
+ await tester.pumpAndSettle();
+ final hero = tester.widget<Hero>(find.byType(Hero));
+ expect(hero.flightShuttleBuilder, isNull);
+ expect(hero.createRectTween, isNull);
+ expect(find.byType(Image), findsOneWidget);
+ expect(tester.takeException(), isNull);
+ });
+ }
+
+ testWidgets("shows the photo without a Hero when motion is disabled", (
+ tester,
+ ) async {
+ await tester.pumpWidget(
+ MaterialApp(
+ builder: (context, child) => MediaQuery(
+ data: MediaQuery.of(context).copyWith(disableAnimations: true),
+ child: child!,
+ ),
+ home: ImageZoomViewer(
+ imageProvider: _DeterministicImageProvider(landscapeImage),
+ heroTag: "photo",
+ ),
+ ),
+ );
+ await tester.pump();
+ expect(find.byType(Hero), findsNothing);
+ expect(find.byType(Image), findsOneWidget);
+ expect(tester.takeException(), isNull);
+ });
+
group("double-tap focal zoom", () {
testWidgets("centers the tapped horizontal area", (tester) async {
final harness = await _pumpViewer(tester, image: landscapeImage);
@@ -805,6 +1016,25 @@ Future<Color> _centerPixel(Finder boundaryFinder) async {
return color;
}
+class _DelayedImageProvider extends ImageProvider<_DelayedImageProvider> {
+ final _frame = Completer<ImageInfo>();
+
+ void complete(ui.Image image) =>
+ _frame.complete(ImageInfo(image: image.clone()));
+
+ void fail() => _frame.completeError(StateError("Decode failed"));
+
+ @override
+ Future<_DelayedImageProvider> obtainKey(ImageConfiguration configuration) =>
+ SynchronousFuture(this);
+
+ @override
+ ImageStreamCompleter loadImage(
+ _DelayedImageProvider key,
+ ImageDecoderCallback decode,
+ ) => OneFrameImageStreamCompleter(_frame.future);
+}
+
class _DeterministicImageProvider
extends ImageProvider<_DeterministicImageProvider> {
const _DeterministicImageProvider(this.image);
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/component/gallery_file_widget_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/component/gallery_file_widget_test.dart
index 247073ee82..a7b04971b2 100644
--- a/mobile/apps/photos/test/ui/viewer/gallery/component/gallery_file_widget_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/gallery/component/gallery_file_widget_test.dart
@@ -10,6 +10,9 @@ import "package:photos/models/file/file.dart";
import "package:photos/models/file/file_type.dart";
import "package:photos/models/selected_files.dart";
import "package:photos/service_locator.dart";
+import "package:photos/ui/viewer/file/gallery_photo_page_route.dart";
+import "package:photos/ui/viewer/file/hero_image.dart";
+import "package:photos/ui/viewer/file/image_zoom/image_zoom_viewer.dart";
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
import "package:photos/ui/viewer/gallery/component/gallery_file_widget.dart";
import "package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart";
@@ -74,10 +77,10 @@ const _tinyImage = <int>[
0x00,
0x01,
0xff,
- 0x89,
- 0x99,
- 0xd1,
- 0x8d,
+ 0x72,
+ 0x9c,
+ 0x52,
+ 0x67,
0x00,
0x00,
0x00,
@@ -265,6 +268,84 @@ void main() {
await tester.pump(const Duration(milliseconds: 100));
});
+ testWidgets(
+ "a justified thumbnail keeps its decoded image through the return hero",
+ (tester) async {
+ final file = EnteFile()
+ ..generatedID = 3
+ ..localID = "hero-photo"
+ ..fileType = FileType.image
+ ..title = "hero-photo.jpg";
+ final bytes = Uint8List.fromList(_tinyImage);
+ ThumbnailInMemoryLruCache.put(file, bytes, thumbnailLargeSize);
+ addTearDown(() => ThumbnailInMemoryLruCache.clearCache(file));
+ await tester.pumpWidget(
+ MaterialApp(
+ home: GalleryContextState(
+ sortOrderAsc: false,
+ child: Align(
+ alignment: Alignment.topLeft,
+ child: SizedBox(
+ width: 200,
+ height: 120,
+ child: GalleryFileWidget(
+ file: file,
+ selectedFiles: null,
+ limitSelectionToOne: true,
+ tag: "gallery_",
+ photoGridSize: photoGridSizeDefault,
+ thumbnailSize: thumbnailLargeSize,
+ currentUserID: null,
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.runAsync(() async {
+ await precacheImage(
+ MemoryImage(bytes),
+ tester.element(find.byType(GalleryFileWidget)),
+ );
+ });
+ await tester.pump();
+ final thumbnail = find.byType(ThumbnailWidget, skipOffstage: false);
+ final thumbnailState = tester.state<State<ThumbnailWidget>>(thumbnail);
+ final hero = find.byType(Hero);
+ final tag = tester.widget<Hero>(hero).tag;
+ final sourceImage = imageFromHero(tester.element(hero));
+ expect(sourceImage, isNotNull);
+ final navigator = Navigator.of(tester.element(hero));
+ navigator.push(
+ GalleryPhotoPageRoute<void>(
+ tag: tag,
+ sourceImage: sourceImage,
+ page: ImageZoomViewer(
+ imageProvider: MemoryImage(bytes),
+ heroTag: tag,
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ expect(tester.state(thumbnail), same(thumbnailState));
+ ThumbnailInMemoryLruCache.clearCache(file);
+ PaintingBinding.instance.imageCache.clear();
+
+ navigator.pop();
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 100));
+ expect(tester.state(thumbnail), same(thumbnailState));
+ expect(imageFromHero(thumbnailState.context), isNotNull);
+ await tester.pump(const Duration(milliseconds: 110));
+ expect(tester.state(thumbnail), same(thumbnailState));
+ expect(imageFromHero(thumbnailState.context), isNotNull);
+ expect(tester.takeException(), isNull);
+
+ await tester.pumpWidget(const SizedBox.shrink());
+ await tester.pump(const Duration(milliseconds: 100));
+ },
+ );
+
testWidgets(
"a requested large justified thumbnail bypasses the cached small tier",
(tester) async {