Skip to content
Closed
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
58 changes: 58 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue20042.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 20042, "[iOS] ScrollView HorizontalOptions=StartAndExpand does not expand to fill screen width in landscape", PlatformAffected.iOS)]
public class Issue20042 : ContentPage
{
public Issue20042()
{
var scrollView = new ScrollView
{
Orientation = ScrollOrientation.Vertical,
HorizontalOptions = LayoutOptions.StartAndExpand,
VerticalOptions = LayoutOptions.Fill,
};

var innerGrid = new Grid
{
BackgroundColor = Colors.LightBlue,
AutomationId = "InnerGrid",
};

var label = new Label
{
Text = "ScrollView with HorizontalOptions=StartAndExpand\nIn landscape, this blue area must fill the full screen width.",
HorizontalTextAlignment = TextAlignment.Center,
VerticalTextAlignment = TextAlignment.Center,
Margin = new Thickness(16),
};

innerGrid.Add(label);
scrollView.Content = innerGrid;

// A reference element that always fills the full page width — used to compare against InnerGrid.
var referenceBar = new BoxView
{
Color = Colors.Red,
HeightRequest = 4,
HorizontalOptions = LayoutOptions.Fill,
AutomationId = "ReferenceBar",
};

Content = new Grid
{
RowDefinitions = new RowDefinitionCollection
{
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Star },
},
Children =
{
referenceBar,
scrollView,
}
};

Grid.SetRow(referenceBar, 0);
Grid.SetRow(scrollView, 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#if IOS || ANDROID //SetOrientation is only supported on iOS and Android; orientation change is not available on Windows and MacCatalyst.

using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue20042 : _IssuesUITest
{
public Issue20042(TestDevice device) : base(device) { }

public override string Issue => "[iOS] ScrollView HorizontalOptions=StartAndExpand does not expand to fill screen width in landscape";

[Test]
[Category(UITestCategories.ScrollView)]
public void ScrollViewShouldFillScreenWidthInLandscape()
{
App.WaitForElement("InnerGrid");

var portraitGridRect = App.WaitForElement("InnerGrid").GetRect();
var portraitRefRect = App.WaitForElement("ReferenceBar").GetRect();

Assert.That(portraitGridRect.Width, Is.EqualTo(portraitRefRect.Width).Within(5),
$"Portrait: InnerGrid width ({portraitGridRect.Width}) should match full page width ({portraitRefRect.Width})");

try
{
App.SetOrientationLandscape();
App.WaitForElement("InnerGrid");

var landscapeGridRect = App.WaitForElement("InnerGrid").GetRect();
var landscapeRefRect = App.WaitForElement("ReferenceBar").GetRect();

Assert.That(landscapeGridRect.Width, Is.EqualTo(landscapeRefRect.Width).Within(5),
$"Landscape: InnerGrid width ({landscapeGridRect.Width}) should match full screen width ({landscapeRefRect.Width})");

Assert.That(landscapeGridRect.Width, Is.GreaterThan(portraitGridRect.Width),
"Landscape width should be greater than portrait width");
}
finally
{
App.SetOrientationPortrait();
}
}
}

#endif
11 changes: 11 additions & 0 deletions src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double he
var width = contentSize.Width <= widthConstraint ? contentSize.Width : widthConstraint;
var height = contentSize.Height <= heightConstraint ? contentSize.Height : heightConstraint;

// Expand the ScrollView to fill the available constraint if the content requests it (e.g., Fill alignment).
if (scrollView.PresentedContent is { } presentedContent)
{
var fillWidth = double.IsInfinity(widthConstraint) ? width : widthConstraint;
var fillHeight = double.IsInfinity(heightConstraint) ? height : heightConstraint;
var adjustedSize = new Size(width, height).AdjustForFill(
new Rect(0, 0, fillWidth, fillHeight), presentedContent);
width = adjustedSize.Width;
height = adjustedSize.Height;
}

width = ViewHandlerExtensions.ResolveConstraints(width, scrollView.Width, scrollView.MinimumWidth, scrollView.MaximumWidth);
height = ViewHandlerExtensions.ResolveConstraints(height, scrollView.Height, scrollView.MinimumHeight, scrollView.MaximumHeight);

Expand Down
Loading