diff --git a/Xamarin.Forms.Platform.Android/Renderers/FormsWebViewClient.cs b/Xamarin.Forms.Platform.Android/Renderers/FormsWebViewClient.cs index 9d979a8a8..6c4fb96af 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/FormsWebViewClient.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/FormsWebViewClient.cs @@ -69,7 +69,7 @@ namespace Xamarin.Forms.Platform.Android if (navigate) { - var args = new WebNavigatedEventArgs(WebNavigationEvent.NewPage, source, url, _navigationResult); + var args = new WebNavigatedEventArgs(_renderer.GetCurrentWebNavigationEvent(), source, url, _navigationResult); _renderer.ElementController.SendNavigated(args); } diff --git a/Xamarin.Forms.Platform.Android/Renderers/WebViewRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/WebViewRenderer.cs index e53bf2f05..5ade20268 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/WebViewRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/WebViewRenderer.cs @@ -15,6 +15,7 @@ namespace Xamarin.Forms.Platform.Android { public const string AssetBaseUrl = "file:///android_asset/"; + WebNavigationEvent _eventState; WebViewClient _webViewClient; FormsWebChromeClient _webChromeClient; bool _isDisposed = false; @@ -36,13 +37,17 @@ namespace Xamarin.Forms.Platform.Android public void LoadHtml(string html, string baseUrl) { + _eventState = WebNavigationEvent.NewPage; Control.LoadDataWithBaseURL(baseUrl ?? AssetBaseUrl, html, "text/html", "UTF-8", null); } public void LoadUrl(string url) { if (!SendNavigatingCanceled(url)) + { + _eventState = WebNavigationEvent.NewPage; Control.LoadUrl(url); + } } protected internal bool SendNavigatingCanceled(string url) @@ -53,7 +58,7 @@ namespace Xamarin.Forms.Platform.Android if (url == AssetBaseUrl) return false; - var args = new WebNavigatingEventArgs(WebNavigationEvent.NewPage, new UrlWebViewSource { Url = url }, url); + var args = new WebNavigatingEventArgs(_eventState, new UrlWebViewSource { Url = url }, url); ElementController.SendNavigating(args); UpdateCanGoBackForward(); UrlCanceled = args.Cancel ? null : url; @@ -106,6 +111,11 @@ namespace Xamarin.Forms.Platform.Android return new AWebView(Context); } + internal WebNavigationEvent GetCurrentWebNavigationEvent() + { + return _eventState; + } + protected override void OnElementChanged(ElementChangedEventArgs e) { base.OnElementChanged(e); @@ -210,7 +220,10 @@ namespace Xamarin.Forms.Platform.Android void OnGoBackRequested(object sender, EventArgs eventArgs) { if (Control.CanGoBack()) + { + _eventState = WebNavigationEvent.Back; Control.GoBack(); + } UpdateCanGoBackForward(); } @@ -218,13 +231,17 @@ namespace Xamarin.Forms.Platform.Android void OnGoForwardRequested(object sender, EventArgs eventArgs) { if (Control.CanGoForward()) + { + _eventState = WebNavigationEvent.Forward; Control.GoForward(); + } UpdateCanGoBackForward(); } void OnReloadRequested(object sender, EventArgs eventArgs) { + _eventState = WebNavigationEvent.Refresh; Control.Reload(); }