mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
fix(mobile): keep zoom consistent when scale boundaries change
This commit is contained in:
@@ -139,8 +139,6 @@ class PhotoViewCoreState extends State<PhotoViewCore>
|
|||||||
|
|
||||||
PhotoViewHeroAttributes? get heroAttributes => widget.heroAttributes;
|
PhotoViewHeroAttributes? get heroAttributes => widget.heroAttributes;
|
||||||
|
|
||||||
late ScaleBoundaries cachedScaleBoundaries = widget.scaleBoundaries;
|
|
||||||
|
|
||||||
void handleScaleAnimation() {
|
void handleScaleAnimation() {
|
||||||
scale = _scaleAnimation!.value;
|
scale = _scaleAnimation!.value;
|
||||||
}
|
}
|
||||||
@@ -303,7 +301,12 @@ class PhotoViewCoreState extends State<PhotoViewCore>
|
|||||||
controller.scaleAnimationBuilder(_animateControllerScale);
|
controller.scaleAnimationBuilder(_animateControllerScale);
|
||||||
controller.rotationAnimationBuilder(_animateControllerRotation);
|
controller.rotationAnimationBuilder(_animateControllerRotation);
|
||||||
|
|
||||||
cachedScaleBoundaries = widget.scaleBoundaries;
|
final prevBoundaries = controller.scaleBoundaries;
|
||||||
|
if (prevBoundaries != null && prevBoundaries != widget.scaleBoundaries) {
|
||||||
|
_updateScaleBoundaries(prevBoundaries);
|
||||||
|
} else {
|
||||||
|
controller.scaleBoundaries = widget.scaleBoundaries;
|
||||||
|
}
|
||||||
|
|
||||||
_scaleAnimationController = AnimationController(vsync: this)
|
_scaleAnimationController = AnimationController(vsync: this)
|
||||||
..addListener(handleScaleAnimation)
|
..addListener(handleScaleAnimation)
|
||||||
@@ -334,14 +337,26 @@ class PhotoViewCoreState extends State<PhotoViewCore>
|
|||||||
widget.onTapDown?.call(context, details, controller.value);
|
widget.onTapDown?.call(context, details, controller.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _updateScaleBoundaries(ScaleBoundaries prev) {
|
||||||
|
if (controller.scale != null && prev.initialScale > 0) {
|
||||||
|
final ratio = widget.scaleBoundaries.initialScale / prev.initialScale;
|
||||||
|
controller.setScaleInvisibly(controller.scale! * ratio);
|
||||||
|
} else {
|
||||||
|
markNeedsScaleRecalc = true;
|
||||||
|
}
|
||||||
|
controller.scaleBoundaries = widget.scaleBoundaries;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(PhotoViewCore oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
if (widget.scaleBoundaries != oldWidget.scaleBoundaries) {
|
||||||
|
_updateScaleBoundaries(oldWidget.scaleBoundaries);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Check if we need a recalc on the scale
|
|
||||||
if (widget.scaleBoundaries != cachedScaleBoundaries) {
|
|
||||||
markNeedsScaleRecalc = true;
|
|
||||||
cachedScaleBoundaries = widget.scaleBoundaries;
|
|
||||||
}
|
|
||||||
|
|
||||||
return StreamBuilder(
|
return StreamBuilder(
|
||||||
stream: controller.outputStateStream,
|
stream: controller.outputStateStream,
|
||||||
initialData: controller.prevValue,
|
initialData: controller.prevValue,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:immich_mobile/utils/debug_print.dart';
|
|
||||||
import 'package:immich_mobile/widgets/photo_view/photo_view.dart';
|
import 'package:immich_mobile/widgets/photo_view/photo_view.dart';
|
||||||
import 'package:immich_mobile/widgets/photo_view/src/core/photo_view_core.dart';
|
import 'package:immich_mobile/widgets/photo_view/src/core/photo_view_core.dart';
|
||||||
import 'package:immich_mobile/widgets/photo_view/src/photo_view_default_widgets.dart';
|
import 'package:immich_mobile/widgets/photo_view/src/photo_view_default_widgets.dart';
|
||||||
|
|||||||
Reference in New Issue
Block a user