* Started implementation of zoom support on Android WebView * Implemented fully working zoom and zoom controls for Android WebView * Corrected merge error * Removed redundant API checks * Update Xamarin.Forms.Core/PlatformConfiguration/AndroidSpecific/WebView.cs Co-Authored-By: jfversluis <github@geraldversluis.nl> * Update Xamarin.Forms.Core/PlatformConfiguration/AndroidSpecific/WebView.cs Co-Authored-By: jfversluis <github@geraldversluis.nl> * Update Xamarin.Forms.Core/PlatformConfiguration/AndroidSpecific/WebView.cs Co-Authored-By: jfversluis <github@geraldversluis.nl> * Update Xamarin.Forms.Core/PlatformConfiguration/AndroidSpecific/WebView.cs Co-Authored-By: jfversluis <github@geraldversluis.nl> * Update Xamarin.Forms.Core/PlatformConfiguration/AndroidSpecific/WebView.cs Co-Authored-By: jfversluis <github@geraldversluis.nl> * Update Xamarin.Forms.Core/PlatformConfiguration/AndroidSpecific/WebView.cs Co-Authored-By: jfversluis <github@geraldversluis.nl>
This commit is contained in:
Родитель
920e2dd416
Коммит
2c3df0ac0e
|
@ -63,6 +63,7 @@ namespace Xamarin.Forms.Controls
|
|||
);
|
||||
|
||||
// NOTE: Currently the ability to programmatically enable/disable mixed content only exists on Android
|
||||
// NOTE: Currently the ability to programmatically enable/disable zoom only exists on Android
|
||||
if (Device.RuntimePlatform == Device.Android)
|
||||
{
|
||||
var mixedContentTestPage = "https://mixed-content-test.appspot.com/";
|
||||
|
@ -81,13 +82,36 @@ namespace Xamarin.Forms.Controls
|
|||
Url = mixedContentTestPage
|
||||
};
|
||||
|
||||
var enableZoomControlsWebView = new WebView() { HeightRequest = 200 };
|
||||
enableZoomControlsWebView.On<Android>().SetEnableZoomControls(true);
|
||||
enableZoomControlsWebView.On<Android>().SetDisplayZoomControls(false);
|
||||
enableZoomControlsWebView.Source = new UrlWebViewSource
|
||||
{
|
||||
Url = "https://www.xamarin.com"
|
||||
};
|
||||
|
||||
var displayZoomControlsWebView = new WebView() { HeightRequest = 200 };
|
||||
displayZoomControlsWebView.On<Android>().SetEnableZoomControls(true);
|
||||
displayZoomControlsWebView.On<Android>().SetDisplayZoomControls(true);
|
||||
displayZoomControlsWebView.Source = new UrlWebViewSource
|
||||
{
|
||||
Url = "https://www.xamarin.com"
|
||||
};
|
||||
|
||||
var mixedContentDisallowedContainer = new ViewContainer<WebView>(Test.WebView.MixedContentDisallowed,
|
||||
mixedContentDisallowedWebView);
|
||||
var mixedContentAllowedContainer = new ViewContainer<WebView>(Test.WebView.MixedContentAllowed,
|
||||
mixedContentAllowedWebView);
|
||||
|
||||
var enableZoomControlsContainer = new ViewContainer<WebView>(Test.WebView.EnableZoomControls,
|
||||
enableZoomControlsWebView);
|
||||
var displayZoomControlsWebViewContainer = new ViewContainer<WebView>(Test.WebView.DisplayZoomControls,
|
||||
displayZoomControlsWebView);
|
||||
|
||||
Add(mixedContentDisallowedContainer);
|
||||
Add(mixedContentAllowedContainer);
|
||||
Add(enableZoomControlsContainer);
|
||||
Add(displayZoomControlsWebViewContainer);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -105,6 +105,30 @@ namespace Xamarin.Forms.Core.UnitTests
|
|||
Assert.AreEqual(mixedContentWebView.On<Android>().MixedContentMode(), MixedContentHandling.AlwaysAllow);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEnableZoomControls()
|
||||
{
|
||||
var defaultWebView = new WebView();
|
||||
|
||||
var enableZoomControlsWebView = new WebView();
|
||||
enableZoomControlsWebView.On<Android>().SetEnableZoomControls(true);
|
||||
|
||||
Assert.AreEqual(defaultWebView.On<Android>().EnableZoomControls(), false);
|
||||
Assert.AreEqual(enableZoomControlsWebView.On<Android>().EnableZoomControls(), true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDisplayZoomControls()
|
||||
{
|
||||
var defaultWebView = new WebView();
|
||||
|
||||
var displayZoomControlsWebView = new WebView();
|
||||
displayZoomControlsWebView.On<Android>().SetDisplayZoomControls(false);
|
||||
|
||||
Assert.AreEqual(defaultWebView.On<Android>().DisplayZoomControls(), true);
|
||||
Assert.AreEqual(displayZoomControlsWebView.On<Android>().DisplayZoomControls(), false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWindowsSetAllowJavaScriptAlertsFlag()
|
||||
{
|
||||
|
|
|
@ -34,5 +34,51 @@ namespace Xamarin.Forms.PlatformConfiguration.AndroidSpecific
|
|||
SetMixedContentMode(config.Element, value);
|
||||
return config;
|
||||
}
|
||||
|
||||
public static readonly BindableProperty EnableZoomControlProperty = BindableProperty.Create("EnableZoomControls", typeof(bool), typeof(FormsElement), false);
|
||||
|
||||
public static bool GetEnableZoomControls(FormsElement element)
|
||||
{
|
||||
return (bool)element.GetValue(EnableZoomControlProperty);
|
||||
}
|
||||
|
||||
public static void SetEnableZoomControls(FormsElement element, bool value)
|
||||
{
|
||||
element.SetValue(EnableZoomControlProperty, value);
|
||||
}
|
||||
|
||||
public static bool EnableZoomControls(this IPlatformElementConfiguration<Android, FormsElement> config)
|
||||
{
|
||||
return GetEnableZoomControls(config.Element);
|
||||
}
|
||||
|
||||
public static IPlatformElementConfiguration<Android, FormsElement> SetEnableZoomControls(this IPlatformElementConfiguration<Android, FormsElement> config, bool value)
|
||||
{
|
||||
SetEnableZoomControls(config.Element, value);
|
||||
return config;
|
||||
}
|
||||
|
||||
public static readonly BindableProperty DisplayZoomControlsProperty = BindableProperty.Create("DisplayZoomControls", typeof(bool), typeof(FormsElement), true);
|
||||
|
||||
public static bool GetDisplayZoomControls(FormsElement element)
|
||||
{
|
||||
return (bool)element.GetValue(DisplayZoomControlsProperty);
|
||||
}
|
||||
|
||||
public static void SetDisplayZoomControls(FormsElement element, bool value)
|
||||
{
|
||||
element.SetValue(DisplayZoomControlsProperty, value);
|
||||
}
|
||||
|
||||
public static bool DisplayZoomControls(this IPlatformElementConfiguration<Android, FormsElement> config)
|
||||
{
|
||||
return GetDisplayZoomControls(config.Element);
|
||||
}
|
||||
|
||||
public static IPlatformElementConfiguration<Android, FormsElement> SetDisplayZoomControls(this IPlatformElementConfiguration<Android, FormsElement> config, bool value)
|
||||
{
|
||||
SetDisplayZoomControls(config.Element, value);
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -736,7 +736,9 @@ namespace Xamarin.Forms.CustomAttributes
|
|||
MixedContentDisallowed,
|
||||
MixedContentAllowed,
|
||||
JavaScriptAlert,
|
||||
EvaluateJavaScript
|
||||
EvaluateJavaScript,
|
||||
EnableZoomControls,
|
||||
DisplayZoomControls
|
||||
}
|
||||
|
||||
public enum UrlWebViewSource
|
||||
|
|
|
@ -129,6 +129,8 @@ namespace Xamarin.Forms.Platform.Android
|
|||
newElementController.ReloadRequested += OnReloadRequested;
|
||||
|
||||
UpdateMixedContentMode();
|
||||
UpdateEnableZoomControls();
|
||||
UpdateDisplayZoomControls();
|
||||
}
|
||||
|
||||
Load();
|
||||
|
@ -146,6 +148,12 @@ namespace Xamarin.Forms.Platform.Android
|
|||
case "MixedContentMode":
|
||||
UpdateMixedContentMode();
|
||||
break;
|
||||
case "EnableZoomControls":
|
||||
UpdateEnableZoomControls();
|
||||
break;
|
||||
case "DisplayZoomControls":
|
||||
UpdateDisplayZoomControls();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,6 +218,18 @@ namespace Xamarin.Forms.Platform.Android
|
|||
}
|
||||
}
|
||||
|
||||
void UpdateEnableZoomControls()
|
||||
{
|
||||
var value = Element.OnThisPlatform().EnableZoomControls();
|
||||
Control.Settings.SetSupportZoom(value);
|
||||
Control.Settings.BuiltInZoomControls = value;
|
||||
}
|
||||
|
||||
void UpdateDisplayZoomControls()
|
||||
{
|
||||
Control.Settings.DisplayZoomControls = Element.OnThisPlatform().DisplayZoomControls();
|
||||
}
|
||||
|
||||
class JavascriptResult : Java.Lang.Object, IValueCallback
|
||||
{
|
||||
TaskCompletionSource<string> source;
|
||||
|
|
Загрузка…
Ссылка в новой задаче