Skip to content

Commit

Permalink
Address PR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jknaudt21 committed Sep 19, 2023
1 parent af3dd89 commit 4172d78
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,26 @@ public async Task DoesNotGrow()
Assert.True(parentLayout.Height < 500, "ScrollView should not make parent layout grow!");
}

[Fact (DisplayName = "ScrollView's viewport fills available space if set to fill")]
public async Task ShouldGrow()
{
var label = new Label() { Text = "Text inside a ScrollView" };
var childLayout = new VerticalStackLayout { label };
var scrollView = new ScrollView() { VerticalOptions = LayoutOptions.Fill, Content = childLayout};
var parentLayout = new Grid { scrollView };
parentLayout.HeightRequest = 500;

await CreateHandlerAsync<LabelHandler>(label);
await CreateHandlerAsync<LayoutHandler>(childLayout);
await CreateHandlerAsync<ScrollViewHandler>(scrollView);
var layoutHandler = await CreateHandlerAsync<LayoutHandler>(parentLayout);

await AttachAndRun(parentLayout, (layoutHandler) => { });
Assert.True(parentLayout.Height == 500, "Parent be 500px tall");
Assert.True(scrollView.Height == 500, "ScrollView should fill parent layout" );
Assert.True(childLayout.Height == 500, "Child VerticalStackLayout should fill available space");
}

void SetupBuilder()
{
EnsureHandlerCreated(builder =>
Expand Down
6 changes: 3 additions & 3 deletions src/Core/src/Handlers/ScrollView/ScrollViewHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override Size GetDesiredSize(double widthConstraint, double heightConstra

// If the ScrollView is inside of a layout it shouldn't have to fill all the space it can
// See: https://github.com/dotnet/maui/issues/16464
if (platformView.FillViewport && virtualView.Parent?.Handler is not ILayoutHandler)
if (platformView.FillViewport)
{
/* With FillViewport active, the Android ScrollView will measure the content at least once; if it is
smaller than the ScrollView's viewport, it measure a second time at the size of the viewport
Expand All @@ -63,12 +63,12 @@ public override Size GetDesiredSize(double widthConstraint, double heightConstra

var orientation = virtualView.Orientation;

if (orientation == ScrollOrientation.Both || orientation == ScrollOrientation.Vertical)
if (!double.IsInfinity(heightConstraint) && (orientation == ScrollOrientation.Both || orientation == ScrollOrientation.Vertical))
{
heightSpec = AdjustSpecForAlignment(heightSpec, virtualView.VerticalLayoutAlignment);
}

if (orientation == ScrollOrientation.Both || orientation == ScrollOrientation.Horizontal)
if (!double.IsInfinity(widthConstraint) && (orientation == ScrollOrientation.Both || orientation == ScrollOrientation.Horizontal))
{
widthSpec = AdjustSpecForAlignment(widthSpec, virtualView.HorizontalLayoutAlignment);
}
Expand Down

0 comments on commit 4172d78

Please sign in to comment.