Skip to content

Commit e983a38

Browse files
committed
move edges/size/center to MASLayoutConstraint protocol
1 parent 08e05b1 commit e983a38

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

Masonry/MASConstraintMaker.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,27 @@ typedef NS_OPTIONS(NSInteger, MASAttribute) {
5353
@property (nonatomic, strong, readonly) MASConstraint *centerX;
5454
@property (nonatomic, strong, readonly) MASConstraint *centerY;
5555

56+
/**
57+
* Creates a MASCompositeConstraint with type MASCompositeConstraintTypeEdges
58+
* which generates the appropriate MASViewConstraint children (top, left, bottom, right)
59+
* with the first item set to the makers associated view
60+
*/
61+
@property (nonatomic, strong, readonly) MASConstraint *edges;
62+
63+
/**
64+
* Creates a MASCompositeConstraint with type MASCompositeConstraintTypeSize
65+
* which generates the appropriate MASViewConstraint children (width, height)
66+
* with the first item set to the makers associated view
67+
*/
68+
@property (nonatomic, strong, readonly) MASConstraint *size;
69+
70+
/**
71+
* Creates a MASCompositeConstraint with type MASCompositeConstraintTypeCenter
72+
* which generates the appropriate MASViewConstraint children (centerX, centerY)
73+
* with the first item set to the makers associated view
74+
*/
75+
@property (nonatomic, strong, readonly) MASConstraint *center;
76+
5677
@end
5778

5879
/**

Masonry/MASConstraintMaker.m

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
#import "MASConstraint+Private.h"
1313
#import "MASViewAttribute.h"
1414
#import "View+MASAdditions.h"
15+
#import "LayoutGuide+MASAdditions.h"
1516

1617
@interface MASConstraintMaker () <MASConstraintDelegate>
1718

1819
@property (nonatomic, weak) MAS_VIEW *view;
19-
@property (nonatomic, weak) id item;
20+
@property (nonatomic, weak) MASLayoutGuide *item;
2021
@property (nonatomic, strong) NSMutableArray *constraints;
2122

2223
@end
@@ -95,17 +96,19 @@ - (MASConstraint *)addConstraintWithAttributes:(MASAttribute)attrs {
9596
NSAssert((attrs & anyAttribute) != 0, @"You didn't pass any attribute to make.attributes(...)");
9697

9798
NSMutableArray *attributes = [NSMutableArray array];
99+
100+
#define layoutItem (self.item ?: self.view)
98101

99-
if (attrs & MASAttributeLeft) [attributes addObject:self.view.mas_left];
100-
if (attrs & MASAttributeRight) [attributes addObject:self.view.mas_right];
101-
if (attrs & MASAttributeTop) [attributes addObject:self.view.mas_top];
102-
if (attrs & MASAttributeBottom) [attributes addObject:self.view.mas_bottom];
103-
if (attrs & MASAttributeLeading) [attributes addObject:self.view.mas_leading];
104-
if (attrs & MASAttributeTrailing) [attributes addObject:self.view.mas_trailing];
105-
if (attrs & MASAttributeWidth) [attributes addObject:self.view.mas_width];
106-
if (attrs & MASAttributeHeight) [attributes addObject:self.view.mas_height];
107-
if (attrs & MASAttributeCenterX) [attributes addObject:self.view.mas_centerX];
108-
if (attrs & MASAttributeCenterY) [attributes addObject:self.view.mas_centerY];
102+
if (attrs & MASAttributeLeft) [attributes addObject:layoutItem.mas_left];
103+
if (attrs & MASAttributeRight) [attributes addObject:layoutItem.mas_right];
104+
if (attrs & MASAttributeTop) [attributes addObject:layoutItem.mas_top];
105+
if (attrs & MASAttributeBottom) [attributes addObject:layoutItem.mas_bottom];
106+
if (attrs & MASAttributeLeading) [attributes addObject:layoutItem.mas_leading];
107+
if (attrs & MASAttributeTrailing) [attributes addObject:layoutItem.mas_trailing];
108+
if (attrs & MASAttributeWidth) [attributes addObject:layoutItem.mas_width];
109+
if (attrs & MASAttributeHeight) [attributes addObject:layoutItem.mas_height];
110+
if (attrs & MASAttributeCenterX) [attributes addObject:layoutItem.mas_centerX];
111+
if (attrs & MASAttributeCenterY) [attributes addObject:layoutItem.mas_centerY];
109112
if (attrs & MASAttributeBaseline) [attributes addObject:self.view.mas_baseline];
110113
if (attrs & MASAttributeFirstBaseline) [attributes addObject:self.view.mas_firstBaseline];
111114
if (attrs & MASAttributeLastBaseline) [attributes addObject:self.view.mas_lastBaseline];

0 commit comments

Comments
 (0)