summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.UnitTests
diff options
context:
space:
mode:
authorPhilippe Leybaert <philippe@activa.be>2017-02-02 12:55:55 -0600
committerJason Smith <jason.smith@xamarin.com>2017-02-02 13:55:54 -0500
commit01a56f9836a1cc5ea7da860032d8ca71859b1e17 (patch)
treecf8d6069f02358e9d4be75971a01b3018694ea24 /Xamarin.Forms.Core.UnitTests
parent9a6c9a0896a80889079ec57aa09a6c323deb24f3 (diff)
downloadxamarin-forms-01a56f9836a1cc5ea7da860032d8ca71859b1e17.tar.gz
xamarin-forms-01a56f9836a1cc5ea7da860032d8ca71859b1e17.tar.bz2
xamarin-forms-01a56f9836a1cc5ea7da860032d8ca71859b1e17.zip
Update RelativeLayout to make it respond to constraint changes (#425)
* Update RelativeLayout to make it respond to constraint changes Constraints of a RelativeLayout are bindable properties but the layout does not update when the constraints are updated. This change will invalidate the layout whenever XConstraint, YConstraint, WidthConstraint or HeightConstraint is changed (either in code or through a change in the bound property) * Specified changed handler as named property * Adding attached property accessors for layout properties Since the constraint attached properties can now be updated at runtime, setters are required for those properties. Also, when adding a child view at runtime using the Add() method with x/y/w/h constraints, generating the bounds constraints is deferred to the layout phase. * Unit tests for runtime constraints updates in RelativeLayout * Rename unit test method Rename LayoutChangesAtRuntim() to LayoutIsUpdatedWhenConstraintsChange() * Wrap RelativeLayout update setters in BatchBegin/Commit * Update documentation of RelativeLayout Added SetXConstraint(), SetYConstraint(), SetWidthConstraint() and SetHeightConstraint()
Diffstat (limited to 'Xamarin.Forms.Core.UnitTests')
-rw-r--r--Xamarin.Forms.Core.UnitTests/RelativeLayoutTests.cs41
1 files changed, 41 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core.UnitTests/RelativeLayoutTests.cs b/Xamarin.Forms.Core.UnitTests/RelativeLayoutTests.cs
index 96b3dfc8..fdbcdfc0 100644
--- a/Xamarin.Forms.Core.UnitTests/RelativeLayoutTests.cs
+++ b/Xamarin.Forms.Core.UnitTests/RelativeLayoutTests.cs
@@ -75,6 +75,47 @@ namespace Xamarin.Forms.Core.UnitTests
}
[Test]
+ public void LayoutIsUpdatedWhenConstraintsChange()
+ {
+ var relativeLayout = new RelativeLayout
+ {
+ Platform = new UnitPlatform(),
+ IsPlatformEnabled = true
+ };
+
+ var child = new View
+ {
+ IsPlatformEnabled = true
+ };
+
+ relativeLayout.Children.Add(child,
+ Constraint.Constant(30),
+ Constraint.Constant(20),
+ Constraint.RelativeToParent(parent => parent.Height / 2),
+ Constraint.RelativeToParent(parent => parent.Height / 4));
+
+ relativeLayout.Layout(new Rectangle(0, 0, 100, 100));
+
+ Assert.AreEqual(new Rectangle(30, 20, 50, 25), child.Bounds);
+
+ RelativeLayout.SetXConstraint(child, Constraint.Constant(40));
+
+ Assert.AreEqual(new Rectangle(40, 20, 50, 25), child.Bounds);
+
+ RelativeLayout.SetYConstraint(child, Constraint.Constant(10));
+
+ Assert.AreEqual(new Rectangle(40, 10, 50, 25), child.Bounds);
+
+ RelativeLayout.SetWidthConstraint(child, Constraint.RelativeToParent(parent => parent.Height / 4));
+
+ Assert.AreEqual(new Rectangle(40, 10, 25, 25), child.Bounds);
+
+ RelativeLayout.SetHeightConstraint(child, Constraint.RelativeToParent(parent => parent.Height / 2));
+
+ Assert.AreEqual(new Rectangle(40, 10, 25, 50), child.Bounds);
+ }
+
+ [Test]
public void SimpleExpressionLayout ()
{
var relativeLayout = new RelativeLayout {