roll back IButtonLayoutRenderer to its former 3.6 glory (#6290)
authorShane Neuville <shane94@hotmail.com>
Wed, 29 May 2019 00:27:26 +0000 (18:27 -0600)
committerSamantha Houts <samhouts@users.noreply.github.com>
Wed, 29 May 2019 00:27:26 +0000 (17:27 -0700)
Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs
Xamarin.Forms.Platform.Android/AppCompat/ButtonRenderer.cs
Xamarin.Forms.Platform.Android/ButtonLayoutManager.cs
Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs
Xamarin.Forms.Platform.Android/IButtonLayoutRenderer.cs

index 7f8e954..a78a8f3 100644 (file)
@@ -361,6 +361,14 @@ namespace Xamarin.Forms.Material.Android
 
                // IButtonLayoutRenderer
                AppCompatButton IButtonLayoutRenderer.View => this;
+
+               Button IButtonLayoutRenderer.Element => this.Element;
+
+               event EventHandler<VisualElementChangedEventArgs> IButtonLayoutRenderer.ElementChanged
+               {
+                       add => ((IVisualElementRenderer)this).ElementChanged += value;
+                       remove => ((IVisualElementRenderer)this).ElementChanged -= value;
+               }
        }
 }
 #endif
index 174ed3e..a4c9ba7 100644 (file)
@@ -201,6 +201,12 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
                        remove => ((IVisualElementRenderer)this).ElementChanged -= value;
                }
 
+               event EventHandler<VisualElementChangedEventArgs> IButtonLayoutRenderer.ElementChanged
+               {
+                       add => ((IVisualElementRenderer)this).ElementChanged += value;
+                       remove => ((IVisualElementRenderer)this).ElementChanged -= value;
+               }
+
                AppCompatButton IButtonLayoutRenderer.View => Control;
                bool IDisposedState.IsDisposed => _isDisposed;
        }
index 593fc66..0b7d16c 100644 (file)
@@ -288,31 +288,34 @@ namespace Xamarin.Forms.Platform.Android
                                        break;
                                }
 
-                       _renderer.ApplyDrawableAsync(Button.ImageSourceProperty, Context, image =>
+                       if (_renderer is IVisualElementRenderer visualElementRenderer)
                        {
-                               if (image == existingImage)
-                                       return;
-
-                               switch (layout.Position)
+                               visualElementRenderer.ApplyDrawableAsync(Button.ImageSourceProperty, Context, image =>
                                {
-                                       case Button.ButtonContentLayout.ImagePosition.Top:
-                                               TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, null, image, null, null);
-                                               break;
-                                       case Button.ButtonContentLayout.ImagePosition.Right:
-                                               TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, null, null, image, null);
-                                               break;
-                                       case Button.ButtonContentLayout.ImagePosition.Bottom:
-                                               TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, null, null, null, image);
-                                               break;
-                                       default:
+                                       if (image == existingImage)
+                                               return;
+
+                                       switch (layout.Position)
+                                       {
+                                               case Button.ButtonContentLayout.ImagePosition.Top:
+                                                       TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, null, image, null, null);
+                                                       break;
+                                               case Button.ButtonContentLayout.ImagePosition.Right:
+                                                       TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, null, null, image, null);
+                                                       break;
+                                               case Button.ButtonContentLayout.ImagePosition.Bottom:
+                                                       TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, null, null, null, image);
+                                                       break;
+                                               default:
                                                // Defaults to image on the left
                                                TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, image, null, null, null);
-                                               break;
-                               }
+                                                       break;
+                                       }
 
-                               if (_hasLayoutOccurred)
-                                       _element?.InvalidateMeasureNonVirtual(InvalidationTrigger.MeasureChanged);
-                       });
+                                       if (_hasLayoutOccurred)
+                                               _element?.InvalidateMeasureNonVirtual(InvalidationTrigger.MeasureChanged);
+                               });
+                       }
                }
        }
 }
index cfba741..c0870d4 100644 (file)
@@ -351,5 +351,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
                }
 
                AppCompatButton IButtonLayoutRenderer.View => this;
+
+               Button IButtonLayoutRenderer.Element => this.Element;
        }
 }
index c47613f..934ec1c 100644 (file)
@@ -1,9 +1,12 @@
-using Android.Support.V7.Widget;
+using System;
+using Android.Support.V7.Widget;
 
 namespace Xamarin.Forms.Platform.Android
 {
-       public interface IButtonLayoutRenderer : IVisualElementRenderer
+       public interface IButtonLayoutRenderer
        {
-               new AppCompatButton View { get; }
+               AppCompatButton View { get; }           
+               Button Element { get; }
+               event EventHandler<VisualElementChangedEventArgs> ElementChanged;
        }
 }