Skip to content

Commit

Permalink
LayoutItem Improvements (#13)
Browse files Browse the repository at this point in the history
* Improved Logic behind ConstrictoCore

* Bumped Spec

* Code Review

* Updated Project Structure
  • Loading branch information
pedrommcarrasco authored Sep 28, 2018
1 parent 55fd076 commit 6183848
Show file tree
Hide file tree
Showing 12 changed files with 428 additions and 375 deletions.
2 changes: 1 addition & 1 deletion Constrictor.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.swift_version = "4.2"
s.name = "Constrictor"
s.version = "3.0.0"
s.version = "3.0.1"
s.summary = "🐍 AutoLayout's µFramework"

s.description = "(Boe) Constrictor's AutoLayout µFramework with the goal of simplying your constraints by reducing the amount of code you have to write."
Expand Down
50 changes: 35 additions & 15 deletions Constrictor/Constrictor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
20D1F2BC20B35D4C00B327B7 /* Constrictable+ConstrictorCenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20D1F2BB20B35D4C00B327B7 /* Constrictable+ConstrictorCenter.swift */; };
20D1F2BE20B35FBC00B327B7 /* Constrictable+ConstrictorEdges.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20D1F2BD20B35FBC00B327B7 /* Constrictable+ConstrictorEdges.swift */; };
20D364DC20B6291000EF02B2 /* UIView+ConstrictorCenterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20D364DB20B6291000EF02B2 /* UIView+ConstrictorCenterTests.swift */; };
534B3A8D2139C680009D9F74 /* ItemLayoutAttributesDecoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 534B3A8C2139C680009D9F74 /* ItemLayoutAttributesDecoder.swift */; };
531188D8215E364D00148AF3 /* LayoutItemFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 531188D7215E364D00148AF3 /* LayoutItemFactory.swift */; };
537F0042213B424300BC0354 /* ConstantTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 537F0041213B424300BC0354 /* ConstantTests.swift */; };
539B841820B6C7DF00C85514 /* UIView+ConstrictorEdgesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 539B841720B6C7DF00C85514 /* UIView+ConstrictorEdgesTests.swift */; };
53CB882320B4618B002731A6 /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53CB882220B4618B002731A6 /* Constant.swift */; };
Expand All @@ -30,7 +30,8 @@
53D819A420B5A4E700E62D1E /* ConstraintIndex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53D819A320B5A4E700E62D1E /* ConstraintIndex.swift */; };
53D819A620B5A58800E62D1E /* UIView+Finder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53D819A520B5A58800E62D1E /* UIView+Finder.swift */; };
53D819AB20B5B1F300E62D1E /* ConstraintTestable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53D819AA20B5B1F300E62D1E /* ConstraintTestable.swift */; };
53ED274920BC012C00038282 /* ItemLayoutAttributesDecoderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53ED274820BC012C00038282 /* ItemLayoutAttributesDecoderTests.swift */; };
53E6F33C215D4C6200E0337E /* LayoutItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53E6F33B215D4C6200E0337E /* LayoutItem.swift */; };
53ED274920BC012C00038282 /* LayoutItemFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53ED274820BC012C00038282 /* LayoutItemFactoryTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -55,7 +56,7 @@
20D1F2BB20B35D4C00B327B7 /* Constrictable+ConstrictorCenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Constrictable+ConstrictorCenter.swift"; sourceTree = "<group>"; };
20D1F2BD20B35FBC00B327B7 /* Constrictable+ConstrictorEdges.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Constrictable+ConstrictorEdges.swift"; sourceTree = "<group>"; };
20D364DB20B6291000EF02B2 /* UIView+ConstrictorCenterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+ConstrictorCenterTests.swift"; sourceTree = "<group>"; };
534B3A8C2139C680009D9F74 /* ItemLayoutAttributesDecoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemLayoutAttributesDecoder.swift; sourceTree = "<group>"; };
531188D7215E364D00148AF3 /* LayoutItemFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutItemFactory.swift; sourceTree = "<group>"; };
537F0041213B424300BC0354 /* ConstantTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantTests.swift; sourceTree = "<group>"; };
539B841720B6C7DF00C85514 /* UIView+ConstrictorEdgesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+ConstrictorEdgesTests.swift"; sourceTree = "<group>"; };
53CB882220B4618B002731A6 /* Constant.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = "<group>"; };
Expand All @@ -70,7 +71,8 @@
53D819A320B5A4E700E62D1E /* ConstraintIndex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstraintIndex.swift; sourceTree = "<group>"; };
53D819A520B5A58800E62D1E /* UIView+Finder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Finder.swift"; sourceTree = "<group>"; };
53D819AA20B5B1F300E62D1E /* ConstraintTestable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstraintTestable.swift; sourceTree = "<group>"; };
53ED274820BC012C00038282 /* ItemLayoutAttributesDecoderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemLayoutAttributesDecoderTests.swift; sourceTree = "<group>"; };
53E6F33B215D4C6200E0337E /* LayoutItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutItem.swift; sourceTree = "<group>"; };
53ED274820BC012C00038282 /* LayoutItemFactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutItemFactoryTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -111,10 +113,6 @@
20D1F2B820B3501400B327B7 /* Extensions */ = {
isa = PBXGroup;
children = (
53CDE3CC20B3204D007E4AE0 /* Constrictable+Constrictor.swift */,
20BC12FC20B98A240034207F /* Constrictable+ConstrictorCore.swift */,
20D1F2BB20B35D4C00B327B7 /* Constrictable+ConstrictorCenter.swift */,
20D1F2BD20B35FBC00B327B7 /* Constrictable+ConstrictorEdges.swift */,
205B527D20BADEA50016C8B8 /* UIView+Constrictable.swift */,
205B527F20BADEB10016C8B8 /* UIViewController+Constrictable.swift */,
205B528820BAE5E20016C8B8 /* UILayoutGuide+Constrictable.swift */,
Expand All @@ -123,18 +121,37 @@
path = Extensions;
sourceTree = "<group>";
};
534B3A8B2139C61E009D9F74 /* Handlers */ = {
531188D9215E861400148AF3 /* Core */ = {
isa = PBXGroup;
children = (
20BC12FC20B98A240034207F /* Constrictable+ConstrictorCore.swift */,
);
path = Core;
sourceTree = "<group>";
};
531188DA215E862100148AF3 /* Sugar */ = {
isa = PBXGroup;
children = (
53CDE3CC20B3204D007E4AE0 /* Constrictable+Constrictor.swift */,
20D1F2BB20B35D4C00B327B7 /* Constrictable+ConstrictorCenter.swift */,
20D1F2BD20B35FBC00B327B7 /* Constrictable+ConstrictorEdges.swift */,
);
path = Sugar;
sourceTree = "<group>";
};
534B3A8B2139C61E009D9F74 /* Factory */ = {
isa = PBXGroup;
children = (
534B3A8C2139C680009D9F74 /* ItemLayoutAttributesDecoder.swift */,
531188D7215E364D00148AF3 /* LayoutItemFactory.swift */,
);
path = Handlers;
path = Factory;
sourceTree = "<group>";
};
53CB882120B46176002731A6 /* Structs */ = {
isa = PBXGroup;
children = (
53CB882220B4618B002731A6 /* Constant.swift */,
53E6F33B215D4C6200E0337E /* LayoutItem.swift */,
);
path = Structs;
sourceTree = "<group>";
Expand All @@ -160,7 +177,9 @@
53CDE3C020B3201E007E4AE0 /* Constrictor */ = {
isa = PBXGroup;
children = (
534B3A8B2139C61E009D9F74 /* Handlers */,
531188D9215E861400148AF3 /* Core */,
531188DA215E862100148AF3 /* Sugar */,
534B3A8B2139C61E009D9F74 /* Factory */,
205B528520BADF290016C8B8 /* Protocols */,
205B528420BADF220016C8B8 /* Enumerations */,
53CB882120B46176002731A6 /* Structs */,
Expand Down Expand Up @@ -240,7 +259,7 @@
53ED274720BC011800038282 /* Enumerations */ = {
isa = PBXGroup;
children = (
53ED274820BC012C00038282 /* ItemLayoutAttributesDecoderTests.swift */,
53ED274820BC012C00038282 /* LayoutItemFactoryTests.swift */,
);
path = Enumerations;
sourceTree = "<group>";
Expand Down Expand Up @@ -357,7 +376,8 @@
files = (
20D1F2BC20B35D4C00B327B7 /* Constrictable+ConstrictorCenter.swift in Sources */,
205B527E20BADEA50016C8B8 /* UIView+Constrictable.swift in Sources */,
534B3A8D2139C680009D9F74 /* ItemLayoutAttributesDecoder.swift in Sources */,
53E6F33C215D4C6200E0337E /* LayoutItem.swift in Sources */,
531188D8215E364D00148AF3 /* LayoutItemFactory.swift in Sources */,
205B528920BAE5E20016C8B8 /* UILayoutGuide+Constrictable.swift in Sources */,
202473B620BA14E9005693AC /* ConstrictorAttribute.swift in Sources */,
53CDE3CD20B3204D007E4AE0 /* Constrictable+Constrictor.swift in Sources */,
Expand All @@ -380,7 +400,7 @@
53D8199520B5818800E62D1E /* UIView+ConstrictorTests.swift in Sources */,
20D364DC20B6291000EF02B2 /* UIView+ConstrictorCenterTests.swift in Sources */,
53D819A420B5A4E700E62D1E /* ConstraintIndex.swift in Sources */,
53ED274920BC012C00038282 /* ItemLayoutAttributesDecoderTests.swift in Sources */,
53ED274920BC012C00038282 /* LayoutItemFactoryTests.swift in Sources */,
53D819AB20B5B1F300E62D1E /* ConstraintTestable.swift in Sources */,
539B841820B6C7DF00C85514 /* UIView+ConstrictorEdgesTests.swift in Sources */,
53D819A220B5A2CE00E62D1E /* NSLayoutAttribute+Finder.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,22 @@ extension Constrictable {
func constrict(_ selfAttribute: ConstrictorAttribute, relation: NSLayoutConstraint.Relation = .equal,
to item: Constrictable, attribute: ConstrictorAttribute, constant: Constant,
multiplier: CGFloat = 1.0, priority: UILayoutPriority = .required) {

let firstLayoutAttributes = ItemLayoutAttributesDecoder.itemLayoutAttribute(for: self, with: selfAttribute, and: constant)
let secondLayoutAttributes = ItemLayoutAttributesDecoder.itemLayoutAttribute(for: item, with: attribute, and: constant)

if let constrictableAsView = self as? UIView {
prepareForAutoLayout()

constrictableAsView.translatesAutoresizingMaskIntoConstraints = false
}
let items = LayoutItemFactory.makeLayoutItems(firstElement: self,
secondElement: item,
firstAttribute: selfAttribute,
secondAttribute: attribute,
constant: constant)


NSLayoutConstraint(item: self,
attribute: firstLayoutAttributes.layoutAttribute,
attribute: items.head.attribute,
relatedBy: relation,
toItem: secondLayoutAttributes.item,
attribute: secondLayoutAttributes.layoutAttribute,
toItem: items.tail.element,
attribute: items.tail.attribute,
multiplier: multiplier,
constant: firstLayoutAttributes.constant).isActive = true
constant: items.head.constant).isActive = true
}

/**
Expand All @@ -66,20 +65,28 @@ extension Constrictable {

func constrict(_ selfAttribute: ConstrictorAttribute, relation: NSLayoutConstraint.Relation = .equal,
constant: Constant, multiplier: CGFloat = 1.0, priority: UILayoutPriority = .required) {

let layoutAttributes = ItemLayoutAttributesDecoder.itemLayoutAttribute(for: self, with: selfAttribute, and: constant)

if let constrictableAsView = self as? UIView {

constrictableAsView.translatesAutoresizingMaskIntoConstraints = false
}
prepareForAutoLayout()

let item = LayoutItemFactory.makeLayoutItem(element: self,
attribute: selfAttribute,
constant: constant)

NSLayoutConstraint(item: self,
attribute: layoutAttributes.layoutAttribute,
attribute: item.attribute,
relatedBy: relation,
toItem: nil,
attribute: .notAnAttribute,
multiplier: multiplier,
constant: layoutAttributes.constant).isActive = true
constant: item.constant).isActive = true
}


func prepareForAutoLayout() {

if let constrictableAsView = self as? UIView {

constrictableAsView.translatesAutoresizingMaskIntoConstraints = false
}
}
}
Loading

0 comments on commit 6183848

Please sign in to comment.