Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Controls/src/Core/ScrollView/ScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,8 @@ Size ICrossPlatformLayout.CrossPlatformArrange(Rect bounds)
return bounds.Size;
}

Size IContentView.CrossPlatformMeasure(double widthConstraint, double heightConstraint) => ((ICrossPlatformLayout)this).CrossPlatformMeasure(widthConstraint, heightConstraint);
Size IContentView.CrossPlatformMeasure(double widthConstraint, double heightConstraint) =>
((ICrossPlatformLayout)this).CrossPlatformMeasure(widthConstraint, heightConstraint);

Size IContentView.CrossPlatformArrange(Rect bounds) =>
((ICrossPlatformLayout)this).CrossPlatformArrange(bounds);
Expand Down
31 changes: 13 additions & 18 deletions src/Core/src/Handlers/ScrollView/ScrollViewHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ protected override void ConnectHandler(MauiScrollView platformView)
{
base.ConnectHandler(platformView);
platformView.ScrollChange += ScrollChange;
platformView.CrossPlatformArrange = VirtualView.CrossPlatformArrange;
}

protected override void DisconnectHandler(MauiScrollView platformView)
{
base.DisconnectHandler(platformView);
platformView.ScrollChange -= ScrollChange;
platformView.CrossPlatformArrange = null;
}

public override Size GetDesiredSize(double widthConstraint, double heightConstraint)
Expand Down Expand Up @@ -234,7 +232,10 @@ static void InsertInsetView(IScrollViewHandler handler, IScrollView scrollView,

Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint)
{
var scrollView = VirtualView;
if (VirtualView is not { } scrollView)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fires before we set a VirtualView?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we can definitely remove this check

Let's see if it passes tests and if so I'll remove

{
return Size.Zero;
}

var padding = scrollView.Padding;

Expand All @@ -243,31 +244,25 @@ Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double he
return new Size(padding.HorizontalThickness, padding.VerticalThickness);
}

// Exclude the padding while measuring the internal content ...
var measurementWidth = widthConstraint - padding.HorizontalThickness;
var measurementHeight = heightConstraint - padding.VerticalThickness;

var result = (scrollView as ICrossPlatformLayout).CrossPlatformMeasure(measurementWidth, measurementHeight);

// ... and add the padding back in to the final result
var fullSize = new Size(result.Width + padding.HorizontalThickness, result.Height + padding.VerticalThickness);
var scrollOrientation = scrollView.Orientation;
var contentWidthConstraint = scrollOrientation is ScrollOrientation.Horizontal or ScrollOrientation.Both ? double.PositiveInfinity : widthConstraint;
var contentHeightConstraint = scrollOrientation is ScrollOrientation.Vertical or ScrollOrientation.Both ? double.PositiveInfinity : heightConstraint;
var contentSize = scrollView.MeasureContent(scrollView.Padding, contentWidthConstraint, contentHeightConstraint, !double.IsInfinity(contentWidthConstraint), !double.IsInfinity(contentHeightConstraint));

if (double.IsInfinity(widthConstraint))
{
widthConstraint = result.Width;
widthConstraint = contentSize.Width;
}

if (double.IsInfinity(heightConstraint))
{
heightConstraint = result.Height;
heightConstraint = contentSize.Height;
}

return fullSize.AdjustForFill(new Rect(0, 0, widthConstraint, heightConstraint), scrollView.PresentedContent);
return contentSize.AdjustForFill(new Rect(0, 0, widthConstraint, heightConstraint), scrollView.PresentedContent);
}

Size ICrossPlatformLayout.CrossPlatformArrange(Rect bounds)
{
return (VirtualView as ICrossPlatformLayout).CrossPlatformArrange(bounds);
}
Size ICrossPlatformLayout.CrossPlatformArrange(Rect bounds) =>
(VirtualView as ICrossPlatformLayout)?.CrossPlatformArrange(bounds) ?? Size.Zero;
}
}
31 changes: 31 additions & 0 deletions src/Core/src/Layouts/LayoutExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,37 @@ public static Size MeasureContent(this IContentView contentView, Thickness inset
return new Size(contentSize.Width + inset.HorizontalThickness, contentSize.Height + inset.VerticalThickness);
}

internal static Size MeasureContent(
this IContentView contentView,
Thickness inset,
double widthConstraint,
double heightConstraint,
bool constrainPresentedContentWidthToExplicitDimsOnContentView,
bool constrainPresentedContentHeightToExplicitDimsOnContentView)
{
var content = contentView.PresentedContent;

if (Dimension.IsExplicitSet(contentView.Width) && constrainPresentedContentWidthToExplicitDimsOnContentView)
{
widthConstraint = contentView.Width;
}

if (Dimension.IsExplicitSet(contentView.Height) && constrainPresentedContentHeightToExplicitDimsOnContentView)
{
heightConstraint = contentView.Height;
}

var contentSize = Size.Zero;

if (content != null)
{
contentSize = content.Measure(widthConstraint - inset.HorizontalThickness,
heightConstraint - inset.VerticalThickness);
}

return new Size(contentSize.Width + inset.HorizontalThickness, contentSize.Height + inset.VerticalThickness);
}

public static void ArrangeContent(this IContentView contentView, Rect bounds)
{
if (contentView.PresentedContent == null)
Expand Down
17 changes: 5 additions & 12 deletions src/Core/src/Platform/Android/MauiScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ public void SetOrientation(ScrollOrientation orientation)
{
if (_hScrollView == null)
{
_hScrollView = new MauiHorizontalScrollView(Context, this);
_hScrollView = new MauiHorizontalScrollView(Context, this)
{
FillViewport = true
};

_hScrollView.HorizontalFadingEdgeEnabled = HorizontalFadingEdgeEnabled;
_hScrollView.SetFadingEdgeLength(HorizontalFadingEdgeLength);
SetHorizontalScrollBarVisibility(_horizontalScrollVisibility);
Expand Down Expand Up @@ -229,15 +233,6 @@ protected override void OnLayout(bool changed, int left, int top, int right, int
hScrollViewHeight = _isBidirectional ? Math.Max(hScrollViewHeight, scrollViewContentHeight) : hScrollViewHeight;
_hScrollView.Layout(0, 0, hScrollViewWidth, hScrollViewHeight);
}

if (CrossPlatformArrange == null)
{
return;
}

var destination = Context!.ToCrossPlatformRectInReferenceFrame(left, top, right, bottom);

CrossPlatformArrange(destination);
}

public void ScrollTo(int x, int y, bool instant, Action finished)
Expand Down Expand Up @@ -321,8 +316,6 @@ void IOnScrollChangeListener.OnScrollChange(NestedScrollView? v, int scrollX, in
{
OnScrollChanged(scrollX, scrollY, oldScrollX, oldScrollY);
}

internal Func<Graphics.Rect, Graphics.Size>? CrossPlatformArrange { get; set; }
}

internal class MauiHorizontalScrollView : HorizontalScrollView, IScrollBarView
Expand Down
Loading