Skip to content

Commit 7485b92

Browse files
author
Luc Dion
committed
more cleanup
1 parent 3b03920 commit 7485b92

File tree

5 files changed

+56
-57
lines changed

5 files changed

+56
-57
lines changed

MCSwiftLayout.xcodeproj/project.pbxproj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
249EFE841E64FB4C00165E39 /* MCSwiftLayout.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 249EFE7A1E64FB4C00165E39 /* MCSwiftLayout.framework */; };
2323
249EFE891E64FB4C00165E39 /* MCSwiftLayoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 249EFE881E64FB4C00165E39 /* MCSwiftLayoutTests.swift */; };
2424
249EFE8B1E64FB4C00165E39 /* MCSwiftLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 249EFE7D1E64FB4C00165E39 /* MCSwiftLayout.h */; settings = {ATTRIBUTES = (Public, ); }; };
25-
DF11A36F1E833EC2008B33E5 /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF11A36E1E833EC2008B33E5 /* View.swift */; };
2625
DF11A3711E833F03008B33E5 /* Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF11A3701E833F03008B33E5 /* Types.swift */; };
27-
DF11A3731E833F3C008B33E5 /* UIView+PinLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF11A3721E833F3C008B33E5 /* UIView+PinLayout.swift */; };
26+
DF11A3781E834B32008B33E5 /* UIView+PinLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF11A3771E834B32008B33E5 /* UIView+PinLayout.swift */; };
27+
DF11A37A1E834B3F008B33E5 /* Coordinates.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF11A3791E834B3F008B33E5 /* Coordinates.swift */; };
2828
/* End PBXBuildFile section */
2929

3030
/* Begin PBXContainerItemProxy section */
@@ -68,9 +68,9 @@
6868
249EFE831E64FB4C00165E39 /* MCSwiftLayoutTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MCSwiftLayoutTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
6969
249EFE881E64FB4C00165E39 /* MCSwiftLayoutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCSwiftLayoutTests.swift; sourceTree = "<group>"; };
7070
249EFE8A1E64FB4C00165E39 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
71-
DF11A36E1E833EC2008B33E5 /* View.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = View.swift; sourceTree = "<group>"; };
7271
DF11A3701E833F03008B33E5 /* Types.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Types.swift; sourceTree = "<group>"; };
73-
DF11A3721E833F3C008B33E5 /* UIView+PinLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+PinLayout.swift"; sourceTree = "<group>"; };
72+
DF11A3771E834B32008B33E5 /* UIView+PinLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIView+PinLayout.swift"; path = "Extensions/UIView+PinLayout.swift"; sourceTree = "<group>"; };
73+
DF11A3791E834B3F008B33E5 /* Coordinates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Coordinates.swift; path = Helpers/Coordinates.swift; sourceTree = "<group>"; };
7474
/* End PBXFileReference section */
7575

7676
/* Begin PBXFrameworksBuildPhase section */
@@ -129,6 +129,7 @@
129129
DF11A3751E834194008B33E5 /* Extensions */,
130130
DF11A3761E8341A2008B33E5 /* Helpers */,
131131
2439CC301E6659FA003326FB /* Layout.swift */,
132+
DF11A3701E833F03008B33E5 /* Types.swift */,
132133
);
133134
path = MCSwiftLayout;
134135
sourceTree = "<group>";
@@ -161,16 +162,15 @@
161162
DF11A3751E834194008B33E5 /* Extensions */ = {
162163
isa = PBXGroup;
163164
children = (
164-
DF11A3721E833F3C008B33E5 /* UIView+PinLayout.swift */,
165+
DF11A3771E834B32008B33E5 /* UIView+PinLayout.swift */,
165166
);
166167
name = Extensions;
167168
sourceTree = "<group>";
168169
};
169170
DF11A3761E8341A2008B33E5 /* Helpers */ = {
170171
isa = PBXGroup;
171172
children = (
172-
DF11A3701E833F03008B33E5 /* Types.swift */,
173-
DF11A36E1E833EC2008B33E5 /* View.swift */,
173+
DF11A3791E834B3F008B33E5 /* Coordinates.swift */,
174174
);
175175
name = Helpers;
176176
sourceTree = "<group>";
@@ -308,9 +308,9 @@
308308
buildActionMask = 2147483647;
309309
files = (
310310
DF11A3711E833F03008B33E5 /* Types.swift in Sources */,
311-
DF11A36F1E833EC2008B33E5 /* View.swift in Sources */,
312-
DF11A3731E833F3C008B33E5 /* UIView+PinLayout.swift in Sources */,
311+
DF11A3781E834B32008B33E5 /* UIView+PinLayout.swift in Sources */,
313312
2439CC311E6659FA003326FB /* Layout.swift in Sources */,
313+
DF11A37A1E834B3F008B33E5 /* Coordinates.swift in Sources */,
314314
);
315315
runOnlyForDeploymentPostprocessing = 0;
316316
};
File renamed without changes.
Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
import Foundation
1010

