Ver Fonte

[Photos] Fix auto scaling on loading final image (#749)

## Description

When an image is zoomed in, there were cases where when then final image
is loaded and rendered on screen, the image gets zoomed even more.

#### Case 1
Double tapping twice to zoom and then the final image is loaded.

##### Before


https://github.com/ente-io/ente/assets/77285023/7d9acb0f-2849-4ffb-863d-cab61ef4bd16

##### After


https://github.com/ente-io/ente/assets/77285023/89fb1238-1444-4681-a94f-7a58679f9350



#### Case 2
When screen is pressed or dragged (any contact with screen).

##### Before


https://github.com/ente-io/ente/assets/77285023/3aefdec5-3bc3-42ef-9442-592442273569

##### After


https://github.com/ente-io/ente/assets/77285023/7b458184-5abe-4983-ba21-f38080cc8bee

## Tests

Tested for regressions. Found one, which it not quite a regression as
the issue was already present but reproducible in a different flow. It
happens too fast for screen recording to capture it.

Not a blocker as it doesn't affect usability in anyway and since this
fix (auto scaling on final image loading) is an important fix.
Vishnu Mohandas há 1 ano atrás
pai
commit
c75e45897c
1 ficheiros alterados com 9 adições e 8 exclusões
  1. 9 8
      mobile/lib/ui/viewer/file/zoomable_image.dart

+ 9 - 8
mobile/lib/ui/viewer/file/zoomable_image.dart

@@ -41,8 +41,7 @@ class ZoomableImage extends StatefulWidget {
   State<ZoomableImage> createState() => _ZoomableImageState();
   State<ZoomableImage> createState() => _ZoomableImageState();
 }
 }
 
 
-class _ZoomableImageState extends State<ZoomableImage>
-    with SingleTickerProviderStateMixin {
+class _ZoomableImageState extends State<ZoomableImage> {
   late Logger _logger;
   late Logger _logger;
   late EnteFile _photo;
   late EnteFile _photo;
   ImageProvider? _imageProvider;
   ImageProvider? _imageProvider;
@@ -54,6 +53,7 @@ class _ZoomableImageState extends State<ZoomableImage>
   ValueChanged<PhotoViewScaleState>? _scaleStateChangedCallback;
   ValueChanged<PhotoViewScaleState>? _scaleStateChangedCallback;
   bool _isZooming = false;
   bool _isZooming = false;
   PhotoViewController _photoViewController = PhotoViewController();
   PhotoViewController _photoViewController = PhotoViewController();
+  final _scaleStateController = PhotoViewScaleStateController();
 
 
   @override
   @override
   void initState() {
   void initState() {
@@ -74,6 +74,7 @@ class _ZoomableImageState extends State<ZoomableImage>
   @override
   @override
   void dispose() {
   void dispose() {
     _photoViewController.dispose();
     _photoViewController.dispose();
+    _scaleStateController.dispose();
     super.dispose();
     super.dispose();
   }
   }
 
 
@@ -90,8 +91,10 @@ class _ZoomableImageState extends State<ZoomableImage>
       content = PhotoViewGestureDetectorScope(
       content = PhotoViewGestureDetectorScope(
         axis: Axis.vertical,
         axis: Axis.vertical,
         child: PhotoView(
         child: PhotoView(
+          key: ValueKey(_loadedFinalImage),
           imageProvider: _imageProvider,
           imageProvider: _imageProvider,
           controller: _photoViewController,
           controller: _photoViewController,
+          scaleStateController: _scaleStateController,
           scaleStateChangedCallback: _scaleStateChangedCallback,
           scaleStateChangedCallback: _scaleStateChangedCallback,
           minScale: widget.shouldCover
           minScale: widget.shouldCover
               ? PhotoViewComputedScale.covered
               ? PhotoViewComputedScale.covered
@@ -272,15 +275,13 @@ class _ZoomableImageState extends State<ZoomableImage>
       final scale = _photoViewController.scale! /
       final scale = _photoViewController.scale! /
           (finalImageInfo.image.width / prevImageInfo.image.width);
           (finalImageInfo.image.width / prevImageInfo.image.width);
       final currentPosition = _photoViewController.value.position;
       final currentPosition = _photoViewController.value.position;
-      final positionScaleFactor = 1 / scale;
-      final newPosition = currentPosition.scale(
-        positionScaleFactor,
-        positionScaleFactor,
-      );
       _photoViewController = PhotoViewController(
       _photoViewController = PhotoViewController(
-        initialPosition: newPosition,
+        initialPosition: currentPosition,
         initialScale: scale,
         initialScale: scale,
       );
       );
+      // Fix for auto-zooming when final image is loaded after double tapping
+      //twice.
+      _scaleStateController.scaleState = PhotoViewScaleState.zoomedIn;
     }
     }
     final bool canUpdateMetadata = _photo.canEditMetaInfo;
     final bool canUpdateMetadata = _photo.canEditMetaInfo;
     // forcefully get finalImageInfo is dimensions are not available in metadata
     // forcefully get finalImageInfo is dimensions are not available in metadata