Skip to content

Commit 6183848

Browse files
LayoutItem Improvements (#13)
* Improved Logic behind ConstrictoCore * Bumped Spec * Code Review * Updated Project Structure
1 parent 55fd076 commit 6183848

12 files changed

Lines changed: 428 additions & 375 deletions

Constrictor.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.swift_version = "4.2"
33
s.name = "Constrictor"
4-
s.version = "3.0.0"
4+
s.version = "3.0.1"
55
s.summary = "🐍 AutoLayout's µFramework"
66

77
s.description = "(Boe) Constrictor's AutoLayout µFramework with the goal of simplying your constraints by reducing the amount of code you have to write."

Constrictor/Constrictor.xcodeproj/project.pbxproj

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
20D1F2BC20B35D4C00B327B7 /* Constrictable+ConstrictorCenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20D1F2BB20B35D4C00B327B7 /* Constrictable+ConstrictorCenter.swift */; };
1919
20D1F2BE20B35FBC00B327B7 /* Constrictable+ConstrictorEdges.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20D1F2BD20B35FBC00B327B7 /* Constrictable+ConstrictorEdges.swift */; };
2020
20D364DC20B6291000EF02B2 /* UIView+ConstrictorCenterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20D364DB20B6291000EF02B2 /* UIView+ConstrictorCenterTests.swift */; };
21-
534B3A8D2139C680009D9F74 /* ItemLayoutAttributesDecoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 534B3A8C2139C680009D9F74 /* ItemLayoutAttributesDecoder.swift */; };
21+
531188D8215E364D00148AF3 /* LayoutItemFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 531188D7215E364D00148AF3 /* LayoutItemFactory.swift */; };
2222
537F0042213B424300BC0354 /* ConstantTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 537F0041213B424300BC0354 /* ConstantTests.swift */; };
2323
539B841820B6C7DF00C85514 /* UIView+ConstrictorEdgesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 539B841720B6C7DF00C85514 /* UIView+ConstrictorEdgesTests.swift */; };
2424
53CB882320B4618B002731A6 /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53CB882220B4618B002731A6 /* Constant.swift */; };
@@ -30,7 +30,8 @@
3030
53D819A420B5A4E700E62D1E /* ConstraintIndex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53D819A320B5A4E700E62D1E /* ConstraintIndex.swift */; };
3131
53D819A620B5A58800E62D1E /* UIView+Finder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53D819A520B5A58800E62D1E /* UIView+Finder.swift */; };
3232
53D819AB20B5B1F300E62D1E /* ConstraintTestable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53D819AA20B5B1F300E62D1E /* ConstraintTestable.swift */; };
33-
53ED274920BC012C00038282 /* ItemLayoutAttributesDecoderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53ED274820BC012C00038282 /* ItemLayoutAttributesDecoderTests.swift */; };
33+
53E6F33C215D4C6200E0337E /* LayoutItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53E6F33B215D4C6200E0337E /* LayoutItem.swift */; };
34+
53ED274920BC012C00038282 /* LayoutItemFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53ED274820BC012C00038282 /* LayoutItemFactoryTests.swift */; };
3435
/* End PBXBuildFile section */
3536

3637
/* Begin PBXContainerItemProxy section */
@@ -55,7 +56,7 @@
5556
20D1F2BB20B35D4C00B327B7 /* Constrictable+ConstrictorCenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Constrictable+ConstrictorCenter.swift"; sourceTree = "<group>"; };
5657
20D1F2BD20B35FBC00B327B7 /* Constrictable+ConstrictorEdges.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Constrictable+ConstrictorEdges.swift"; sourceTree = "<group>"; };
5758
20D364DB20B6291000EF02B2 /* UIView+ConstrictorCenterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+ConstrictorCenterTests.swift"; sourceTree = "<group>"; };
58-
534B3A8C2139C680009D9F74 /* ItemLayoutAttributesDecoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemLayoutAttributesDecoder.swift; sourceTree = "<group>"; };
59+
531188D7215E364D00148AF3 /* LayoutItemFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutItemFactory.swift; sourceTree = "<group>"; };
5960
537F0041213B424300BC0354 /* ConstantTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantTests.swift; sourceTree = "<group>"; };
6061
539B841720B6C7DF00C85514 /* UIView+ConstrictorEdgesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+ConstrictorEdgesTests.swift"; sourceTree = "<group>"; };
6162
53CB882220B4618B002731A6 /* Constant.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = "<group>"; };
@@ -70,7 +71,8 @@
7071
53D819A320B5A4E700E62D1E /* ConstraintIndex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstraintIndex.swift; sourceTree = "<group>"; };
7172
53D819A520B5A58800E62D1E /* UIView+Finder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Finder.swift"; sourceTree = "<group>"; };
7273
53D819AA20B5B1F300E62D1E /* ConstraintTestable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstraintTestable.swift; sourceTree = "<group>"; };
73-
53ED274820BC012C00038282 /* ItemLayoutAttributesDecoderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemLayoutAttributesDecoderTests.swift; sourceTree = "<group>"; };
74+
53E6F33B215D4C6200E0337E /* LayoutItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutItem.swift; sourceTree = "<group>"; };
75+
53ED274820BC012C00038282 /* LayoutItemFactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutItemFactoryTests.swift; sourceTree = "<group>"; };
7476
/* End PBXFileReference section */
7577

