mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
update animation methods to return futures
This commit is contained in:
@@ -38,12 +38,13 @@ abstract class PhotoViewControllerBase<T extends PhotoViewControllerValue> {
|
||||
/// Closes streams and removes eventual listeners.
|
||||
void dispose();
|
||||
|
||||
void positionAnimationBuilder(void Function(Offset)? value);
|
||||
void scaleAnimationBuilder(void Function(double)? value);
|
||||
void rotationAnimationBuilder(void Function(double)? value);
|
||||
void positionAnimationBuilder(Future<void> Function(Offset)? value);
|
||||
void scaleAnimationBuilder(Future<void> Function(double)? value);
|
||||
void rotationAnimationBuilder(Future<void> Function(double)? value);
|
||||
|
||||
/// Animates multiple fields of the state
|
||||
void animateMultiple({Offset? position, double? scale, double? rotation});
|
||||
/// Animates multiple fields of the state. The returned future completes
|
||||
/// when all underlying animations have settled.
|
||||
Future<void> animateMultiple({Offset? position, double? scale, double? rotation});
|
||||
|
||||
/// Add a listener that will ignore updates made internally
|
||||
///
|
||||
@@ -148,9 +149,9 @@ class PhotoViewController implements PhotoViewControllerBase<PhotoViewController
|
||||
@override
|
||||
ScaleBoundaries? scaleBoundaries;
|
||||
|
||||
late void Function(Offset)? _animatePosition;
|
||||
late void Function(double)? _animateScale;
|
||||
late void Function(double)? _animateRotation;
|
||||
late Future<void> Function(Offset)? _animatePosition;
|
||||
late Future<void> Function(double)? _animateScale;
|
||||
late Future<void> Function(double)? _animateRotation;
|
||||
|
||||
@override
|
||||
Stream<PhotoViewControllerValue> get outputStateStream => _outputCtrl.stream;
|
||||
@@ -159,17 +160,17 @@ class PhotoViewController implements PhotoViewControllerBase<PhotoViewController
|
||||
late PhotoViewControllerValue prevValue;
|
||||
|
||||
@override
|
||||
void positionAnimationBuilder(void Function(Offset)? value) {
|
||||
void positionAnimationBuilder(Future<void> Function(Offset)? value) {
|
||||
_animatePosition = value;
|
||||
}
|
||||
|
||||
@override
|
||||
void scaleAnimationBuilder(void Function(double)? value) {
|
||||
void scaleAnimationBuilder(Future<void> Function(double)? value) {
|
||||
_animateScale = value;
|
||||
}
|
||||
|
||||
@override
|
||||
void rotationAnimationBuilder(void Function(double)? value) {
|
||||
void rotationAnimationBuilder(Future<void> Function(double)? value) {
|
||||
_animateRotation = value;
|
||||
}
|
||||
|
||||
@@ -193,18 +194,18 @@ class PhotoViewController implements PhotoViewControllerBase<PhotoViewController
|
||||
}
|
||||
|
||||
@override
|
||||
void animateMultiple({Offset? position, double? scale, double? rotation}) {
|
||||
Future<void> animateMultiple({Offset? position, double? scale, double? rotation}) {
|
||||
final futures = <Future<void>>[];
|
||||
if (position != null && _animatePosition != null) {
|
||||
_animatePosition!(position);
|
||||
futures.add(_animatePosition!(position));
|
||||
}
|
||||
|
||||
if (scale != null && _animateScale != null) {
|
||||
_animateScale!(scale);
|
||||
futures.add(_animateScale!(scale));
|
||||
}
|
||||
|
||||
if (rotation != null && _animateRotation != null) {
|
||||
_animateRotation!(rotation);
|
||||
futures.add(_animateRotation!(rotation));
|
||||
}
|
||||
return Future.wait(futures);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -237,34 +237,31 @@ class PhotoViewCoreState extends State<PhotoViewCore>
|
||||
nextScaleState();
|
||||
}
|
||||
|
||||
void animateScale(double from, double to) {
|
||||
Future<void> animateScale(double from, double to) {
|
||||
if (!mounted) {
|
||||
return;
|
||||
return Future.value();
|
||||
}
|
||||
_scaleAnimation = Tween<double>(begin: from, end: to).animate(_scaleAnimationController);
|
||||
_scaleAnimationController
|
||||
..value = 0.0
|
||||
..fling(velocity: 0.4);
|
||||
_scaleAnimationController.value = 0.0;
|
||||
return _scaleAnimationController.fling(velocity: 0.4);
|
||||
}
|
||||
|
||||
void animatePosition(Offset from, Offset to) {
|
||||
Future<void> animatePosition(Offset from, Offset to) {
|
||||
if (!mounted) {
|
||||
return;
|
||||
return Future.value();
|
||||
}
|
||||
_positionAnimation = Tween<Offset>(begin: from, end: to).animate(_positionAnimationController);
|
||||
_positionAnimationController
|
||||
..value = 0.0
|
||||
..fling(velocity: 0.4);
|
||||
_positionAnimationController.value = 0.0;
|
||||
return _positionAnimationController.fling(velocity: 0.4);
|
||||
}
|
||||
|
||||
void animateRotation(double from, double to) {
|
||||
Future<void> animateRotation(double from, double to) {
|
||||
if (!mounted) {
|
||||
return;
|
||||
return Future.value();
|
||||
}
|
||||
_rotationAnimation = Tween<double>(begin: from, end: to).animate(_rotationAnimationController);
|
||||
_rotationAnimationController
|
||||
..value = 0.0
|
||||
..fling(velocity: 0.4);
|
||||
_rotationAnimationController.value = 0.0;
|
||||
return _rotationAnimationController.fling(velocity: 0.4);
|
||||
}
|
||||
|
||||
void onAnimationStatus(AnimationStatus status) {
|
||||
@@ -280,18 +277,19 @@ class PhotoViewCoreState extends State<PhotoViewCore>
|
||||
}
|
||||
}
|
||||
|
||||
void _animateControllerPosition(Offset position) {
|
||||
animatePosition(controller.position, position);
|
||||
Future<void> _animateControllerPosition(Offset position) {
|
||||
return animatePosition(controller.position, position);
|
||||
}
|
||||
|
||||
void _animateControllerScale(double scale) {
|
||||
Future<void> _animateControllerScale(double scale) {
|
||||
if (controller.scale != null) {
|
||||
animateScale(controller.scale!, scale);
|
||||
return animateScale(controller.scale!, scale);
|
||||
}
|
||||
return Future.value();
|
||||
}
|
||||
|
||||
void _animateControllerRotation(double rotation) {
|
||||
animateRotation(controller.rotation, rotation);
|
||||
Future<void> _animateControllerRotation(double rotation) {
|
||||
return animateRotation(controller.rotation, rotation);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user