fixes #6679 [Bug] WebView UWP not displaying (#9390)

* fixes #6679 [Bug] WebView UWP not displaying

* free up memory after we're done with _internalWebView

* add comments

* remove private keyword
fixes #6679
This commit is contained in:
Artem 2020-02-19 01:52:06 +02:00 коммит произвёл GitHub
Родитель 6b879e6f0c
Коммит d53191abc9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 9 добавлений и 5 удалений

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

@ -1,4 +1,4 @@
using System;
using System;
using System.ComponentModel;
using Windows.UI.Core;
using Windows.UI.Xaml.Controls;
@ -14,6 +14,7 @@ namespace Xamarin.Forms.Platform.UWP
{
WebNavigationEvent _eventState;
bool _updating;
Windows.UI.Xaml.Controls.WebView _internalWebView;
const string LocalScheme = "ms-appx-web:///";
// Script to insert a <base> tag into an HTML document
@ -36,10 +37,11 @@ if(bases.length == 0){
string htmlWithBaseTag;
// Set up an internal WebView we can use to load and parse the original HTML string
var internalWebView = new Windows.UI.Xaml.Controls.WebView();
// Make _internalWebView a field instead of local variable to avoid garbage collection
_internalWebView = new Windows.UI.Xaml.Controls.WebView();
// When the 'navigation' to the original HTML string is done, we can modify it to include our <base> tag
internalWebView.NavigationCompleted += async (sender, args) =>
_internalWebView.NavigationCompleted += async (sender, args) =>
{
// Generate a version of the <base> script with the correct <base> tag
var script = BaseInsertionScript.Replace("baseTag", baseTag);
@ -50,10 +52,12 @@ if(bases.length == 0){
// Set the HTML for the 'real' WebView to the updated HTML
Control.NavigateToString(!IsNullOrEmpty(htmlWithBaseTag) ? htmlWithBaseTag : html);
// free up memory after we're done with _internalWebView
_internalWebView = null;
};
// Kick off the initial navigation
internalWebView.NavigateToString(html);
_internalWebView.NavigateToString(html);
}
public void LoadUrl(string url)
@ -235,4 +239,4 @@ if(bases.length == 0){
((IWebViewController)Element).CanGoForward = Control.CanGoForward;
}
}
}
}