11-
internal class View {
12-
static func top(_ view: UIView) -> CGFloat {
13-
return view.frame.origin.y
14-
}
15-
16-
static func left(_ view: UIView) -> CGFloat {
17-
return view.frame.origin.x
18-
}
11+
internal class Coordinates {
12+
// static func top(_ view: UIView) -> CGFloat {
13+
// return view.frame.origin.y
14+
// }
15+
//
16+
// static func left(_ view: UIView) -> CGFloat {
17+
// return view.frame.origin.x
18+
// }
1919

2020
static func bottom(_ view: UIView) -> CGFloat {
2121
return view.frame.maxY
@@ -33,17 +33,16 @@ internal class View {
3333
return view.frame.origin.y + (view.frame.size.height / 2)
3434
}
3535

36-
static func size(_ view: UIView) -> CGSize {
37-
return view.frame.size
38-
}
39-
40-
static func width(_ view: UIView) -> CGFloat {
41-
return view.frame.size.width
42-
}
43-
44-
static func height(_ view: UIView) -> CGFloat {
45-
return view.frame.size.height
46-
}
36+
// static func size(_ view: UIView) -> CGSize {
37+
// return view.frame.size
38+
// }
39+
// static func width(_ view: UIView) -> CGFloat {
40+
// return view.frame.size.width
41+
// }
42+
//
43+
// static func height(_ view: UIView) -> CGFloat {
44+
// return view.frame.size.height
45+
// }
4746

4847
static func topLeft(_ view: UIView) -> CGPoint {
4948
return CGPoint(x: view.frame.origin.x, y: view.frame.origin.y)
@@ -81,29 +80,6 @@ internal class View {
8180
return CGPoint(x: view.frame.origin.x + view.frame.size.width, y: view.frame.origin.y + view.frame.size.height)
8281
}
8382

84-
static func coordinate(forEdge edge: EdgeType, of view: UIView) -> CGPoint {
85-
switch edge {
86-
case .top: return CGPoint(x: 0, y: view.frame.origin.y)
87-
case .left: return CGPoint(x: view.frame.origin.x, y: 0)
88-
case .bottom: return CGPoint(x: 0, y: bottom(view))
89-
case .right: return CGPoint(x: right(view), y: 0)
90-
}
91-
}
92-
93-
static func point(forPin pin: PinType, of view: UIView) -> CGPoint {
94-
switch pin {
95-
case .topLeft: return topLeft(view)
96-
case .topCenter: return topCenter(view)
97-
case .topRight: return topRight(view)
98-
case .leftCenter: return leftCenter(view)
99-
case .center: return center(view)
100-
case .rightCenter: return rightCenter(view)
101-
case .bottomLeft: return bottomLeft(view)
102-
case .bottomCenter: return bottomCenter(view)
103-
case .bottomRight: return bottomRight(view)
104-
}
105-
}
106-
10783
static let displayScale = UIScreen.main.scale
10884

10985
static func adjustRectToDisplayScale(_ rect: CGRect) -> CGRect {

MCSwiftLayout/Layout.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ public class Layout {
711711

712712
@discardableResult
713713
public func width(of view: UIView) -> Layout {
714-
return setWidth(View.width(view), context: { return "width(of: \(view))" })
714+
return setWidth(view.frame.size.width, context: { return "width(of: \(view))" })
715715
}
716716

717717
@discardableResult
@@ -721,7 +721,7 @@ public class Layout {
721721

722722
@discardableResult
723723
public func height(of view: UIView) -> Layout {
724-
return setHeight(View.height(view), context: { return "height(of: \(view))" })
724+
return setHeight(view.frame.size.height, context: { return "height(of: \(view))" })
725725
}
726726

727727
//
@@ -743,7 +743,7 @@ public class Layout {
743743

744744
if isSizeNotSet(context: context) {
745745
setWidth(viewSize.width, context: context)
746-
setHeight(View.height(view), context: context)
746+
setHeight(viewSize.height, context: context)
747747
}
748748
return self
749749
}
@@ -1045,7 +1045,7 @@ extension Layout {
10451045
guard let layoutSuperview = validateLayoutSuperview(context: context) else { return nil }
10461046
guard let relativeSuperview = relativeView.superview else { warn("relative view's superview is nil", context: context); return nil }
10471047

1048-
return computeCoordinates(View.point(forPin: pin, of: relativeView), layoutSuperview, relativeView, relativeSuperview)
1048+
return computeCoordinates(pin.point(for: relativeView), layoutSuperview, relativeView, relativeSuperview)
10491049
}
10501050

10511051
fileprivate func computeCoordinates(_ point: CGPoint, _ layoutSuperview: UIView, _ relativeView: UIView, _ relativeSuperview: UIView) -> CGPoint {
@@ -1060,7 +1060,7 @@ extension Layout {
10601060
guard let layoutSuperview = validateLayoutSuperview(context: context) else { return nil }
10611061
guard let relativeSuperview = relativeView.superview else { warn("relative view's superview is nil", context: context); return nil }
10621062

1063-
return computeCoordinates(View.coordinate(forEdge: edge, of: relativeView), layoutSuperview, relativeView, relativeSuperview)
1063+
return computeCoordinates(edge.point(for: relativeView), layoutSuperview, relativeView, relativeSuperview)
10641064
}
10651065

10661066
fileprivate func validateLayoutSuperview(context: Context) -> UIView? {
@@ -1149,7 +1149,7 @@ extension Layout {
11491149
newRect.size.height = height
11501150
}
11511151

1152-
view.frame = View.adjustRectToDisplayScale(newRect)
1152+
view.frame = Coordinates.adjustRectToDisplayScale(newRect)
11531153
}
11541154

11551155
fileprivate func computeSize() -> Size {

MCSwiftLayout/Types.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ public enum EdgeType: String {
2626
case left
2727
case bottom
2828
case right
29+
30+
func point(for view: UIView) -> CGPoint {
31+
switch self {
32+
case .top: return CGPoint(x: 0, y: view.frame.origin.y)
33+
case .left: return CGPoint(x: view.frame.origin.x, y: 0)
34+
case .bottom: return CGPoint(x: 0, y: Coordinates.bottom(view))
35+
case .right: return CGPoint(x: Coordinates.right(view), y: 0)
36+
}
37+
}
2938
}
3039

3140
public class HorizontalEdge {
@@ -76,6 +85,20 @@ enum PinType: String {
7685
case bottomLeft
7786
case bottomCenter
7887
case bottomRight
88+
89+
func point(for view: UIView) -> CGPoint {
90+
switch self {
91+
case .topLeft: return Coordinates.topLeft(view)
92+
case .topCenter: return Coordinates.topCenter(view)
93+
case .topRight: return Coordinates.topRight(view)
94+
case .leftCenter: return Coordinates.leftCenter(view)
95+
case .center: return Coordinates.center(view)
96+
case .rightCenter: return Coordinates.rightCenter(view)
97+
case .bottomLeft: return Coordinates.bottomLeft(view)
98+
case .bottomCenter: return Coordinates.bottomCenter(view)
99+
case .bottomRight: return Coordinates.bottomRight(view)
100+
}
101+
}
79102
}
80103

81104
public class Pin {

0 commit comments

Comments
 (0)