Set ImageButton property of Android.ImageButtonRenderer public (#4534)
authorAlexandre Caprais <43949501+cacti-acaprais@users.noreply.github.com>
Fri, 30 Nov 2018 00:14:14 +0000 (01:14 +0100)
committerShane Neuville <shane94@hotmail.com>
Fri, 30 Nov 2018 00:14:14 +0000 (17:14 -0700)
* Set ImageButton property public
Set ImageButton property public.
* Rename ImageButton to Element
the Element set property remains private.

Xamarin.Forms.Platform.Android/AppCompat/ImageButtonRenderer.cs

index fbfed49..99d1a89 100644 (file)
@@ -1,4 +1,4 @@
-using System;
+using System;
 using System.ComponentModel;
 using Android.Content;
 using Android.Support.V7.Widget;
@@ -37,15 +37,15 @@ namespace Xamarin.Forms.Platform.Android
                public event EventHandler<PropertyChangedEventArgs> ElementPropertyChanged;
 
                void IVisualElementRenderer.UpdateLayout() => _tracker?.UpdateLayout();
-               VisualElement IVisualElementRenderer.Element => ImageButton;
+               VisualElement IVisualElementRenderer.Element => Element;
                AView IVisualElementRenderer.View => this;
                ViewGroup IVisualElementRenderer.ViewGroup => null;
                VisualElementTracker IVisualElementRenderer.Tracker => _tracker;
 
-               ImageButton ImageButton
+               public ImageButton Element
                {
                        get => _imageButton;
-                       set
+                       private set
                        {
                                _imageButton = value;
                                _platformElementConfiguration = null;
@@ -89,16 +89,16 @@ namespace Xamarin.Forms.Platform.Android
                                _backgroundTracker?.Dispose();
                                _backgroundTracker = null;
 
-                               if (ImageButton != null)
+                               if (Element != null)
                                {
-                                       ImageButton.PropertyChanged -= OnElementPropertyChanged;
+                                       Element.PropertyChanged -= OnElementPropertyChanged;
 
-                                       if (Android.Platform.GetRenderer(ImageButton) == this)
+                                       if (Android.Platform.GetRenderer(Element) == this)
                                        {
-                                               ImageButton.ClearValue(Android.Platform.RendererProperty);
+                                               Element.ClearValue(Android.Platform.RendererProperty);
                                        }
 
-                                       ImageButton = null;
+                                       Element = null;
                                }
                        }
 
@@ -144,8 +144,8 @@ namespace Xamarin.Forms.Platform.Android
                                throw new ArgumentException("Element is not of type " + typeof(ImageButton), nameof(element));
                        }
 
-                       ImageButton oldElement = ImageButton;
-                       ImageButton = image;
+                       ImageButton oldElement = Element;
+                       Element = image;
 
                        Performance.Start(out string reference);
 
@@ -174,8 +174,8 @@ namespace Xamarin.Forms.Platform.Android
                        UpdateInputTransparent();
                        UpdatePadding();
 
-                       OnElementChanged(new ElementChangedEventArgs<ImageButton>(oldElement, ImageButton));
-                       ImageButton?.SendViewInitialized(Control);
+                       OnElementChanged(new ElementChangedEventArgs<ImageButton>(oldElement, Element));
+                       Element?.SendViewInitialized(Control);
                }
 
                protected virtual void OnElementChanged(ElementChangedEventArgs<ImageButton> e)
@@ -185,7 +185,7 @@ namespace Xamarin.Forms.Platform.Android
 
                public override void Draw(Canvas canvas)
                {
-                       if (ImageButton == null)
+                       if (Element == null)
                                return;
 
                        var backgroundDrawable = _backgroundTracker?.BackgroundDrawable;
@@ -201,10 +201,10 @@ namespace Xamarin.Forms.Platform.Android
                                var widthRatio = 1f;
                                var heightRatio = 1f;
 
-                               if (ImageButton.Aspect == Aspect.AspectFill && OnThisPlatform().GetIsShadowEnabled())
+                               if (Element.Aspect == Aspect.AspectFill && OnThisPlatform().GetIsShadowEnabled())
                                        Internals.Log.Warning(nameof(ImageButtonRenderer), "AspectFill isn't fully supported when using shadows. Image may be clipped incorrectly to Border");
 
-                               switch (ImageButton.Aspect)
+                               switch (Element.Aspect)
                                {
                                        case Aspect.Fill:
                                                break;
@@ -248,21 +248,21 @@ namespace Xamarin.Forms.Platform.Android
                void UpdatePadding()
                {
                        SetPadding(
-                               (int)(Context.ToPixels(ImageButton.Padding.Left)),
-                               (int)(Context.ToPixels(ImageButton.Padding.Top)),
-                               (int)(Context.ToPixels(ImageButton.Padding.Right)),
-                               (int)(Context.ToPixels(ImageButton.Padding.Bottom))
+                               (int)(Context.ToPixels(Element.Padding.Left)),
+                               (int)(Context.ToPixels(Element.Padding.Top)),
+                               (int)(Context.ToPixels(Element.Padding.Right)),
+                               (int)(Context.ToPixels(Element.Padding.Bottom))
                        );
                }
 
                void UpdateInputTransparent()
                {
-                       if (ImageButton == null || _disposed)
+                       if (Element == null || _disposed)
                        {
                                return;
                        }
 
-                       _inputTransparent = ImageButton.InputTransparent;
+                       _inputTransparent = Element.InputTransparent;
                }
 
                protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -279,17 +279,17 @@ namespace Xamarin.Forms.Platform.Android
                // general state related
                void IOnFocusChangeListener.OnFocusChange(AView v, bool hasFocus)
                {
-                       ((IElementController)ImageButton).SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, hasFocus);
+                       ((IElementController)Element).SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, hasFocus);
                }
                // general state related
 
 
                // Button related
                void IOnClickListener.OnClick(AView v) =>
-                       ButtonElementManager.OnClick(ImageButton, ImageButton, v);
+                       ButtonElementManager.OnClick(Element, Element, v);
 
                bool IOnTouchListener.OnTouch(AView v, MotionEvent e) =>
-                       ButtonElementManager.OnTouch(ImageButton, ImageButton, v, e);
+                       ButtonElementManager.OnTouch(Element, Element, v, e);
                // Button related
 
 
@@ -300,13 +300,13 @@ namespace Xamarin.Forms.Platform.Android
                bool IBorderVisualElementRenderer.IsShadowEnabled() => OnThisPlatform().GetIsShadowEnabled();
                bool IBorderVisualElementRenderer.UseDefaultPadding() => false;
                bool IBorderVisualElementRenderer.UseDefaultShadow() => false;
-               VisualElement IBorderVisualElementRenderer.Element => ImageButton;
+               VisualElement IBorderVisualElementRenderer.Element => Element;
                AView IBorderVisualElementRenderer.View => this;
 
                IPlatformElementConfiguration<PlatformConfiguration.Android, ImageButton> OnThisPlatform()
                {
                        if (_platformElementConfiguration == null)
-                               _platformElementConfiguration = ImageButton.OnThisPlatform();
+                               _platformElementConfiguration = Element.OnThisPlatform();
 
                        return _platformElementConfiguration;
                }