diff --git a/Xamarin.Forms.Controls/CoreGalleryPages/WebViewCoreGalleryPage.cs b/Xamarin.Forms.Controls/CoreGalleryPages/WebViewCoreGalleryPage.cs index 837026679..10b70d920 100644 --- a/Xamarin.Forms.Controls/CoreGalleryPages/WebViewCoreGalleryPage.cs +++ b/Xamarin.Forms.Controls/CoreGalleryPages/WebViewCoreGalleryPage.cs @@ -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().SetEnableZoomControls(true); + enableZoomControlsWebView.On().SetDisplayZoomControls(false); + enableZoomControlsWebView.Source = new UrlWebViewSource + { + Url = "https://www.xamarin.com" + }; + + var displayZoomControlsWebView = new WebView() { HeightRequest = 200 }; + displayZoomControlsWebView.On().SetEnableZoomControls(true); + displayZoomControlsWebView.On().SetDisplayZoomControls(true); + displayZoomControlsWebView.Source = new UrlWebViewSource + { + Url = "https://www.xamarin.com" + }; + var mixedContentDisallowedContainer = new ViewContainer(Test.WebView.MixedContentDisallowed, mixedContentDisallowedWebView); var mixedContentAllowedContainer = new ViewContainer(Test.WebView.MixedContentAllowed, mixedContentAllowedWebView); + var enableZoomControlsContainer = new ViewContainer(Test.WebView.EnableZoomControls, + enableZoomControlsWebView); + var displayZoomControlsWebViewContainer = new ViewContainer(Test.WebView.DisplayZoomControls, + displayZoomControlsWebView); + Add(mixedContentDisallowedContainer); Add(mixedContentAllowedContainer); + Add(enableZoomControlsContainer); + Add(displayZoomControlsWebViewContainer); } diff --git a/Xamarin.Forms.Core.UnitTests/WebViewUnitTests.cs b/Xamarin.Forms.Core.UnitTests/WebViewUnitTests.cs index ed12f0296..c021320d6 100644 --- a/Xamarin.Forms.Core.UnitTests/WebViewUnitTests.cs +++ b/Xamarin.Forms.Core.UnitTests/WebViewUnitTests.cs @@ -105,6 +105,30 @@ namespace Xamarin.Forms.Core.UnitTests Assert.AreEqual(mixedContentWebView.On().MixedContentMode(), MixedContentHandling.AlwaysAllow); } + [Test] + public void TestEnableZoomControls() + { + var defaultWebView = new WebView(); + + var enableZoomControlsWebView = new WebView(); + enableZoomControlsWebView.On().SetEnableZoomControls(true); + + Assert.AreEqual(defaultWebView.On().EnableZoomControls(), false); + Assert.AreEqual(enableZoomControlsWebView.On().EnableZoomControls(), true); + } + + [Test] + public void TestDisplayZoomControls() + { + var defaultWebView = new WebView(); + + var displayZoomControlsWebView = new WebView(); + displayZoomControlsWebView.On().SetDisplayZoomControls(false); + + Assert.AreEqual(defaultWebView.On().DisplayZoomControls(), true); + Assert.AreEqual(displayZoomControlsWebView.On().DisplayZoomControls(), false); + } + [Test] public void TestWindowsSetAllowJavaScriptAlertsFlag() { diff --git a/Xamarin.Forms.Core/PlatformConfiguration/AndroidSpecific/WebView.cs b/Xamarin.Forms.Core/PlatformConfiguration/AndroidSpecific/WebView.cs index 8c96d375f..b8e5da8a7 100644 --- a/Xamarin.Forms.Core/PlatformConfiguration/AndroidSpecific/WebView.cs +++ b/Xamarin.Forms.Core/PlatformConfiguration/AndroidSpecific/WebView.cs @@ -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 config) + { + return GetEnableZoomControls(config.Element); + } + + public static IPlatformElementConfiguration SetEnableZoomControls(this IPlatformElementConfiguration 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 config) + { + return GetDisplayZoomControls(config.Element); + } + + public static IPlatformElementConfiguration SetDisplayZoomControls(this IPlatformElementConfiguration config, bool value) + { + SetDisplayZoomControls(config.Element, value); + return config; + } } } diff --git a/Xamarin.Forms.CustomAttributes/TestAttributes.cs b/Xamarin.Forms.CustomAttributes/TestAttributes.cs index dc37df91c..aff1749e4 100644 --- a/Xamarin.Forms.CustomAttributes/TestAttributes.cs +++ b/Xamarin.Forms.CustomAttributes/TestAttributes.cs @@ -736,7 +736,9 @@ namespace Xamarin.Forms.CustomAttributes MixedContentDisallowed, MixedContentAllowed, JavaScriptAlert, - EvaluateJavaScript + EvaluateJavaScript, + EnableZoomControls, + DisplayZoomControls } public enum UrlWebViewSource diff --git a/Xamarin.Forms.Platform.Android/Renderers/WebViewRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/WebViewRenderer.cs index 51cd095d5..e9fb6c239 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/WebViewRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/WebViewRenderer.cs @@ -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 source;