Skip to content

Commit

Permalink
Handle setting of DesiredSize in Measure implementations, rather than…
Browse files Browse the repository at this point in the history
… MeasureOverride (#19794)
  • Loading branch information
hartez committed Jan 10, 2024
1 parent c0f42f9 commit 3f99858
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/Controls/src/Core/ContentPage/ContentPage.cs
Expand Up @@ -70,8 +70,7 @@ internal override void OnControlTemplateChanged(ControlTemplate oldValue, Contro

protected override Size MeasureOverride(double widthConstraint, double heightConstraint)
{
DesiredSize = this.ComputeDesiredSize(widthConstraint, heightConstraint);
return DesiredSize;
return this.ComputeDesiredSize(widthConstraint, heightConstraint);
}

protected override Size ArrangeOverride(Rect bounds)
Expand Down
3 changes: 1 addition & 2 deletions src/Controls/src/Core/ContentPresenter.cs
Expand Up @@ -102,8 +102,7 @@ static async void OnContentChanged(BindableObject bindable, object oldValue, obj

protected override Size MeasureOverride(double widthConstraint, double heightConstraint)
{
DesiredSize = this.ComputeDesiredSize(widthConstraint, heightConstraint);
return DesiredSize;
return this.ComputeDesiredSize(widthConstraint, heightConstraint);
}

Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint)
Expand Down
6 changes: 3 additions & 3 deletions src/Controls/src/Core/Layout.cs
Expand Up @@ -236,14 +236,14 @@ protected virtual void OnChildMeasureInvalidated()

Size IView.Measure(double widthConstraint, double heightConstraint)
{
return MeasureOverride(widthConstraint, heightConstraint);
DesiredSize = MeasureOverride(widthConstraint, heightConstraint);
return DesiredSize;
}

protected override Size MeasureOverride(double widthConstraint, double heightConstraint)
{
var sansMargins = OnMeasure(widthConstraint, heightConstraint).Request;
DesiredSize = new Size(sansMargins.Width + Margin.HorizontalThickness, sansMargins.Height + Margin.VerticalThickness);
return DesiredSize;
return new Size(sansMargins.Width + Margin.HorizontalThickness, sansMargins.Height + Margin.VerticalThickness);
}

protected override void OnSizeAllocated(double width, double height)
Expand Down
3 changes: 1 addition & 2 deletions src/Controls/src/Core/ScrollView/ScrollView.cs
Expand Up @@ -441,8 +441,7 @@ void IScrollView.RequestScrollTo(double horizontalOffset, double verticalOffset,

protected override Size MeasureOverride(double widthConstraint, double heightConstraint)
{
DesiredSize = this.ComputeDesiredSize(widthConstraint, heightConstraint);
return DesiredSize;
return this.ComputeDesiredSize(widthConstraint, heightConstraint);
}

Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint)
Expand Down
1 change: 0 additions & 1 deletion src/Controls/src/Core/Shapes/Shape.cs
Expand Up @@ -430,7 +430,6 @@ protected override Size MeasureOverride(double widthConstraint, double heightCon
result.Height += StrokeThickness;
result.Width += StrokeThickness;

DesiredSize = result;
return result;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Controls/src/Core/TemplatedView/TemplatedView.cs
Expand Up @@ -120,8 +120,7 @@ public virtual ControlTemplate ResolveControlTemplate()

protected override Size MeasureOverride(double widthConstraint, double heightConstraint)
{
DesiredSize = this.ComputeDesiredSize(widthConstraint, heightConstraint);
return DesiredSize;
return this.ComputeDesiredSize(widthConstraint, heightConstraint);
}

Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint)
Expand Down
6 changes: 3 additions & 3 deletions src/Controls/src/Core/VisualElement/VisualElement.cs
Expand Up @@ -1847,7 +1847,8 @@ void IView.InvalidateArrange()
/// <inheritdoc/>
Size IView.Measure(double widthConstraint, double heightConstraint)
{
return MeasureOverride(widthConstraint, heightConstraint);
DesiredSize = MeasureOverride(widthConstraint, heightConstraint);
return DesiredSize;
}

/// <summary>
Expand All @@ -1859,8 +1860,7 @@ Size IView.Measure(double widthConstraint, double heightConstraint)
/// <returns>The requested size that an element wants in order to be displayed on the device.</returns>
protected virtual Size MeasureOverride(double widthConstraint, double heightConstraint)
{
DesiredSize = this.ComputeDesiredSize(widthConstraint, heightConstraint);
return DesiredSize;
return this.ComputeDesiredSize(widthConstraint, heightConstraint);
}

/// <inheritdoc/>
Expand Down

0 comments on commit 3f99858

Please sign in to comment.