Эх сурвалжийг харах

rename installation methods, set delegate in init of MASCompositeConstraint

Jonas Budelmann 12 жил өмнө
parent
commit
cf2def3f65

+ 0 - 5
Masonry/MASCompositeConstraint.h

@@ -22,11 +22,6 @@ typedef NS_ENUM(NSInteger, MASCompositeConstraintType) {
  */
  */
 @interface MASCompositeConstraint : NSObject <MASConstraint>
 @interface MASCompositeConstraint : NSObject <MASConstraint>
 
 
-/**
- *	Usually MASConstraintMaker but could be a parent MASConstraint
- */
-@property (nonatomic, weak) id<MASConstraintDelegate> delegate;
-
 /**
 /**
  *	default first item for any child MASConstraints
  *	default first item for any child MASConstraints
  */
  */

+ 9 - 4
Masonry/MASCompositeConstraint.m

@@ -19,6 +19,8 @@
 
 
 @implementation MASCompositeConstraint
 @implementation MASCompositeConstraint
 
 
+@synthesize delegate = _delegate;
+
 - (id)initWithView:(UIView *)view type:(MASCompositeConstraintType)type {
 - (id)initWithView:(UIView *)view type:(MASCompositeConstraintType)type {
     self = [super init];
     self = [super init];
     if (!self) return nil;
     if (!self) return nil;
@@ -38,6 +40,9 @@
     _type = MASCompositeConstraintTypeUnknown;
     _type = MASCompositeConstraintTypeUnknown;
     _view = view;
     _view = view;
     _childConstraints = [children mutableCopy];
     _childConstraints = [children mutableCopy];
+    for (id<MASConstraint> constraint in _childConstraints) {
+        constraint.delegate = self;
+    }
 
 
     return self;
     return self;
 }
 }
@@ -213,15 +218,15 @@
 
 
 #pragma mark - MASConstraint
 #pragma mark - MASConstraint
 
 
-- (void)installConstraint {
+- (void)install {
     for (id<MASConstraint> constraint in self.childConstraints) {
     for (id<MASConstraint> constraint in self.childConstraints) {
-        [constraint installConstraint];
+        [constraint install];
     }
     }
 }
 }
 
 
-- (void)uninstallConstraint {
+- (void)uninstall {
     for (id<MASConstraint> constraint in self.childConstraints) {
     for (id<MASConstraint> constraint in self.childConstraints) {
-        [constraint uninstallConstraint];
+        [constraint uninstall];
     }
     }
 }
 }
 
 

+ 9 - 2
Masonry/MASConstraint.h

@@ -17,6 +17,8 @@ enum {
 };
 };
 typedef float MASLayoutPriority;
 typedef float MASLayoutPriority;
 
 
+@protocol MASConstraintDelegate;
+
 /**
 /**
  *	Enables Constraints to be created with chainable syntax
  *	Enables Constraints to be created with chainable syntax
  *  Constraint can represent single NSLayoutConstraint (MASViewConstraint) 
  *  Constraint can represent single NSLayoutConstraint (MASViewConstraint) 
@@ -24,6 +26,11 @@ typedef float MASLayoutPriority;
  */
  */
 @protocol MASConstraint <NSObject>
 @protocol MASConstraint <NSObject>
 
 
+/**
+ *	Usually MASConstraintMaker but could be a parent MASConstraint
+ */
+@property (nonatomic, weak) id<MASConstraintDelegate> delegate;
+
 /**
 /**
  *	Modifies the NSLayoutConstraint constant,
  *	Modifies the NSLayoutConstraint constant,
  *  only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 
  *  only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 
@@ -113,12 +120,12 @@ typedef float MASLayoutPriority;
 /**
 /**
  *	Creates a NSLayoutConstraint. The constraint is installed to the first view or the or the closest common superview of the first and second view. 
  *	Creates a NSLayoutConstraint. The constraint is installed to the first view or the or the closest common superview of the first and second view. 
  */
  */
-- (void)installConstraint;
+- (void)install;
 
 
 /**
 /**
  *	Removes previously installed NSLayoutConstraint
  *	Removes previously installed NSLayoutConstraint
  */
  */
-- (void)uninstallConstraint;
+- (void)uninstall;
 
 
 @end
 @end
 
 

+ 1 - 1
Masonry/MASConstraintMaker.m

@@ -32,7 +32,7 @@
 
 
 - (void)commit {
 - (void)commit {
     for (id<MASConstraint> constraint in self.constraints) {
     for (id<MASConstraint> constraint in self.constraints) {
-        [constraint installConstraint];
+        [constraint install];
     }
     }
     [self.constraints removeAllObjects];
     [self.constraints removeAllObjects];
 }
 }

+ 0 - 5
Masonry/MASViewConstraint.h

@@ -12,11 +12,6 @@
 
 
 @interface MASViewConstraint : NSObject <MASConstraint, NSCopying>
 @interface MASViewConstraint : NSObject <MASConstraint, NSCopying>
 
 
