Skip to content

Commit 91b6f93

Browse files
committed
add shorthand for MASLayoutGuide
1 parent 3116754 commit 91b6f93

9 files changed

+131
-45
lines changed

Masonry.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
1539A4A42665991900892F49 /* LayoutGuide+MASShorthandAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1539A4A22665991900892F49 /* LayoutGuide+MASShorthandAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
1011
15E414912663780600D3D1B6 /* LayoutGuide+MASAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 15E4148F2663780600D3D1B6 /* LayoutGuide+MASAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
1112
15E414922663780600D3D1B6 /* LayoutGuide+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 15E414902663780600D3D1B6 /* LayoutGuide+MASAdditions.m */; };
1213
3AED05BD1AD59FD40053CC65 /* Masonry.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AED05BC1AD59FD40053CC65 /* Masonry.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -37,6 +38,7 @@
3738
/* End PBXBuildFile section */
3839

3940
/* Begin PBXFileReference section */
41+
1539A4A22665991900892F49 /* LayoutGuide+MASShorthandAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LayoutGuide+MASShorthandAdditions.h"; sourceTree = "<group>"; };
4042
15E4148F2663780600D3D1B6 /* LayoutGuide+MASAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LayoutGuide+MASAdditions.h"; sourceTree = "<group>"; };
4143
15E414902663780600D3D1B6 /* LayoutGuide+MASAdditions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "LayoutGuide+MASAdditions.m"; sourceTree = "<group>"; };
4244
3AED05B71AD59FD40053CC65 /* Masonry.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Masonry.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -107,6 +109,7 @@
107109
4473548C1B39F772004DACCB /* ViewController+MASAdditions.m */,
108110
15E4148F2663780600D3D1B6 /* LayoutGuide+MASAdditions.h */,
109111
15E414902663780600D3D1B6 /* LayoutGuide+MASAdditions.m */,
112+
1539A4A22665991900892F49 /* LayoutGuide+MASShorthandAdditions.h */,
110113
3AED05EA1AD5A0470053CC65 /* NSArray+MASAdditions.h */,
111114
3AED05EB1AD5A0470053CC65 /* NSArray+MASAdditions.m */,
112115
3AED05EC1AD5A0470053CC65 /* NSArray+MASShorthandAdditions.h */,
@@ -149,6 +152,7 @@
149152
3AED06071AD5A0470053CC65 /* View+MASShorthandAdditions.h in Headers */,
150153
4473548D1B39F772004DACCB /* ViewController+MASAdditions.h in Headers */,
151154
15E414912663780600D3D1B6 /* LayoutGuide+MASAdditions.h in Headers */,
155+
1539A4A42665991900892F49 /* LayoutGuide+MASShorthandAdditions.h in Headers */,
152156
3AED05FC1AD5A0470053CC65 /* MASViewAttribute.h in Headers */,
153157
3AED05BD1AD59FD40053CC65 /* Masonry.h in Headers */,
154158
3AED05F91AD5A0470053CC65 /* MASLayoutConstraint.h in Headers */,

Masonry/LayoutGuide+MASAdditions.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// NSLayoutGuide+MASAdditions.h
2+
// LayoutGuide+MASAdditions.h
33
// Masonry
44
//
55
// Created by v on 2021/5/30.
@@ -26,6 +26,8 @@ API_AVAILABLE(macos(10.11), ios(9.0))
2626
@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerX;
2727
@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY;
2828

