diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue30515.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue30515.cs new file mode 100644 index 000000000000..1bbf8a89421e --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue30515.cs @@ -0,0 +1,135 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 30515, "[iOS] WebView.Reload() with HtmlWebViewSource returns WebNavigationResult.Failure in Navigated event", PlatformAffected.iOS)] +public class Issue30515 : ContentPage +{ + WebView webView; + Label statusTextLabel; + Label statusValueLabel; + + public Issue30515() + { + Title = "Issue 30515"; + + // Create the navigation status labels - split into static text and dynamic value + statusTextLabel = new Label + { + Text = "Status:", + FontSize = 14, + TextColor = Colors.Gray, + VerticalOptions = LayoutOptions.Center + }; + + statusValueLabel = new Label + { + Text = "Ready", + AutomationId = "NavigationStatusLabel", + FontSize = 14, + TextColor = Colors.Blue, + VerticalOptions = LayoutOptions.Center + }; + + // Create a horizontal stack for the status display + var statusContainer = new StackLayout + { + Orientation = StackOrientation.Horizontal, + Spacing = 5, + HorizontalOptions = LayoutOptions.Center, + Children = { statusTextLabel, statusValueLabel } + }; + + // Create the WebView + webView = new WebView + { + HeightRequest = 300, + WidthRequest = 400, + Source = new HtmlWebViewSource + { + Html = @" + + + HTML WebView Source + + +

WebView Feature Matrix

+

This page demonstrates various capabilities of the .NET MAUI WebView control, such as:

+ +

Test Content

+

+ This is a longer body paragraph to help test the EvaluateJavaScript functionality + and how it extracts body text. You can use this text to verify substring operations and test scrolling + or formatting in the WebView. + +

+

+ Try interacting with navigation buttons, loading multiple pages, or checking cookie behavior. +

+ +

Navigation Test Links

+

Click these links to test URL navigation:

+ + + + + " + } + }; + + // Set up event handlers + webView.Navigated += OnWebViewNavigated; + + // Create the reload button + var reloadButton = new Button + { + Text = "Reload", + AutomationId = "ReloadButton", + HorizontalOptions = LayoutOptions.Center + }; + reloadButton.Clicked += OnReloadClicked; + + // Add all elements to the page + Content = new StackLayout + { + Padding = new Thickness(10), + Spacing = 10, + Children = + { + statusContainer, + webView, + new StackLayout + { + Orientation = StackOrientation.Horizontal, + Spacing = 10, + HorizontalOptions = LayoutOptions.Center, + Children = + { + reloadButton + } + } + } + }; + } + + void OnReloadClicked(object sender, EventArgs e) + { + statusValueLabel.Text = "Reloading..."; + webView.Reload(); + } + + void OnWebViewNavigated(object sender, WebNavigatedEventArgs e) + { + statusValueLabel.Text = e.Result.ToString(); + statusValueLabel.TextColor = Colors.Green; + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30515.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30515.cs new file mode 100644 index 000000000000..44d90073c08f --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30515.cs @@ -0,0 +1,23 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue30515 : _IssuesUITest +{ + public override string Issue => "[iOS] WebView.Reload() with HtmlWebViewSource returns WebNavigationResult.Failure in Navigated event"; + + public Issue30515(TestDevice device) + : base(device) + { } + + [Test] + [Category(UITestCategories.WebView)] + public void VerifyWebViewHTMLSourceReloadStatus() + { + App.WaitForElement("NavigationStatusLabel"); + App.Tap("ReloadButton"); + Assert.That(App.FindElement("NavigationStatusLabel").GetText(), Is.EqualTo("Success")); + } +} \ No newline at end of file diff --git a/src/Core/src/Platform/iOS/WebViewExtensions.cs b/src/Core/src/Platform/iOS/WebViewExtensions.cs index 7f4a5c748bb1..3236c0dc3185 100644 --- a/src/Core/src/Platform/iOS/WebViewExtensions.cs +++ b/src/Core/src/Platform/iOS/WebViewExtensions.cs @@ -56,7 +56,32 @@ public static void UpdateGoForward(this WKWebView platformWebView, IWebView webV public static void UpdateReload(this WKWebView platformWebView, IWebView webView) { - platformWebView?.Reload(); + if (platformWebView == null) + { + return; + } + + // Check if we have a source and platformWebView implements IWebViewDelegate + if (webView.Source != null && platformWebView is IWebViewDelegate webViewDelegate) + { + // If the source is an HTML source, we need to reload from the source + // since WKWebView.Reload() doesn't work properly with LoadHtmlString + var sourceType = webView.Source.GetType().Name; + if (string.Equals(sourceType, "HtmlWebViewSource", StringComparison.Ordinal)) + { + // For HTML sources, always reload from the source + webView.Source.Load(webViewDelegate); + } + else + { + // For URL sources, use the standard reload + platformWebView.Reload(); + } + } + else + { + platformWebView.Reload(); + } } internal static void UpdateCanGoBackForward(this WKWebView platformWebView, IWebView webView)