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

[Issue(IssueTracker.Github, 26795, "Specifying HeightRequest in Webview when wrapped by ScrollView set invisible causes crash in iOS", PlatformAffected.iOS)]
public class Issue26795 : ContentPage
{
public Issue26795()
{
var layout = new VerticalStackLayout();

var webView = new WebView
{
Source = "https://en.m.wikipedia.org/wiki",
HeightRequest = 1000,
};
Comment on lines +10 to +14
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

Consider adding an AutomationId to the WebView to enable more comprehensive UI testing of the layout behavior:

var webView = new WebView
{
    Source = "https://en.m.wikipedia.org/wiki",
    HeightRequest = 1000,
    AutomationId = "TestWebView"
};

This would allow the test to verify that the WebView is properly sized and positioned, not just that the app doesn't crash.

Copilot uses AI. Check for mistakes.

var label = new Label
{
Text = "Test passes if no crash occurs",
AutomationId = "Label"
};

var scrollView = new ScrollView
{
IsVisible = false,
Content = webView
};
Comment on lines +22 to +26
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

Consider adding a button to toggle the ScrollView's visibility to enable more comprehensive testing:

var toggleButton = new Button
{
    Text = "Toggle Visibility",
    AutomationId = "ToggleVisibilityButton"
};
toggleButton.Clicked += (s, e) => scrollView.IsVisible = !scrollView.IsVisible;
layout.Children.Add(toggleButton);

This would allow the test to verify that the WebView layout works correctly both when initially invisible and when made visible.

Copilot uses AI. Check for mistakes.
layout.Children.Add(label);
layout.Children.Add(scrollView);
Content = layout;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;
public class Issue26795 : _IssuesUITest
{
public Issue26795(TestDevice device) : base(device) { }

public override string Issue => "Specifying HeightRequest in Webview when wrapped by ScrollView set invisible causes crash in iOS";

[Test]
[Category(UITestCategories.WebView)]
public void WebViewShouldNotCrashWithHeightRequest()
{
App.WaitForElement("Label");
}
Comment on lines +14 to +17
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The test only verifies that the app doesn't crash, but doesn't validate the actual layout behavior. Consider adding assertions to verify:

  1. The WebView renders with the correct dimensions when made visible
  2. The HeightRequest is respected
  3. The layout works correctly when the ScrollView's IsVisible property is toggled

Example:

App.Tap("ToggleVisibilityButton");
App.WaitForElement("WebViewId");
var webViewRect = App.FindElement("WebViewId").GetRect();
Assert.That(webViewRect.Height, Is.GreaterThan(0));

This would provide more comprehensive coverage of the layout fix beyond just crash prevention.

Copilot uses AI. Check for mistakes.
}
8 changes: 4 additions & 4 deletions src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ public override Size GetDesiredSize(double widthConstraint, double heightConstra

var set = false;

var width = widthConstraint;
var height = heightConstraint;
var width = size.Width;
var height = size.Height;

if (size.Width == 0)
if (width == 0)
{
if (widthConstraint <= 0 || double.IsInfinity(widthConstraint))
{
Expand All @@ -116,7 +116,7 @@ public override Size GetDesiredSize(double widthConstraint, double heightConstra
}
}

if (size.Height == 0)
if (height == 0)
{
if (heightConstraint <= 0 || double.IsInfinity(heightConstraint))
{
Expand Down
Loading