Skip to content

High performance self-hosted photo and video management solution.

fix(mobile): preserve zoom level during image loading and live photo playback (#27960)

Luis Nachtigall790585363991
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 2f775f57e2..5009ee5333 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
@@ -139,8 +139,6 @@ class PhotoViewCoreState extends State<PhotoViewCore>
PhotoViewHeroAttributes? get heroAttributes => widget.heroAttributes;
- late ScaleBoundaries cachedScaleBoundaries = widget.scaleBoundaries;
-
void handleScaleAnimation() {
scale = _scaleAnimation!.value;
}
@@ -303,7 +301,7 @@ class PhotoViewCoreState extends State<PhotoViewCore>
controller.scaleAnimationBuilder(_animateControllerScale);
controller.rotationAnimationBuilder(_animateControllerRotation);
- cachedScaleBoundaries = widget.scaleBoundaries;
+ _updateScaleBoundaries();
_scaleAnimationController = AnimationController(vsync: this)
..addListener(handleScaleAnimation)
@@ -334,14 +332,27 @@ class PhotoViewCoreState extends State<PhotoViewCore>
widget.onTapDown?.call(context, details, controller.value);
}
- @override
- Widget build(BuildContext context) {
- // Check if we need a recalc on the scale
- if (widget.scaleBoundaries != cachedScaleBoundaries) {
+ void _updateScaleBoundaries() {
+ final prev = controller.scaleBoundaries;
+ if (prev == widget.scaleBoundaries) return;
+
+ if (prev != null && controller.scale != null && prev.initialScale > 0) {
+ final ratio = widget.scaleBoundaries.initialScale / prev.initialScale;
+ controller.setScaleInvisibly(controller.scale! * ratio);
+ } else {
markNeedsScaleRecalc = true;
- cachedScaleBoundaries = widget.scaleBoundaries;
}
+ controller.scaleBoundaries = widget.scaleBoundaries;
+ }
+ @override
+ void didUpdateWidget(PhotoViewCore oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ _updateScaleBoundaries();
+ }
+
+ @override
+ Widget build(BuildContext context) {
return StreamBuilder(
stream: controller.outputStateStream,
initialData: controller.prevValue,
diff --git a/mobile/lib/widgets/photo_view/src/photo_view_wrappers.dart b/mobile/lib/widgets/photo_view/src/photo_view_wrappers.dart
index d8d2ae7ee5..a9cfeb3a40 100644
--- a/mobile/lib/widgets/photo_view/src/photo_view_wrappers.dart
+++ b/mobile/lib/widgets/photo_view/src/photo_view_wrappers.dart
@@ -145,7 +145,6 @@ class _ImageWrapperState extends State<ImageWrapper> {
_lastStack = null;
_didLoadSynchronously = synchronousCall;
- widget.controller.scaleBoundaries = scaleBoundaries;
}
synchronousCall && !_didLoadSynchronously ? setupCB() : setState(setupCB);