[Android] Remove call to update Image on button during measure (#6274)
authorShane Neuville <shane94@hotmail.com>
Wed, 29 May 2019 01:40:39 +0000 (19:40 -0600)
committerSamantha Houts <samhouts@users.noreply.github.com>
Wed, 29 May 2019 01:40:39 +0000 (18:40 -0700)
* remove update call before measure

* apply to material as well
fixes #6260

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6260.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs
Xamarin.Forms.Platform.Android/AppCompat/ButtonRenderer.cs
Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs

diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6260.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6260.cs
new file mode 100644 (file)
index 0000000..c4ccd16
--- /dev/null
@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Text;
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+using Xamarin.Forms.Core.UITests;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+       [Preserve(AllMembers = true)]
+       [Issue(IssueTracker.Github, 6260, "[Android] infinite layout loop",
+               PlatformAffected.Android)]
+#if UITEST
+       [NUnit.Framework.Category(UITestCategories.Button)]
+#endif
+       public class Issue6260 : TestContentPage
+       {
+               const string text = "If this number keeps increasing test has failed: ";
+               static string success = text + "0";
+
+               protected override void Init()
+               {
+                       int measurecount = 0;
+
+                       var button = new Button()
+                       {
+                               Text = "Click me",
+                               BackgroundColor = Color.Green,
+                               
+                       };
+
+                       var label = new Label()
+                       {
+                               Text = success
+                       };
+
+                       this.Appearing += (_, __) =>
+                       {
+                               button.ImageSource = "coffee.png";
+                               Device.BeginInvokeOnMainThread(() =>
+                               {
+                                       button.MeasureInvalidated += (___, ____) =>
+                                       {
+                                               measurecount++;
+                                               label.Text = text + measurecount.ToString();
+                                       };
+                               });
+                       };
+
+                       Content = new StackLayout()
+                       {
+                               Children =
+                               {
+                                       new Label()
+                                       {
+                                               Text = "Welcome to Xamarin.Forms!",
+                                               HorizontalOptions = LayoutOptions.Center,
+                                               VerticalOptions = LayoutOptions.CenterAndExpand
+                                       },
+                                       new Entry(),
+                                       button,
+                                       label
+                               }
+                       };
+               }
+
+#if UITEST
+               [Test]
+               public void ButtonImageInfiniteLayout()
+               {
+                       RunningApp.WaitForElement(success);
+               }
+#endif
+       }
+}
index 3a010ef..1e5359d 100644 (file)
@@ -11,6 +11,7 @@
   <ItemGroup>
     <Compile Include="$(MSBuildThisFileDirectory)Issue6262.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla59172.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Issue6260.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue5766.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue4684.xaml.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue4992.xaml.cs">
index a78a8f3..afd9ecc 100644 (file)
@@ -180,12 +180,6 @@ namespace Xamarin.Forms.Material.Android
                        base.OnLayout(changed, left, top, right, bottom);
                }
 
-               protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
-               {
-                       _buttonLayoutManager?.Update();
-                       base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
-               }
-
                void UpdateFont()
                {
                        if (_disposed || Element == null)
@@ -334,7 +328,6 @@ namespace Xamarin.Forms.Material.Android
 
                SizeRequest IVisualElementRenderer.GetDesiredSize(int widthConstraint, int heightConstraint)
                {
-                       _buttonLayoutManager?.Update();
                        Measure(widthConstraint, heightConstraint);
                        return new SizeRequest(new Size(MeasuredWidth, MeasuredHeight), new Size());
                }
index a4c9ba7..f912753 100644 (file)
@@ -52,11 +52,6 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
                void AView.IOnAttachStateChangeListener.OnViewDetachedFromWindow(AView detachedView) =>
                        _buttonLayoutManager?.OnViewDetachedFromWindow(detachedView);
 
-               public override SizeRequest GetDesiredSize(int widthConstraint, int heightConstraint)
-               {
-                       return base.GetDesiredSize(widthConstraint, heightConstraint);
-               }
-
                protected override void OnLayout(bool changed, int l, int t, int r, int b)
                {
                        _buttonLayoutManager?.OnLayout(changed, l, t, r, b);
index c0870d4..02d44d5 100644 (file)
@@ -241,12 +241,6 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
                        base.OnLayout(changed, l, t, r, b);
                }
 
-               protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
-               {
-                       _buttonLayoutManager?.Update();
-                       base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
-               }
-
                void SetTracker(VisualElementTracker tracker)
                {
                        _tracker = tracker;