-/**
- *	Usually MASConstraintMaker but could be a parent MASConstraint
- */
-@property (nonatomic, weak) id<MASConstraintDelegate> delegate;
-
 /**
 /**
  *	First item/view and first attribute of the NSLayoutConstraint
  *	First item/view and first attribute of the NSLayoutConstraint
  */
  */

+ 4 - 2
Masonry/MASViewConstraint.m

@@ -26,6 +26,8 @@
 
 
 @implementation MASViewConstraint
 @implementation MASViewConstraint
 
 
+@synthesize delegate = _delegate;
+
 - (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute {
 - (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute {
     self = [super init];
     self = [super init];
     if (!self) return nil;
     if (!self) return nil;
@@ -241,7 +243,7 @@
 
 
 #pragma mark - MASConstraint
 #pragma mark - MASConstraint
 
 
-- (void)installConstraint {
+- (void)install {
     NSAssert(!self.hasBeenInstalled, @"Cannot install constraint more than once");
     NSAssert(!self.hasBeenInstalled, @"Cannot install constraint more than once");
     
     
     UIView *firstLayoutItem = self.firstViewAttribute.view;
     UIView *firstLayoutItem = self.firstViewAttribute.view;
@@ -291,7 +293,7 @@
     }
     }
 }
 }
 
 
-- (void)uninstallConstraint {
+- (void)uninstall {
     [self.installedView removeConstraint:self.layoutConstraint];
     [self.installedView removeConstraint:self.layoutConstraint];
     self.layoutConstraint = nil;
     self.layoutConstraint = nil;
     self.installedView = nil;
     self.installedView = nil;

+ 1 - 1
MasonryTests/MASCompositeConstraintSpec.m

@@ -125,7 +125,7 @@ it(@"should not remove on install", ^{
     //first equality statement
     //first equality statement
     composite.equalTo(newView).sizeOffset(CGSizeMake(90, 30));
     composite.equalTo(newView).sizeOffset(CGSizeMake(90, 30));
 
 
-    [composite installConstraint];
+    [composite install];
 
 
     expect(composite.childConstraints).to.haveCountOf(2);
     expect(composite.childConstraints).to.haveCountOf(2);
 });
 });

+ 5 - 5
MasonryTests/MASViewConstraintSpec.m

@@ -154,7 +154,7 @@ describe(@"create equality constraint", ^{
 describe(@"multiplier & constant", ^{
 describe(@"multiplier & constant", ^{
 
 
     it(@"should not allow update of multiplier after layoutconstraint is created", ^{
     it(@"should not allow update of multiplier after layoutconstraint is created", ^{
-        [constraint installConstraint];
+        [constraint install];
         
         
         expect(^{
         expect(^{
             constraint.percent(0.9);
             constraint.percent(0.9);
@@ -162,7 +162,7 @@ describe(@"multiplier & constant", ^{
     });
     });
     
     
     it(@"should allow update of constant after layoutconstraint is created", ^{
     it(@"should allow update of constant after layoutconstraint is created", ^{
-        [constraint installConstraint];
+        [constraint install];
         constraint.offset(10);
         constraint.offset(10);
         
         
         expect(constraint.layoutConstant).to.equal(10);
         expect(constraint.layoutConstant).to.equal(10);
@@ -228,7 +228,7 @@ describe(@"install", ^{
         constraint.percent(0.5);
         constraint.percent(0.5);
         constraint.offset(10);
         constraint.offset(10);
         constraint.priority(345);
         constraint.priority(345);
-        [constraint installConstraint];
+        [constraint install];
 
 
         expect(constraint.layoutConstraint.firstAttribute).to.equal(NSLayoutAttributeWidth);
         expect(constraint.layoutConstraint.firstAttribute).to.equal(NSLayoutAttributeWidth);
         expect(constraint.layoutConstraint.secondAttribute).to.equal(NSLayoutAttributeHeight);
         expect(constraint.layoutConstraint.secondAttribute).to.equal(NSLayoutAttributeHeight);
@@ -245,12 +245,12 @@ describe(@"install", ^{
     it(@"should uninstall constraint", ^{
     it(@"should uninstall constraint", ^{
         MASViewAttribute *secondViewAttribute = otherView.mas_height;
         MASViewAttribute *secondViewAttribute = otherView.mas_height;
         constraint.equalTo(secondViewAttribute);
         constraint.equalTo(secondViewAttribute);
-        [constraint installConstraint];
+        [constraint install];
 
 
         expect(superview.constraints).to.haveCountOf(1);
         expect(superview.constraints).to.haveCountOf(1);
         expect(superview.constraints[0]).to.equal(constraint.layoutConstraint);
         expect(superview.constraints[0]).to.equal(constraint.layoutConstraint);
 
 
-        [constraint uninstallConstraint];
+        [constraint uninstall];
         expect(superview.constraints).to.haveCountOf(0);
         expect(superview.constraints).to.haveCountOf(0);
     });
     });