Skip to content

Commit eaf4de2

Browse files
committed
Extracted UpdateImageLayout call from UpdateAspectRatio
1 parent b09ecc6 commit eaf4de2

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ private void ImageCanvas_SizeChanged(object sender, SizeChangedEventArgs e)
173173

174174
UpdateImageLayout();
175175
UpdateMaskArea();
176-
UpdateAspectRatio();
176+
177+
if (TryUpdateAspectRatio())
178+
{
179+
UpdateImageLayout();
180+
}
177181
}
178182
}
179183
}

Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@ private void InitImageLayout(bool animate = false)
3636
UpdateThumbsVisibility();
3737
}
3838

39-
private bool ShouldUpdateImageLayout => Source != null && IsValidRect(CanvasRect);
40-
4139
/// <summary>
4240
/// Update image source transform.
4341
/// </summary>
4442
/// <param name="animate">Whether animation is enabled.</param>
4543
private void UpdateImageLayout(bool animate = false)
4644
{
47-
if (ShouldUpdateImageLayout)
45+
if (Source != null && IsValidRect(CanvasRect))
4846
{
4947
var uniformSelectedRect = GetUniformRect(CanvasRect, _currentCroppedRect.Width / _currentCroppedRect.Height);
5048
UpdateImageLayoutWithViewport(uniformSelectedRect, _currentCroppedRect, animate);
@@ -506,16 +504,14 @@ private void UpdateMaskArea(bool animate = false)
506504
};
507505
}
508506

509-
private bool ShouldUpdateAspectRatio => KeepAspectRatio && Source != null && IsValidRect(_restrictedSelectRect);
510-
511507
/// <summary>
512508
/// Update image aspect ratio.
513509
/// </summary>
514-
private void UpdateAspectRatio(bool animate = false)
510+
private bool TryUpdateAspectRatio()
515511
{
516-
if (!ShouldUpdateAspectRatio)
512+
if (!(KeepAspectRatio && Source != null && IsValidRect(_restrictedSelectRect)))
517513
{
518-
return;
514+
return false;
519515
}
520516

521517
var center = SelectionAreaCenter;
@@ -542,7 +538,7 @@ private void UpdateAspectRatio(bool animate = false)
542538
{
543539
// Sentinal value. Equivelant to setting KeepAspectRatio to false. Causes AspectRatio to be recalculated.
544540
AspectRatio = -1;
545-
return;
541+
return false;
546542
}
547543
}
548544

@@ -573,7 +569,7 @@ private void UpdateAspectRatio(bool animate = false)
573569
croppedRect.Intersect(_restrictedCropRect);
574570
_currentCroppedRect = croppedRect;
575571

576-
UpdateImageLayout(animate);
572+
return true;
577573
}
578574

579575
/// <summary>

Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Properties.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ private static void OnAspectRatioChanged(
5151
DependencyObject d, DependencyPropertyChangedEventArgs e)
5252
{
5353
var target = (ImageCropper)d;
54-
target.UpdateAspectRatio(true);
54+
55+
if (target.TryUpdateAspectRatio())
56+
{
57+
target.UpdateImageLayout(true);
58+
}
5559
}
5660

5761
private static void OnCropShapeChanged(
@@ -60,7 +64,12 @@ private static void OnCropShapeChanged(
6064
var target = (ImageCropper)d;
6165
target.UpdateCropShape();
6266
target.UpdateThumbsVisibility();
63-
target.UpdateAspectRatio();
67+
68+
if (target.TryUpdateAspectRatio())
69+
{
70+
target.UpdateImageLayout();
71+
}
72+
6473
target.UpdateMaskArea();
6574
}
6675

0 commit comments

Comments
 (0)