diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue26795.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue26795.cs new file mode 100644 index 000000000000..4249e1ff0273 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue26795.cs @@ -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, + }; + + var label = new Label + { + Text = "Test passes if no crash occurs", + AutomationId = "Label" + }; + + var scrollView = new ScrollView + { + IsVisible = false, + Content = webView + }; + layout.Children.Add(label); + layout.Children.Add(scrollView); + Content = layout; + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26795.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26795.cs new file mode 100644 index 000000000000..3cf5ae8f7fd6 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26795.cs @@ -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"); + } +} \ No newline at end of file diff --git a/src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs b/src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs index 7d7b83f0a58f..26b20f3bb324 100644 --- a/src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs +++ b/src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs @@ -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)) { @@ -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)) {