[Android] Update webview to use correct value for WebNavigationEvent (#7089)

* Update Android webview to return correct WebNavigationEvent value

* set _eventState on load
This commit is contained in:
Ravinder Jangra 2019-08-13 02:40:23 +05:30 коммит произвёл kingces95
Родитель 6f663f1c8b
Коммит 26d63d6af6
2 изменённых файлов: 19 добавлений и 2 удалений

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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<WebView> 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();
}