29+
@property (nonatomic, strong, readonly) MASViewAttribute *(^mas_attribute)(NSLayoutAttribute attr);
30+
2931
/**
3032
* Creates a MASConstraintMaker with the callee view.
3133
* Any constraints defined are added to the view or the appropriate superview once the block has finished executing

Masonry/LayoutGuide+MASAdditions.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// NSLayoutGuide+MASAdditions.m
2+
// LayoutGuide+MASAdditions.m
33
// Masonry
44
//
55
// Created by v on 2021/5/30.
@@ -77,4 +77,10 @@ - (MASViewAttribute *)mas_centerY {
7777
return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeCenterY];
7878
}
7979

80+
- (MASViewAttribute *(^)(NSLayoutAttribute))mas_attribute {
81+
return ^(NSLayoutAttribute attr) {
82+
return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:attr];
83+
};
84+
}
85+
8086
@end
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//
2+
// LayoutGuide+MASShorthandAdditions.h
3+
// Masonry
4+
//
5+
// Created by v on 2021/6/1.
6+
// Copyright © 2021 Jonas Budelmann. All rights reserved.
7+
//
8+
9+
#import "LayoutGuide+MASAdditions.h"
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
#ifdef MAS_SHORTHAND
14+
15+
/**
16+
* Shorthand view additions without the 'mas_' prefixes,
17+
* only enabled if MAS_SHORTHAND is defined
18+
*/
19+
API_AVAILABLE(macos(10.11), ios(9.0))
20+
@interface MASLayoutGuide (MASShorthandAdditions)
21+
22+
@property (nonatomic, strong, readonly) MASViewAttribute *left;
23+
@property (nonatomic, strong, readonly) MASViewAttribute *top;
24+
@property (nonatomic, strong, readonly) MASViewAttribute *right;
25+
@property (nonatomic, strong, readonly) MASViewAttribute *bottom;
26+
@property (nonatomic, strong, readonly) MASViewAttribute *leading;
27+
@property (nonatomic, strong, readonly) MASViewAttribute *trailing;
28+
@property (nonatomic, strong, readonly) MASViewAttribute *width;
29+
@property (nonatomic, strong, readonly) MASViewAttribute *height;
30+
@property (nonatomic, strong, readonly) MASViewAttribute *centerX;
31+
@property (nonatomic, strong, readonly) MASViewAttribute *centerY;
32+
33+
@property (nonatomic, strong, readonly) MASViewAttribute *(^attribute)(NSLayoutAttribute attr);
34+
35+
- (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
36+
- (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block;
37+
- (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block;
38+
39+
@end
40+
41+
@implementation MASLayoutGuide (MASShorthandAdditions)
42+
43+
MAS_ATTR_FORWARD(top);
44+
MAS_ATTR_FORWARD(left);
45+
MAS_ATTR_FORWARD(bottom);
46+
MAS_ATTR_FORWARD(right);
47+
MAS_ATTR_FORWARD(leading);
48+
MAS_ATTR_FORWARD(trailing);
49+
MAS_ATTR_FORWARD(width);
50+
MAS_ATTR_FORWARD(height);
51+
MAS_ATTR_FORWARD(centerX);
52+
MAS_ATTR_FORWARD(centerY);
53+
54+
- (MASViewAttribute *(^)(NSLayoutAttribute))attribute {
55+
return [self mas_attribute];
56+
}
57+
58+
- (NSArray *)makeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block {
59+
return [self mas_makeConstraints:block];
60+
}
61+
62+
- (NSArray *)updateConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block {
63+
return [self mas_updateConstraints:block];
64+
}
65+
66+
- (NSArray *)remakeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block {
67+
return [self mas_remakeConstraints:block];
68+
}
69+
70+
@end
71+
72+
#endif
73+
74+
NS_ASSUME_NONNULL_END

Masonry/MASUtilities.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,13 @@ static inline id _MASBoxValue(const char *type, ...) {
136136
}
137137

138138
#define MASBoxValue(value) _MASBoxValue(@encode(__typeof__((value))), (value))
139+
140+
#define MAS_ATTR_FORWARD(attr) \
141+
- (MASViewAttribute *)attr { \
142+
return [self mas_##attr]; \
143+
}
144+
145+
#define MAS_ATTR_FORWARD_AVAILABLE(attr, available) \
146+
- (MASViewAttribute *)attr available { \
147+
return [self mas_##attr]; \
148+
}

Masonry/Masonry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ FOUNDATION_EXPORT const unsigned char MasonryVersionString[];
1919
#import "View+MASShorthandAdditions.h"
2020
#import "ViewController+MASAdditions.h"
2121
#import "LayoutGuide+MASAdditions.h"
22+
#import "LayoutGuide+MASShorthandAdditions.h"
2223
#import "NSArray+MASAdditions.h"
2324
#import "NSArray+MASShorthandAdditions.h"
2425
#import "MASConstraint.h"

Masonry/View+MASAdditions.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@
4646
@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerXWithinMargins;
4747
@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerYWithinMargins;
4848

49-
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuide NS_AVAILABLE_IOS(11.0);
50-
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeading NS_AVAILABLE_IOS(11.0);
51-
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTrailing NS_AVAILABLE_IOS(11.0);
52-
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeft NS_AVAILABLE_IOS(11.0);
53-
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideRight NS_AVAILABLE_IOS(11.0);
54-
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTop NS_AVAILABLE_IOS(11.0);
55-
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideBottom NS_AVAILABLE_IOS(11.0);
56-
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideWidth NS_AVAILABLE_IOS(11.0);
57-
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideHeight NS_AVAILABLE_IOS(11.0);
58-
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideCenterX NS_AVAILABLE_IOS(11.0);
59-
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideCenterY NS_AVAILABLE_IOS(11.0);
49+
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuide API_AVAILABLE(ios(11.0));
50+
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeading API_AVAILABLE(ios(11.0));
51+
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTrailing API_AVAILABLE(ios(11.0));
52+
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeft API_AVAILABLE(ios(11.0));
53+
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideRight API_AVAILABLE(ios(11.0));
54+
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTop API_AVAILABLE(ios(11.0));
55+
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideBottom API_AVAILABLE(ios(11.0));
56+
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideWidth API_AVAILABLE(ios(11.0));
57+
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideHeight API_AVAILABLE(ios(11.0));
58+
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideCenterX API_AVAILABLE(ios(11.0));
59+
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideCenterY API_AVAILABLE(ios(11.0));
6060

6161
#endif
6262

Masonry/View+MASAdditions.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ - (MASViewAttribute *)mas_baseline {
8080
return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLastBaseline];
8181
}
8282

83-
- (MASViewAttribute *(^)(NSLayoutAttribute))mas_attribute
84-
{
83+
- (MASViewAttribute *(^)(NSLayoutAttribute))mas_attribute {
8584
return ^(NSLayoutAttribute attr) {
8685
return [[MASViewAttribute alloc] initWithView:self layoutAttribute:attr];
8786
};

Masonry/View+MASShorthandAdditions.h

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@
4747

4848
#if TARGET_OS_IPHONE || TARGET_OS_TV
4949

50-
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideLeading NS_AVAILABLE_IOS(11.0);
51-
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideTrailing NS_AVAILABLE_IOS(11.0);
52-
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideLeft NS_AVAILABLE_IOS(11.0);
53-
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideRight NS_AVAILABLE_IOS(11.0);
54-
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideTop NS_AVAILABLE_IOS(11.0);
55-
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideBottom NS_AVAILABLE_IOS(11.0);
56-
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideWidth NS_AVAILABLE_IOS(11.0);
57-
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideHeight NS_AVAILABLE_IOS(11.0);
58-
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideCenterX NS_AVAILABLE_IOS(11.0);
59-
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideCenterY NS_AVAILABLE_IOS(11.0);
50+
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideLeading API_AVAILABLE(ios(11.0));
51+
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideTrailing API_AVAILABLE(ios(11.0));
52+
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideLeft API_AVAILABLE(ios(11.0));
53+
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideRight API_AVAILABLE(ios(11.0));
54+
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideTop API_AVAILABLE(ios(11.0));
55+
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideBottom API_AVAILABLE(ios(11.0));
56+
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideWidth API_AVAILABLE(ios(11.0));
57+
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideHeight API_AVAILABLE(ios(11.0));
58+
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideCenterX API_AVAILABLE(ios(11.0));
59+
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideCenterY API_AVAILABLE(ios(11.0));
6060

6161
#endif
6262

@@ -66,16 +66,6 @@
6666

6767
@end
6868

69-
#define MAS_ATTR_FORWARD(attr) \
70-
- (MASViewAttribute *)attr { \
71-
return [self mas_##attr]; \
72-
}
73-
74-
#define MAS_ATTR_FORWARD_AVAILABLE(attr, available) \
75-
- (MASViewAttribute *)attr available { \
76-
return [self mas_##attr]; \
77-
}
78-
7969
@implementation MAS_VIEW (MASShorthandAdditions)
8070

8171
MAS_ATTR_FORWARD(top);
@@ -104,16 +94,16 @@ MAS_ATTR_FORWARD(trailingMargin);
10494
MAS_ATTR_FORWARD(centerXWithinMargins);
10595
MAS_ATTR_FORWARD(centerYWithinMargins);
10696

107-
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideLeading, NS_AVAILABLE_IOS(11.0));
108-
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideTrailing, NS_AVAILABLE_IOS(11.0));
109-
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideLeft, NS_AVAILABLE_IOS(11.0));
110-
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideRight, NS_AVAILABLE_IOS(11.0));
111-
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideTop, NS_AVAILABLE_IOS(11.0));
112-
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideBottom, NS_AVAILABLE_IOS(11.0));
113-
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideWidth, NS_AVAILABLE_IOS(11.0));
114-
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideHeight, NS_AVAILABLE_IOS(11.0));
115-
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideCenterX, NS_AVAILABLE_IOS(11.0));
116-
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideCenterY, NS_AVAILABLE_IOS(11.0));
97+
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideLeading, API_AVAILABLE(ios(11.0)));
98+
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideTrailing, API_AVAILABLE(ios(11.0)));
99+
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideLeft, API_AVAILABLE(ios(11.0)));
100+
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideRight, API_AVAILABLE(ios(11.0)));
101+
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideTop, API_AVAILABLE(ios(11.0)));
102+
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideBottom, API_AVAILABLE(ios(11.0)));
103+
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideWidth, API_AVAILABLE(ios(11.0)));
104+
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideHeight, API_AVAILABLE(ios(11.0)));
105+
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideCenterX, API_AVAILABLE(ios(11.0)));
106+
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideCenterY, API_AVAILABLE(ios(11.0)));
117107

118108
#endif
119109

0 commit comments

Comments
 (0)