[Android] Fix WebView EnableZoomControls and DisplayZoomControls api (#6137)
authorSamantha Houts <samhouts@users.noreply.github.com>
Thu, 9 May 2019 18:00:14 +0000 (11:00 -0700)
committerGitHub <noreply@github.com>
Thu, 9 May 2019 18:00:14 +0000 (11:00 -0700)
* Add tests for #6132 and #6130

* [Android] Fix EnableZoomControl BP name and fix helper methods

fixes #6132
fixes #6130

* Update Xamarin.Forms.Controls.Issues.Shared.projitems

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6130.xaml [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6130.xaml.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6132.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Core.UnitTests/WebViewUnitTests.cs
Xamarin.Forms.Core/PlatformConfiguration/AndroidSpecific/WebView.cs
Xamarin.Forms.Platform.Android/Renderers/WebViewRenderer.cs

diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6130.xaml b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6130.xaml
new file mode 100644 (file)
index 0000000..17dfedf
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
+             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+             xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
+             x:Class="Xamarin.Forms.Controls.Issues.Issue6130">
+    <ContentPage.Content>
+        <WebView Source="http://www.xamarin.com" android:WebView.EnableZoomControls="True" android:WebView.DisplayZoomControls="True"  />
+    </ContentPage.Content>
+</ContentPage>
\ No newline at end of file
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6130.xaml.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6130.xaml.cs
new file mode 100644 (file)
index 0000000..a9a24be
--- /dev/null
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using Xamarin.Forms;
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+using Xamarin.Forms.Xaml;
+
+namespace Xamarin.Forms.Controls.Issues
+{
+       [Preserve(AllMembers = true)]
+       [Issue(IssueTracker.Github, 6130, "[Bug] [Forms 4.0] [Android] Mismatch in WebView.EnableZoomControls platform-specific", PlatformAffected.Android)]
+       public partial class Issue6130 : ContentPage
+       {
+               public Issue6130()
+               {
+#if APP
+                       InitializeComponent();
+#endif
+               }
+       }
+}
\ No newline at end of file
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6132.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6132.cs
new file mode 100644 (file)
index 0000000..66c8137
--- /dev/null
@@ -0,0 +1,26 @@
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+using Xamarin.Forms.PlatformConfiguration;
+using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
+
+namespace Xamarin.Forms.Controls.Issues
+{
+       [Preserve(AllMembers = true)]
+       [Issue(IssueTracker.Github, 6132, "[Bug] [Forms 4.0] [Android] WebView.EnableZoomControls platform-specific doesn't work ", PlatformAffected.Android)]
+       public class Issue6132 : TestContentPage
+       {
+               protected override void Init()
+               {
+                       Title = "WebView Zoom Controls";
+                       WebView webView = new WebView
+                       {
+                               Source = "https://www.xamarin.com"
+                       };
+
+                       webView.On<Android>().EnableZoomControls(true);
+                       webView.On<Android>().DisplayZoomControls(true);
+
+                       Content = webView;
+               }
+       }
+}
\ No newline at end of file
index 56324a0..4e9d6e5 100644 (file)
     </Compile>
     <Compile Include="$(MSBuildThisFileDirectory)Issue5535.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue5793.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Issue6130.xaml.cs">
+      <SubType>Code</SubType>
+    </Compile>
     <Compile Include="$(MSBuildThisFileDirectory)LegacyComponents\NonAppCompatSwitch.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)MapsModalCrash.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)ModalActivityIndicatorTest.cs" />
     </Compile>
     <Compile Include="$(MSBuildThisFileDirectory)Issue5470.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue5724.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Issue6132.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)_Template.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla56298.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla42620.cs" />
       <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
     </EmbeddedResource>
   </ItemGroup>
-</Project>
\ No newline at end of file
+  <ItemGroup>
+    <EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue6130.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </EmbeddedResource>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Update="$(MSBuildThisFileDirectory)Issue6130.xaml.cs">
+      <DependentUpon>Issue6130.xaml</DependentUpon>
+    </Compile>
+  </ItemGroup>
+</Project>
index c021320..8e107a7 100644 (file)
@@ -113,8 +113,8 @@ namespace Xamarin.Forms.Core.UnitTests
                        var enableZoomControlsWebView = new WebView();
                        enableZoomControlsWebView.On<Android>().SetEnableZoomControls(true);
 
-                       Assert.AreEqual(defaultWebView.On<Android>().EnableZoomControls(), false);
-                       Assert.AreEqual(enableZoomControlsWebView.On<Android>().EnableZoomControls(), true);
+                       Assert.AreEqual(defaultWebView.On<Android>().ZoomControlsEnabled(), false);
+                       Assert.AreEqual(enableZoomControlsWebView.On<Android>().ZoomControlsEnabled(), true);
                }
 
                [Test]
@@ -125,8 +125,8 @@ namespace Xamarin.Forms.Core.UnitTests
                        var displayZoomControlsWebView = new WebView();
                        displayZoomControlsWebView.On<Android>().SetDisplayZoomControls(false);
 
-                       Assert.AreEqual(defaultWebView.On<Android>().DisplayZoomControls(), true);
-                       Assert.AreEqual(displayZoomControlsWebView.On<Android>().DisplayZoomControls(), false);
+                       Assert.AreEqual(defaultWebView.On<Android>().ZoomControlsDisplayed(), true);
+                       Assert.AreEqual(displayZoomControlsWebView.On<Android>().ZoomControlsDisplayed(), false);
                }
 
                [Test]