7678
/* Begin PBXFrameworksBuildPhase section */
@@ -111,10 +113,6 @@
111113
20D1F2B820B3501400B327B7 /* Extensions */ = {
112114
isa = PBXGroup;
113115
children = (
114-
53CDE3CC20B3204D007E4AE0 /* Constrictable+Constrictor.swift */,
115-
20BC12FC20B98A240034207F /* Constrictable+ConstrictorCore.swift */,
116-
20D1F2BB20B35D4C00B327B7 /* Constrictable+ConstrictorCenter.swift */,
117-
20D1F2BD20B35FBC00B327B7 /* Constrictable+ConstrictorEdges.swift */,
118116
205B527D20BADEA50016C8B8 /* UIView+Constrictable.swift */,
119117
205B527F20BADEB10016C8B8 /* UIViewController+Constrictable.swift */,
120118
205B528820BAE5E20016C8B8 /* UILayoutGuide+Constrictable.swift */,
@@ -123,18 +121,37 @@
123121
path = Extensions;
124122
sourceTree = "<group>";
125123
};
126-
534B3A8B2139C61E009D9F74 /* Handlers */ = {
124+
531188D9215E861400148AF3 /* Core */ = {
125+
isa = PBXGroup;
126+
children = (
127+
20BC12FC20B98A240034207F /* Constrictable+ConstrictorCore.swift */,
128+
);
129+
path = Core;
130+
sourceTree = "<group>";
131+
};
132+
531188DA215E862100148AF3 /* Sugar */ = {
133+
isa = PBXGroup;
134+
children = (
135+
53CDE3CC20B3204D007E4AE0 /* Constrictable+Constrictor.swift */,
136+
20D1F2BB20B35D4C00B327B7 /* Constrictable+ConstrictorCenter.swift */,
137+
20D1F2BD20B35FBC00B327B7 /* Constrictable+ConstrictorEdges.swift */,
138+
);
139+
path = Sugar;
140+
sourceTree = "<group>";
141+
};
142+
534B3A8B2139C61E009D9F74 /* Factory */ = {
127143
isa = PBXGroup;
128144
children = (
129-
534B3A8C2139C680009D9F74 /* ItemLayoutAttributesDecoder.swift */,
145+
531188D7215E364D00148AF3 /* LayoutItemFactory.swift */,
130146
);
131-
path = Handlers;
147+
path = Factory;
132148
sourceTree = "<group>";
133149
};
134150
53CB882120B46176002731A6 /* Structs */ = {
135151
isa = PBXGroup;
136152
children = (
137153
53CB882220B4618B002731A6 /* Constant.swift */,
154+
53E6F33B215D4C6200E0337E /* LayoutItem.swift */,
138155
);
139156
path = Structs;
140157
sourceTree = "<group>";
@@ -160,7 +177,9 @@
160177
53CDE3C020B3201E007E4AE0 /* Constrictor */ = {
161178
isa = PBXGroup;
162179
children = (
163-
534B3A8B2139C61E009D9F74 /* Handlers */,
180+
531188D9215E861400148AF3 /* Core */,
181+
531188DA215E862100148AF3 /* Sugar */,
182+
534B3A8B2139C61E009D9F74 /* Factory */,
164183
205B528520BADF290016C8B8 /* Protocols */,
165184
205B528420BADF220016C8B8 /* Enumerations */,
166185
53CB882120B46176002731A6 /* Structs */,
@@ -240,7 +259,7 @@
240259
53ED274720BC011800038282 /* Enumerations */ = {
241260
isa = PBXGroup;
242261
children = (
243-
53ED274820BC012C00038282 /* ItemLayoutAttributesDecoderTests.swift */,
262+
53ED274820BC012C00038282 /* LayoutItemFactoryTests.swift */,
244263
);
245264
path = Enumerations;
246265
sourceTree = "<group>";
@@ -357,7 +376,8 @@
357376
files = (
358377
20D1F2BC20B35D4C00B327B7 /* Constrictable+ConstrictorCenter.swift in Sources */,
359378
205B527E20BADEA50016C8B8 /* UIView+Constrictable.swift in Sources */,
360-
534B3A8D2139C680009D9F74 /* ItemLayoutAttributesDecoder.swift in Sources */,
379+
53E6F33C215D4C6200E0337E /* LayoutItem.swift in Sources */,
380+
531188D8215E364D00148AF3 /* LayoutItemFactory.swift in Sources */,
361381
205B528920BAE5E20016C8B8 /* UILayoutGuide+Constrictable.swift in Sources */,
362382
202473B620BA14E9005693AC /* ConstrictorAttribute.swift in Sources */,
363383
53CDE3CD20B3204D007E4AE0 /* Constrictable+Constrictor.swift in Sources */,
@@ -380,7 +400,7 @@
380400
53D8199520B5818800E62D1E /* UIView+ConstrictorTests.swift in Sources */,
381401
20D364DC20B6291000EF02B2 /* UIView+ConstrictorCenterTests.swift in Sources */,
382402
53D819A420B5A4E700E62D1E /* ConstraintIndex.swift in Sources */,
383-
53ED274920BC012C00038282 /* ItemLayoutAttributesDecoderTests.swift in Sources */,
403+
53ED274920BC012C00038282 /* LayoutItemFactoryTests.swift in Sources */,
384404
53D819AB20B5B1F300E62D1E /* ConstraintTestable.swift in Sources */,
385405
539B841820B6C7DF00C85514 /* UIView+ConstrictorEdgesTests.swift in Sources */,
386406
53D819A220B5A2CE00E62D1E /* NSLayoutAttribute+Finder.swift in Sources */,

Constrictor/Constrictor/Extensions/Constrictable+ConstrictorCore.swift renamed to Constrictor/Constrictor/Core/Constrictable+ConstrictorCore.swift

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,22 @@ extension Constrictable {
3030
func constrict(_ selfAttribute: ConstrictorAttribute, relation: NSLayoutConstraint.Relation = .equal,
3131
to item: Constrictable, attribute: ConstrictorAttribute, constant: Constant,
3232
multiplier: CGFloat = 1.0, priority: UILayoutPriority = .required) {
33-
34-
let firstLayoutAttributes = ItemLayoutAttributesDecoder.itemLayoutAttribute(for: self, with: selfAttribute, and: constant)
35-
let secondLayoutAttributes = ItemLayoutAttributesDecoder.itemLayoutAttribute(for: item, with: attribute, and: constant)
3633

37-
if let constrictableAsView = self as? UIView {
34+
prepareForAutoLayout()
3835

39-
constrictableAsView.translatesAutoresizingMaskIntoConstraints = false
40-
}
36+
let items = LayoutItemFactory.makeLayoutItems(firstElement: self,
37+
secondElement: item,
38+
firstAttribute: selfAttribute,
39+
secondAttribute: attribute,
40+
constant: constant)
4141

42-
4342
NSLayoutConstraint(item: self,
44-
attribute: firstLayoutAttributes.layoutAttribute,
43+
attribute: items.head.attribute,
4544
relatedBy: relation,
46-
toItem: secondLayoutAttributes.item,
47-
attribute: secondLayoutAttributes.layoutAttribute,
45+
toItem: items.tail.element,
46+
attribute: items.tail.attribute,
4847
multiplier: multiplier,
49-
constant: firstLayoutAttributes.constant).isActive = true
48+
constant: items.head.constant).isActive = true
5049
}
5150

5251
/**
@@ -66,20 +65,28 @@ extension Constrictable {
6665

6766
func constrict(_ selfAttribute: ConstrictorAttribute, relation: NSLayoutConstraint.Relation = .equal,
6867
constant: Constant, multiplier: CGFloat = 1.0, priority: UILayoutPriority = .required) {
69-
70-
let layoutAttributes = ItemLayoutAttributesDecoder.itemLayoutAttribute(for: self, with: selfAttribute, and: constant)
71-
72-
if let constrictableAsView = self as? UIView {
7368

74-
constrictableAsView.translatesAutoresizingMaskIntoConstraints = false
75-
}
69+
prepareForAutoLayout()
70+
71+
let item = LayoutItemFactory.makeLayoutItem(element: self,
72+
attribute: selfAttribute,
73+
constant: constant)
7674

7775
NSLayoutConstraint(item: self,
78-
attribute: layoutAttributes.layoutAttribute,
76+
attribute: item.attribute,
7977
relatedBy: relation,
8078
toItem: nil,
8179
attribute: .notAnAttribute,
8280
multiplier: multiplier,
83-
constant: layoutAttributes.constant).isActive = true
81+
constant: item.constant).isActive = true
82+
}
83+
84+
85+
func prepareForAutoLayout() {
86+
87+
if let constrictableAsView = self as? UIView {
88+
89+
constrictableAsView.translatesAutoresizingMaskIntoConstraints = false
90+
}
8491
}
8592
}

0 commit comments

Comments
 (0)