Jonas Budelmann 12 tahun lalu
induk
melakukan
7e952d922b

+ 2 - 0
.gitignore

@@ -16,3 +16,5 @@ profile
 Podfile.lock
 /Pods/
 script/env.sh
+
+/Masonry.xcworkspace/xcshareddata/Masonry.xccheckout

+ 2 - 2
Masonry.podspec

@@ -1,12 +1,12 @@
 Pod::Spec.new do |s|
   s.name     = 'Masonry'
-  s.version  = '0.2.3'
+  s.version  = '0.2.4'
   s.license  = 'MIT'
   s.summary  = 'Harness the power of Auto Layout NSLayoutConstraints with a simplified, chainable and expressive syntax.'
   s.homepage = 'https://github.com/cloudkite/Masonry'
   s.author   = { 'Jonas Budelmann' => 'jonas.budelmann@gmail.com' }
 
-  s.source   = { :git => 'https://github.com/cloudkite/Masonry.git', :tag => 'v0.2.3' }
+  s.source   = { :git => 'https://github.com/cloudkite/Masonry.git', :tag => 'v0.2.4' }
 
   s.description = %{
     Masonry is a light-weight layout framework which wraps AutoLayout with a nicer syntax.

+ 3 - 1
Masonry/MASViewConstraint.m

@@ -206,8 +206,8 @@
 
 - (id<MASConstraint> (^)(id))equalityWithRelation:(NSLayoutRelation)relation {
     return ^id(id attribute) {
-        NSAssert(!self.hasLayoutRelation, @"Redefinition of constraint relation");
         if ([attribute isKindOfClass:NSArray.class]) {
+            NSAssert(!self.hasLayoutRelation, @"Redefinition of constraint relation");
             NSMutableArray *children = NSMutableArray.new;
             for (id attr in attribute) {
                 MASViewConstraint *viewConstraint = [self copy];
@@ -219,6 +219,8 @@
             [self.delegate constraint:self shouldBeReplacedWithConstraint:compositeConstraint];
             return compositeConstraint;
         } else {
+            BOOL layoutConstantUpdate = self.layoutRelation == relation && [attribute isKindOfClass:NSNumber.class];
+            NSAssert(!self.hasLayoutRelation || layoutConstantUpdate, @"Redefinition of constraint relation");
             self.layoutRelation = relation;
             self.secondViewAttribute = attribute;
             return self;

+ 2 - 2
MasonryTests/MASCompositeConstraintSpec.m

@@ -135,8 +135,8 @@ it(@"should modify insets on appropriate children", ^{
 
 it(@"should uninstall", ^{
     NSArray *children = @[
-        [[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_centerX],
-        [[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_centerY]
+        [[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_leading],
+        [[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_trailing]
     ];
     composite = [[MASCompositeConstraint alloc] initWithChildren:children];
     composite.delegate = delegate;

+ 23 - 1
MasonryTests/NSLayoutConstraint+MASDebugAdditionsSpec.m

@@ -9,6 +9,8 @@
 #import "NSLayoutConstraint+MASDebugAdditions.h"
 #import "View+MASAdditions.h"
 #import "MASLayoutConstraint.h"
+#import "MASCompositeConstraint.h"
+#import "MASViewConstraint.h"
 
 SpecBegin(NSLayoutConstraint_MASDebugAdditions)
 
@@ -18,7 +20,9 @@ it(@"should display view key", ^{
 
     MASLayoutConstraint *layoutConstraint = [MASLayoutConstraint constraintWithItem:newView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:300];
 
-    NSString *description = [NSString stringWithFormat:@"<MASLayoutConstraint:%p %@:newView.width >= 300>", layoutConstraint, MAS_VIEW.class];
+    layoutConstraint.priority = MASLayoutPriorityDefaultLow;
+
+    NSString *description = [NSString stringWithFormat:@"<MASLayoutConstraint:%p %@:newView.width >= 300 ^low>", layoutConstraint, MAS_VIEW.class];
     expect([layoutConstraint description]).to.equal(description);
 });
 
@@ -35,4 +39,22 @@ it(@"should display layoutConstraint key", ^{
     expect([layoutConstraint description]).to.equal(description);
 });
 
+it(@"should print constraint key", ^{
+    MAS_VIEW *superview = MAS_VIEW.new;
+    MAS_VIEW *newView1 = MAS_VIEW.new;
+    newView1.mas_key = @"newView1";
+    MAS_VIEW *newView2 = MAS_VIEW.new;
+    newView2.mas_key = @"newView2";
+    [superview addSubview:newView1];
+    [superview addSubview:newView2];
+
+    [newView1 mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.left.greaterThanOrEqualTo(@[newView2, @10]).key(@"left");
+    }];
+
+
+    NSString *description = [NSString stringWithFormat:@"<MASLayoutConstraint:left[0] %@:newView1.left == %@:newView2.left>", MAS_VIEW.class, MAS_VIEW.class];
+    expect([superview.constraints[0] description]).to.equal(description);
+});
+
 SpecEnd