summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.UnitTests
diff options
context:
space:
mode:
authorPhilippe Leybaert <philippe@activa.be>2017-02-02 12:55:55 -0600
committerKangho Hur <kangho.hur@samsung.com>2017-03-24 13:18:57 +0900
commit1c019470b9c2af3a1f9ab25252b23327ca5e351a (patch)
treedc95dcb1b491236ae6975441e4fc5e5ba4650db3 /Xamarin.Forms.Core.UnitTests
parentb50a12b136ef17b0bf46103821481d92ec3b2dae (diff)
downloadxamarin-forms-1c019470b9c2af3a1f9ab25252b23327ca5e351a.tar.gz
xamarin-forms-1c019470b9c2af3a1f9ab25252b23327ca5e351a.tar.bz2
xamarin-forms-1c019470b9c2af3a1f9ab25252b23327ca5e351a.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 {