summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core/RelativeLayout.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Core/RelativeLayout.cs')
-rw-r--r--Xamarin.Forms.Core/RelativeLayout.cs62
1 files changed, 8 insertions, 54 deletions
diff --git a/Xamarin.Forms.Core/RelativeLayout.cs b/Xamarin.Forms.Core/RelativeLayout.cs
index 2b835013..b3a1b615 100644
--- a/Xamarin.Forms.Core/RelativeLayout.cs
+++ b/Xamarin.Forms.Core/RelativeLayout.cs
@@ -8,13 +8,13 @@ namespace Xamarin.Forms
{
public class RelativeLayout : Layout<View>
{
- public static readonly BindableProperty XConstraintProperty = BindableProperty.CreateAttached("XConstraint", typeof(Constraint), typeof(RelativeLayout), null, propertyChanged: ConstraintChanged);
+ public static readonly BindableProperty XConstraintProperty = BindableProperty.CreateAttached("XConstraint", typeof(Constraint), typeof(RelativeLayout), null);
- public static readonly BindableProperty YConstraintProperty = BindableProperty.CreateAttached("YConstraint", typeof(Constraint), typeof(RelativeLayout), null, propertyChanged: ConstraintChanged);
+ public static readonly BindableProperty YConstraintProperty = BindableProperty.CreateAttached("YConstraint", typeof(Constraint), typeof(RelativeLayout), null);
- public static readonly BindableProperty WidthConstraintProperty = BindableProperty.CreateAttached("WidthConstraint", typeof(Constraint), typeof(RelativeLayout), null, propertyChanged: ConstraintChanged);
+ public static readonly BindableProperty WidthConstraintProperty = BindableProperty.CreateAttached("WidthConstraint", typeof(Constraint), typeof(RelativeLayout), null);
- public static readonly BindableProperty HeightConstraintProperty = BindableProperty.CreateAttached("HeightConstraint", typeof(Constraint), typeof(RelativeLayout), null, propertyChanged: ConstraintChanged);
+ public static readonly BindableProperty HeightConstraintProperty = BindableProperty.CreateAttached("HeightConstraint", typeof(Constraint), typeof(RelativeLayout), null);
public static readonly BindableProperty BoundsConstraintProperty = BindableProperty.CreateAttached("BoundsConstraint", typeof(BoundsConstraint), typeof(RelativeLayout), null);
@@ -72,25 +72,6 @@ namespace Xamarin.Forms
}
}
- static void ConstraintChanged(BindableObject bindable, object oldValue, object newValue)
- {
- View view = bindable as View;
-
- (view?.Parent as RelativeLayout)?.UpdateBoundsConstraint(view);
- }
-
- void UpdateBoundsConstraint(View view)
- {
- if (GetBoundsConstraint(view) == null)
- return; // Bounds constraint hasn't been calculated yet, no need to update just yet
-
- CreateBoundsFromConstraints(view, GetXConstraint(view), GetYConstraint(view), GetWidthConstraint(view), GetHeightConstraint(view));
-
- _childrenInSolveOrder = null; // New constraints may have impact on solve order
-
- InvalidateLayout();
- }
-
public static BoundsConstraint GetBoundsConstraint(BindableObject bindable)
{
return (BoundsConstraint)bindable.GetValue(BoundsConstraintProperty);
@@ -121,26 +102,6 @@ namespace Xamarin.Forms
bindable.SetValue(BoundsConstraintProperty, value);
}
- public static void SetHeightConstraint(BindableObject bindable, Constraint value)
- {
- bindable.SetValue(HeightConstraintProperty, value);
- }
-
- public static void SetWidthConstraint(BindableObject bindable, Constraint value)
- {
- bindable.SetValue(WidthConstraintProperty, value);
- }
-
- public static void SetXConstraint(BindableObject bindable, Constraint value)
- {
- bindable.SetValue(XConstraintProperty, value);
- }
-
- public static void SetYConstraint(BindableObject bindable, Constraint value)
- {
- bindable.SetValue(YConstraintProperty, value);
- }
-
protected override void LayoutChildren(double x, double y, double width, double height)
{
foreach (View child in ChildrenInSolveOrder)
@@ -287,13 +248,13 @@ namespace Xamarin.Forms
static Rectangle SolveView(View view)
{
BoundsConstraint boundsConstraint = GetBoundsConstraint(view);
+ var result = new Rectangle();
if (boundsConstraint == null)
{
throw new Exception("BoundsConstraint should not be null at this point");
}
-
- var result = boundsConstraint.Compute();
+ result = boundsConstraint.Compute();
return result;
}
@@ -319,7 +280,7 @@ namespace Xamarin.Forms
public void Add(View view, Expression<Func<Rectangle>> bounds)
{
if (bounds == null)
- throw new ArgumentNullException(nameof(bounds));
+ throw new ArgumentNullException("bounds");
SetBoundsConstraint(view, BoundsConstraint.FromExpression(bounds));
base.Add(view);
@@ -347,14 +308,7 @@ namespace Xamarin.Forms
public void Add(View view, Constraint xConstraint = null, Constraint yConstraint = null, Constraint widthConstraint = null, Constraint heightConstraint = null)
{
- view.BatchBegin();
-
- RelativeLayout.SetXConstraint(view, xConstraint);
- RelativeLayout.SetYConstraint(view, yConstraint);
- RelativeLayout.SetWidthConstraint(view, widthConstraint);
- RelativeLayout.SetHeightConstraint(view, heightConstraint);
-
- view.BatchCommit();
+ Parent.CreateBoundsFromConstraints(view, xConstraint, yConstraint, widthConstraint, heightConstraint);
base.Add(view);
}