Authored by Jonas Budelmann

rename installation methods, set delegate in init of MASCompositeConstraint

... ... @@ -23,11 +23,6 @@ typedef NS_ENUM(NSInteger, MASCompositeConstraintType) {
@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
*/
@property (nonatomic, weak, readonly) UIView *view;
... ...
... ... @@ -19,6 +19,8 @@
@implementation MASCompositeConstraint
@synthesize delegate = _delegate;
- (id)initWithView:(UIView *)view type:(MASCompositeConstraintType)type {
self = [super init];
if (!self) return nil;
... ... @@ -38,6 +40,9 @@
_type = MASCompositeConstraintTypeUnknown;
_view = view;
_childConstraints = [children mutableCopy];
for (id<MASConstraint> constraint in _childConstraints) {
constraint.delegate = self;
}
return self;
}
... ... @@ -213,15 +218,15 @@
#pragma mark - MASConstraint
- (void)installConstraint {
- (void)install {
for (id<MASConstraint> constraint in self.childConstraints) {
[constraint installConstraint];
[constraint install];
}
}
- (void)uninstallConstraint {
- (void)uninstall {
for (id<MASConstraint> constraint in self.childConstraints) {
[constraint uninstallConstraint];
[constraint uninstall];
}
}
... ...
... ... @@ -17,6 +17,8 @@ enum {
};
typedef float MASLayoutPriority;
@protocol MASConstraintDelegate;
/**
* Enables Constraints to be created with chainable syntax
* Constraint can represent single NSLayoutConstraint (MASViewConstraint)
... ... @@ -25,6 +27,11 @@ typedef float MASLayoutPriority;
@protocol MASConstraint <NSObject>
/**
* Usually MASConstraintMaker but could be a parent MASConstraint
*/
@property (nonatomic, weak) id<MASConstraintDelegate> delegate;
/**
* Modifies the NSLayoutConstraint constant,
* only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
* NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
... ... @@ -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.
*/
- (void)installConstraint;
- (void)install;
/**
* Removes previously installed NSLayoutConstraint
*/
- (void)uninstallConstraint;
- (void)uninstall;
@end
... ...
... ... @@ -32,7 +32,7 @@
- (void)commit {
for (id<MASConstraint> constraint in self.constraints) {
[constraint installConstraint];
[constraint install];
}
[self.constraints removeAllObjects];
}
... ...
... ... @@ -13,11 +13,6 @@
@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
*/
@property (nonatomic, strong, readonly) MASViewAttribute *firstViewAttribute;
... ...
... ... @@ -26,6 +26,8 @@
@implementation MASViewConstraint
@synthesize delegate = _delegate;
- (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute {
self = [super init];
if (!self) return nil;
... ... @@ -241,7 +243,7 @@
#pragma mark - MASConstraint
- (void)installConstraint {
- (void)install {
NSAssert(!self.hasBeenInstalled, @"Cannot install constraint more than once");
UIView *firstLayoutItem = self.firstViewAttribute.view;
... ... @@ -291,7 +293,7 @@
}
}
- (void)uninstallConstraint {
- (void)uninstall {
[self.installedView removeConstraint:self.layoutConstraint];
self.layoutConstraint = nil;
self.installedView = nil;
... ...
... ... @@ -125,7 +125,7 @@ it(@"should not remove on install", ^{
//first equality statement
composite.equalTo(newView).sizeOffset(CGSizeMake(90, 30));
[composite installConstraint];
[composite install];
expect(composite.childConstraints).to.haveCountOf(2);
});
... ...
... ... @@ -154,7 +154,7 @@ describe(@"create equality constraint", ^{
describe(@"multiplier & constant", ^{
it(@"should not allow update of multiplier after layoutconstraint is created", ^{
[constraint installConstraint];
[constraint install];
expect(^{
constraint.percent(0.9);
... ... @@ -162,7 +162,7 @@ describe(@"multiplier & constant", ^{
});
it(@"should allow update of constant after layoutconstraint is created", ^{
[constraint installConstraint];
[constraint install];
constraint.offset(10);
expect(constraint.layoutConstant).to.equal(10);
... ... @@ -228,7 +228,7 @@ describe(@"install", ^{
constraint.percent(0.5);
constraint.offset(10);
constraint.priority(345);
[constraint installConstraint];
[constraint install];
expect(constraint.layoutConstraint.firstAttribute).to.equal(NSLayoutAttributeWidth);
expect(constraint.layoutConstraint.secondAttribute).to.equal(NSLayoutAttributeHeight);
... ... @@ -245,12 +245,12 @@ describe(@"install", ^{
it(@"should uninstall constraint", ^{
MASViewAttribute *secondViewAttribute = otherView.mas_height;
constraint.equalTo(secondViewAttribute);
[constraint installConstraint];
[constraint install];
expect(superview.constraints).to.haveCountOf(1);
expect(superview.constraints[0]).to.equal(constraint.layoutConstraint);
[constraint uninstallConstraint];
[constraint uninstall];
expect(superview.constraints).to.haveCountOf(0);
});
... ...