[Core] FIX RelativeLayout layout error when only width or height specified (#5694)
authorkicsiede <4233752+kicsiede@users.noreply.github.com>
Fri, 16 Aug 2019 21:23:29 +0000 (23:23 +0200)
committerSamantha Houts <samhouts@users.noreply.github.com>
Fri, 16 Aug 2019 21:23:29 +0000 (14:23 -0700)
fixes #5581

Xamarin.Forms.Core/RelativeLayout.cs

index 28f3c04..08a6be6 100644 (file)
@@ -273,6 +273,8 @@ namespace Xamarin.Forms
                                y = () => 0;
 
                        Func<double> width;
+                       Func<double> height = null;
+
                        if (widthConstraint != null)
                        {
                                width = () => widthConstraint.Compute(this);
@@ -280,9 +282,8 @@ namespace Xamarin.Forms
                                        parents.AddRange(widthConstraint.RelativeTo);
                        }
                        else
-                               width = () => view.Measure(Width, Height, MeasureFlags.IncludeMargins).Request.Width;
+                               width = () => view.Measure(Width, heightConstraint != null ? height() : Height, MeasureFlags.IncludeMargins).Request.Width;
 
-                       Func<double> height;
                        if (heightConstraint != null)
                        {
                                height = () => heightConstraint.Compute(this);
@@ -290,7 +291,7 @@ namespace Xamarin.Forms
                                        parents.AddRange(heightConstraint.RelativeTo);
                        }
                        else
-                               height = () => view.Measure(Width, Height, MeasureFlags.IncludeMargins).Request.Height;
+                               height = () => view.Measure(widthConstraint != null ? width() : Width, Height, MeasureFlags.IncludeMargins).Request.Height;
 
                        BoundsConstraint bounds = BoundsConstraint.FromExpression(() => new Rectangle(x(), y(), width(), height()), parents.Distinct().ToArray());
                        SetBoundsConstraint(view, bounds);