From fcc5400e36c65f262fc5ba5bf847d3f97e06f035 Mon Sep 17 00:00:00 2001 From: "immich-push-o-matic[bot]" <179150890+immich-push-o-matic[bot]@users.noreply.github.com> Date: Fri, 2 Oct 2026 08:57:56 +0000 Subject: [PATCH] fix(mobile): image jumps when full-res image loads during pinch or zoom animation (#32011) fix(mobile): image jumps when full-res image loads during pinch or zoom animation (#31948) (cherry picked from commit 007c18aec6cc9552fb7d8b7c791c41d7424876b0) Co-authored-by: Luis Nachtigall <31982496+LeLunZ@users.noreply.github.com> --- .../photo_view/src/core/photo_view_core.dart | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/mobile/lib/widgets/photo_view/src/core/photo_view_core.dart b/mobile/lib/widgets/photo_view/src/core/photo_view_core.dart index 316d7c515..486c790d9 100644 --- a/mobile/lib/widgets/photo_view/src/core/photo_view_core.dart +++ b/mobile/lib/widgets/photo_view/src/core/photo_view_core.dart @@ -130,6 +130,7 @@ class PhotoViewCoreState extends State double? _rotationBefore; late final AnimationController _scaleAnimationController; + Tween? _scaleTween; Animation? _scaleAnimation; late final AnimationController _positionAnimationController; @@ -241,7 +242,8 @@ class PhotoViewCoreState extends State if (!mounted) { return Future.value(); } - _scaleAnimation = Tween(begin: from, end: to).animate(_scaleAnimationController); + _scaleTween = Tween(begin: from, end: to); + _scaleAnimation = _scaleTween!.animate(_scaleAnimationController); _scaleAnimationController.value = 0.0; return _scaleAnimationController.fling(velocity: 0.4); } @@ -301,7 +303,7 @@ class PhotoViewCoreState extends State controller.scaleAnimationBuilder(_animateControllerScale); controller.rotationAnimationBuilder(_animateControllerRotation); - _updateScaleBoundaries(); + _syncScaleBoundaries(); _scaleAnimationController = AnimationController(vsync: this) ..addListener(handleScaleAnimation) @@ -324,7 +326,7 @@ class PhotoViewCoreState extends State super.dispose(); } - void _updateScaleBoundaries() { + void _syncScaleBoundaries() { final prev = controller.scaleBoundaries; if (prev == widget.scaleBoundaries) { return; @@ -333,6 +335,16 @@ class PhotoViewCoreState extends State if (prev != null && controller.scale != null && prev.initialScale > 0) { final ratio = widget.scaleBoundaries.initialScale / prev.initialScale; controller.setScaleInvisibly(controller.scale! * ratio); + + if (_scaleBefore != null) { + _scaleBefore = _scaleBefore! * ratio; + } + + final tween = _scaleTween; + if (tween != null && _scaleAnimationController.isAnimating) { + tween.begin = tween.begin! * ratio; + tween.end = tween.end! * ratio; + } } else { markNeedsScaleRecalc = true; } @@ -342,7 +354,7 @@ class PhotoViewCoreState extends State @override void didUpdateWidget(PhotoViewCore oldWidget) { super.didUpdateWidget(oldWidget); - _updateScaleBoundaries(); + _syncScaleBoundaries(); } @override