Make UpdateCancelButton virtual (#8027)
authorGlenn Versweyveld <Depechie@users.noreply.github.com>
Thu, 17 Oct 2019 07:35:36 +0000 (09:35 +0200)
committerStephane Delcroix <stephane@delcroix.org>
Thu, 17 Oct 2019 07:35:36 +0000 (09:35 +0200)
This allows people to override the default behaviour

Xamarin.Forms.ControlGallery.iOS/CustomRenderers/CustomSearchBarRenderer.cs [new file with mode: 0644]
Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj
Xamarin.Forms.Platform.iOS/Renderers/SearchBarRenderer.cs

diff --git a/Xamarin.Forms.ControlGallery.iOS/CustomRenderers/CustomSearchBarRenderer.cs b/Xamarin.Forms.ControlGallery.iOS/CustomRenderers/CustomSearchBarRenderer.cs
new file mode 100644 (file)
index 0000000..7702390
--- /dev/null
@@ -0,0 +1,20 @@
+using System;
+using UIKit;
+using Xamarin.Forms;
+using Xamarin.Forms.ControlGallery.iOS.CustomRenderers;
+using Xamarin.Forms.Platform.iOS;
+
+// REMARK: Test renderer to validate that Virtual UpdateCancelButton works
+
+//[assembly: ExportRenderer(typeof(SearchBar), typeof(CustomSearchBarRenderer))]
+//namespace Xamarin.Forms.ControlGallery.iOS.CustomRenderers
+//{
+//     public class CustomSearchBarRenderer : SearchBarRenderer
+//     {
+//             public override void UpdateCancelButton()
+//             {
+//                     base.UpdateCancelButton();                      
+//                     Control.ShowsCancelButton = false;
+//             }
+//     }
+//}
\ No newline at end of file
index b8307b4..d94e912 100644 (file)
     <Compile Include="CustomRenderers\CustomRenderer.cs" />
     <Compile Include="CustomRenderers\RoundedLabelRenderer.cs" />
     <Compile Include="ApiLabelRenderer.cs" />
+    <Compile Include="CustomRenderers\CustomSearchBarRenderer.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\Xamarin.Forms.Controls\Xamarin.Forms.Controls.csproj">
index 3f1c073..1ba7d5e 100644 (file)
@@ -228,7 +228,7 @@ namespace Xamarin.Forms.Platform.iOS
                        _textField.VerticalAlignment = Element.VerticalTextAlignment.ToNativeTextAlignment();
                }
 
-               void UpdateCancelButton()
+               public virtual void UpdateCancelButton()
                {
                        Control.ShowsCancelButton = !string.IsNullOrEmpty(Control.Text);