index b8e5da8..9db236f 100644 (file)
@@ -35,19 +35,23 @@ namespace Xamarin.Forms.PlatformConfiguration.AndroidSpecific
                        return config;
                }
 
-               public static readonly BindableProperty EnableZoomControlProperty = BindableProperty.Create("EnableZoomControls", typeof(bool), typeof(FormsElement), false);
+               public static readonly BindableProperty EnableZoomControlsProperty = BindableProperty.Create("EnableZoomControls", typeof(bool), typeof(FormsElement), false);
 
                public static bool GetEnableZoomControls(FormsElement element)
                {
-                       return (bool)element.GetValue(EnableZoomControlProperty);
+                       return (bool)element.GetValue(EnableZoomControlsProperty);
                }
 
                public static void SetEnableZoomControls(FormsElement element, bool value)
                {
-                       element.SetValue(EnableZoomControlProperty, value);
+                       element.SetValue(EnableZoomControlsProperty, value);
                }
 
-               public static bool EnableZoomControls(this IPlatformElementConfiguration<Android, FormsElement> config)
+               public static void EnableZoomControls(this IPlatformElementConfiguration<Android, FormsElement> config, bool value)
+               {
+                       SetEnableZoomControls(config.Element, value);
+               }
+               public static bool ZoomControlsEnabled(this IPlatformElementConfiguration<Android, FormsElement> config)
                {
                        return GetEnableZoomControls(config.Element);
                }
@@ -70,7 +74,12 @@ namespace Xamarin.Forms.PlatformConfiguration.AndroidSpecific
                        element.SetValue(DisplayZoomControlsProperty, value);
                }
 
-               public static bool DisplayZoomControls(this IPlatformElementConfiguration<Android, FormsElement> config)
+               public static void DisplayZoomControls(this IPlatformElementConfiguration<Android, FormsElement> config, bool value)
+               {
+                       SetDisplayZoomControls(config.Element, value);
+               }
+
+               public static bool ZoomControlsDisplayed(this IPlatformElementConfiguration<Android, FormsElement> config)
                {
                        return GetDisplayZoomControls(config.Element);
                }
index dd198f3..1b87331 100644 (file)
@@ -235,14 +235,14 @@ namespace Xamarin.Forms.Platform.Android
 
                void UpdateEnableZoomControls()
                {
-                       var value = Element.OnThisPlatform().EnableZoomControls();
+                       var value = Element.OnThisPlatform().ZoomControlsEnabled();
                        Control.Settings.SetSupportZoom(value);
                        Control.Settings.BuiltInZoomControls = value;
                }
 
                void UpdateDisplayZoomControls()
                {
-                       Control.Settings.DisplayZoomControls = Element.OnThisPlatform().DisplayZoomControls();
+                       Control.Settings.DisplayZoomControls = Element.OnThisPlatform().ZoomControlsDisplayed();
                }
 
                class JavascriptResult : Java.Lang.Object, IValueCallback