diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyWebViewStaysWithinGridCell.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyWebViewStaysWithinGridCell.png new file mode 100644 index 000000000000..f571a46b76af Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyWebViewStaysWithinGridCell.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue32030.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue32030.cs new file mode 100644 index 000000000000..95871be305c8 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue32030.cs @@ -0,0 +1,58 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 32030, "Android - WebView in a grid expands beyond it's cell", PlatformAffected.Android)] + +public class Issue32030 : ContentPage +{ + WebView webView; + + public Issue32030() + { + // Create Grid + var grid = new Grid + { + RowDefinitions = new RowDefinitionCollection + { + new RowDefinition { Height = new GridLength(50) }, + new RowDefinition { Height = GridLength.Star }, + new RowDefinition { Height = new GridLength(50) } + } + }; + + // Create "above webview" Label + var topLabel = new Label + { + Text = "Above webview", + AutomationId = "TopLabel", + HorizontalTextAlignment = TextAlignment.Center + }; + grid.Add(topLabel); + Grid.SetRow(topLabel, 0); + + // Create WebView + webView = new WebView + { + BackgroundColor = Colors.BurlyWood + }; + webView.Navigated += WebView_Navigated; + grid.Add(webView); + Grid.SetRow(webView, 1); + + // Create "below webview" Label + var bottomLabel = new Label + { + Text = "Below webview", + HorizontalTextAlignment = TextAlignment.Center + }; + grid.Add(bottomLabel); + Grid.SetRow(bottomLabel, 2); + + // Set the grid as the page content + Content = grid; + } + + async void WebView_Navigated(object sender, WebNavigatedEventArgs e) + { + await DisplayAlert("Navigation Completed", $"WebView navigated to: {e.Url}", "OK"); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyWebViewStaysWithinGridCell.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyWebViewStaysWithinGridCell.png new file mode 100644 index 000000000000..c98f1bf24f98 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyWebViewStaysWithinGridCell.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32030.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32030.cs new file mode 100644 index 000000000000..ac92609d4c32 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32030.cs @@ -0,0 +1,18 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; +public class Issue32030 : _IssuesUITest +{ + public Issue32030(TestDevice device) : base(device) { } + + public override string Issue => "Android - WebView in a grid expands beyond it's cell"; + [Test] + [Category(UITestCategories.WebView)] + public void VerifyWebViewStaysWithinGridCell() + { + App.WaitForElement("TopLabel"); + VerifyScreenshot(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyWebViewStaysWithinGridCell.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyWebViewStaysWithinGridCell.png new file mode 100644 index 000000000000..5004b8655603 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyWebViewStaysWithinGridCell.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyWebViewStaysWithinGridCell.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyWebViewStaysWithinGridCell.png new file mode 100644 index 000000000000..1f365554b56b Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyWebViewStaysWithinGridCell.png differ diff --git a/src/Core/src/Platform/Android/MauiWebViewClient.cs b/src/Core/src/Platform/Android/MauiWebViewClient.cs index ee6eb9f021e6..428aaa656642 100644 --- a/src/Core/src/Platform/Android/MauiWebViewClient.cs +++ b/src/Core/src/Platform/Android/MauiWebViewClient.cs @@ -57,7 +57,7 @@ public override void OnPageFinished(WebView? view, string? url) bool navigate = _navigationResult != WebNavigationResult.Failure || !GetValidUrl(url).Equals(_lastUrlNavigatedCancel, StringComparison.OrdinalIgnoreCase); _lastUrlNavigatedCancel = _navigationResult == WebNavigationResult.Cancel ? url : null; - if (navigate) + if (navigate && !IsBlankNavigation(url)) handler.VirtualView.Navigated(handler.CurrentNavigationEvent, GetValidUrl(url), _navigationResult); handler.SyncPlatformCookiesToVirtualView(url); @@ -96,6 +96,15 @@ public override bool OnRenderProcessGone(WebView? view, RenderProcessGoneDetail? bool NavigatingCanceled(string? url) => !_handler.TryGetTarget(out var handler) || handler.NavigatingCanceled(url); + static bool IsBlankNavigation(string? url) + { + if (string.IsNullOrWhiteSpace(url)) + return false; + + // Check if URL is about:blank (case insensitive) + return string.Equals(url.Trim(), "about:blank", StringComparison.OrdinalIgnoreCase); + } + static string GetValidUrl(string? url) { if (string.IsNullOrEmpty(url)) diff --git a/src/Core/src/Platform/Android/WebViewExtensions.cs b/src/Core/src/Platform/Android/WebViewExtensions.cs index 7ab41a2789c4..4ac8840b7c8f 100644 --- a/src/Core/src/Platform/Android/WebViewExtensions.cs +++ b/src/Core/src/Platform/Android/WebViewExtensions.cs @@ -25,6 +25,10 @@ public static void UpdateSource(this AWebView platformWebView, IWebView webView, platformWebView.UpdateCanGoBackForward(webView); } } + else + { + platformWebView.LoadUrl("about:blank"); + } } public static void UpdateSettings(this AWebView platformWebView, IWebView webView, bool javaScriptEnabled, bool domStorageEnabled)