Skip to content

Commit

Permalink
Modify ScrollView to allow native measure in addition to content measure
Browse files Browse the repository at this point in the history
  • Loading branch information
hartez committed Jul 14, 2021
1 parent 568fdb6 commit 0772ebc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/Controls/src/Core/Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,14 @@ protected virtual void OnChildMeasureInvalidated()

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

protected override Size MeasureOverride(double widthConstraint, double heightConstraint)
=> (this as IFrameworkElement).Measure(widthConstraint, heightConstraint);
{
DesiredSize = OnMeasure(widthConstraint, heightConstraint).Request;
return DesiredSize;
}

protected override void OnSizeAllocated(double width, double height)
{
Expand Down
18 changes: 16 additions & 2 deletions src/Controls/src/Core/ScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ protected override SizeRequest OnSizeRequest(double widthConstraint, double heig

SizeRequest contentRequest;

if (Content is IFrameworkElement fe && fe.Handler != null)
if (Content is IFrameworkElement fe)
{
contentRequest = fe.Handler.GetDesiredSize(widthConstraint, heightConstraint);
contentRequest = fe.Measure(widthConstraint, heightConstraint);
}
else
{
Expand Down Expand Up @@ -362,5 +362,19 @@ void OnScrollToRequested(ScrollToRequestedEventArgs e)
CheckTaskCompletionSource();
ScrollToRequested?.Invoke(this, e);
}

protected override Size MeasureOverride(double widthConstraint, double heightConstraint)
{
// We call OnSizeRequest so that the content gets measured appropriately
// and then use the standard GetDesiredSize from the handler so the ScrollView's
// backing control gets measured.

// TODO ezhart 2021-07-14 Verify that we've got the naming correct on this after we resolve the OnSizeRequest obsolete stuff
#pragma warning disable CS0618 // Type or member is obsolete
_ = OnSizeRequest(widthConstraint, heightConstraint);
#pragma warning restore CS0618 // Type or member is obsolete

return Handler.GetDesiredSize(widthConstraint, heightConstraint);
}
}
}
8 changes: 0 additions & 8 deletions src/Core/src/Handlers/ScrollView/ScrollViewHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ protected override void ConnectHandler(ScrollViewer nativeView)
nativeView.ViewChanged += ViewChanged;
}

public override void NativeArrange(Rectangle rect)
{
// Re-measure the content too, otherwise winui will try and keep the scrollviewer' size >= the content size
NativeView?.Measure(new Windows.Foundation.Size(rect.Size.Width, rect.Size.Height));

base.NativeArrange(rect);
}

protected override void DisconnectHandler(ScrollViewer nativeView)
{
base.DisconnectHandler(nativeView);
Expand Down

0 comments on commit 0772ebc

Please sign in to comment.