Skip to content

Commit 53376df

Browse files
author
Luc Dion
committed
All access to view's bound or frame now always use Coordinates.getRect(..)
1 parent 41152df commit 53376df

File tree

6 files changed

+52
-48
lines changed

6 files changed

+52
-48
lines changed

PinLayout.xcodeproj/project.pbxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
DFCA5F1620111E0B00180CD7 /* UIScrollViewSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFCA5F1420111BCF00180CD7 /* UIScrollViewSpec.swift */; };
102102
DFEAF71220C8081800E33147 /* PinLayoutImpl+Size.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFEAF71120C8081800E33147 /* PinLayoutImpl+Size.swift */; };
103103
DFEAF75020C9661B00E33147 /* ObjectiveCSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DFEAF74D20C965DC00E33147 /* ObjectiveCSpec.m */; };
104-
DFEAF75120C9661C00E33147 /* ObjectiveCSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DFEAF74D20C965DC00E33147 /* ObjectiveCSpec.m */; };
105104
DFEAF75220C9661D00E33147 /* ObjectiveCSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DFEAF74D20C965DC00E33147 /* ObjectiveCSpec.m */; };
106105
DFEAF75320C9667C00E33147 /* PinLayoutImpl+Size.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFEAF71120C8081800E33147 /* PinLayoutImpl+Size.swift */; };
107106
DFEAF75420C9667D00E33147 /* PinLayoutImpl+Size.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFEAF71120C8081800E33147 /* PinLayoutImpl+Size.swift */; };
@@ -911,7 +910,6 @@
911910
DFF222E420BACBC000AC2A84 /* WrapContentSpec.swift in Sources */,
912911
DFED15532085349A009EF9A7 /* RectNimbleMatcher.swift in Sources */,
913912
DFB288B12085419B001F9588 /* RelativePositionSpec.swift in Sources */,
914-
DFEAF75120C9661C00E33147 /* ObjectiveCSpec.m in Sources */,
915913
DFB288B2208541B7001F9588 /* RelativePositionMultipleViewsSpec.swift in Sources */,
916914
DFB288B02085416E001F9588 /* RTLSpec.swift in Sources */,
917915
DFB288AB2085400C001F9588 /* MinMaxWidthHeightSpec.swift in Sources */,

Sources/Impl/PinLayoutImpl+Coordinates.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ extension PinLayoutImpl {
114114
warnConflict(context, ["Horizontal Center": _hCenter])
115115
} else if let _right = _right, _right != value {
116116
if let superview = view.superview {
117-
warnPropertyAlreadySet("right", propertyValue: superview.frame.width - _right, context)
117+
let rect = Coordinates.getViewRect(superview, keepTransform: keepTransform)
118+
warnPropertyAlreadySet("right", propertyValue: rect.width - _right, context)
118119
} else {
119120
warnPropertyAlreadySet("right", propertyValue: _right, context)
120121
}
@@ -157,7 +158,8 @@ extension PinLayoutImpl {
157158
warnConflict(context, ["Vertical Center": _vCenter])
158159
} else if let _bottom = _bottom, _bottom != value {
159160
if let superview = view.superview {
160-
warnPropertyAlreadySet("bottom", propertyValue: superview.frame.height - _bottom, context)
161+
let rect = Coordinates.getViewRect(superview, keepTransform: keepTransform)
162+
warnPropertyAlreadySet("bottom", propertyValue: rect.height - _bottom, context)
161163
} else {
162164
warnPropertyAlreadySet("bottom", propertyValue: _bottom, context)
163165
}

Sources/Impl/PinLayoutImpl+Layouting.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ extension PinLayoutImpl {
7171
newRect.origin.x = left + _marginLeft
7272
} else if let right = _right {
7373
// Only right is set
74-
newRect.origin.x = right - view.bounds.width - _marginRight
74+
newRect.origin.x = right - newRect.width - _marginRight
7575
} else if let _hCenter = _hCenter {
7676
// Only hCenter is set
77-
newRect.origin.x = (_hCenter - (view.bounds.width / 2)) + _marginLeft - _marginRight
77+
newRect.origin.x = (_hCenter - (newRect.width / 2)) + _marginLeft - _marginRight
7878
} else if let width = newSize.width {
7979
// Only width is set
8080
newRect.size.width = width
@@ -107,21 +107,21 @@ extension PinLayoutImpl {
107107
newRect.origin.y = top + _marginTop
108108
} else if let bottom = _bottom {
109109
// Only bottom is set
110-
newRect.origin.y = bottom - view.bounds.height - _marginBottom
110+
newRect.origin.y = bottom - newRect.height - _marginBottom
111111
} else if let _vCenter = _vCenter {
112112
// Only vCenter is set
113-
newRect.origin.y = (_vCenter - (view.bounds.height / 2)) + _marginTop - _marginBottom
113+
newRect.origin.y = (_vCenter - (newRect.height / 2)) + _marginTop - _marginBottom
114114
} else if let height = newSize.height {
115115
// Only height is set
116116
newRect.size.height = height
117117
}
118118

119119
if !validateComputedWidth(newRect.size.width) {
120-
newRect.size.width = view.bounds.width
120+
newRect.size.width = Coordinates.getViewRect(view, keepTransform: keepTransform).width
121121
}
122122

123123
if !validateComputedHeight(newRect.size.height) {
124-
newRect.size.height = view.bounds.height
124+
newRect.size.height = Coordinates.getViewRect(view, keepTransform: keepTransform).height
125125
}
126126

127127
/*
@@ -275,13 +275,13 @@ extension PinLayoutImpl {
275275
if let width = applyMinMax(toWidth: size.width) {
276276
fitWidth = width
277277
} else {
278-
fitWidth = view.bounds.width
278+
fitWidth = Coordinates.getViewRect(view, keepTransform: keepTransform).width
279279
}
280280
case .fitTypeHeight, .fitTypeHeightFlexible:
281281
if let height = applyMinMax(toHeight: size.height) {
282282
fitHeight = height
283283
} else {
284-
fitHeight = view.bounds.height
284+
fitHeight = Coordinates.getViewRect(view, keepTransform: keepTransform).height
285285
}
286286
default:
287287
assertionFailure("Should not occured")

Sources/Impl/PinLayoutImpl+Size.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ extension PinLayoutImpl {
8282

8383
func size(of view: PView) -> PinLayout {
8484
func context() -> String { return "size(of \(viewDescription(view)))" }
85-
return setSize(view.bounds.size, context)
85+
return setSize(Coordinates.getViewRect(view, keepTransform: keepTransform).size, context)
8686
}
8787

8888
@discardableResult
@@ -91,7 +91,8 @@ extension PinLayoutImpl {
9191
}
9292

9393
func aspectRatio(of view: PView) -> PinLayout {
94-
return setAdjustSizeType(.aspectRatio(view.bounds.width / view.bounds.height), { "aspectRatio(of: \(viewDescription(view)))" })
94+
let rect = Coordinates.getViewRect(view, keepTransform: keepTransform)
95+
return setAdjustSizeType(.aspectRatio(rect.width / rect.height), { "aspectRatio(of: \(viewDescription(view)))" })
9596
}
9697

9798
#if os(iOS) || os(tvOS)

Sources/Impl/PinLayoutImpl+Warning.swift

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,6 @@ fileprivate var numberFormatter: NumberFormatter = {
3030
return numberFormatter
3131
}()
3232

33-
internal func pinLayoutDisplayConsoleWarning(_ text: String, _ view: PView) {
34-
var displayText = "\n👉 \(text)"
35-
36-
let x = numberFormatter.string(from: NSNumber(value: Float(view.frame.origin.x)))!
37-
let y = numberFormatter.string(from: NSNumber(value: Float(view.frame.origin.y)))!
38-
let width = numberFormatter.string(from: NSNumber(value: Float(view.frame.size.width)))!
39-
let height = numberFormatter.string(from: NSNumber(value: Float(view.frame.size.height)))!
40-
let viewName = "\(type(of: view))"
41-
displayText += "\n(Layouted view info: Type: \(viewName), Frame: x: \(x), y: \(y), width: \(width), height: \(height))"
42-
43-
var currentView = view
44-
var hierarchy: [String] = []
45-
while let parent = currentView.superview {
46-
hierarchy.insert("\(type(of: parent))", at: 0)
47-
currentView = parent
48-
}
49-
if hierarchy.count > 0 {
50-
#if swift(>=4.1)
51-
displayText += ", Superviews: \(hierarchy.compactMap({ $0 }).joined(separator: " -> "))"
52-
#else
53-
displayText += ", Superviews: \(hierarchy.flatMap({ $0 }).joined(separator: " -> "))"
54-
#endif
55-
}
56-
57-
displayText += ", Tag: \(view.tag))\n"
58-
59-
print(displayText)
60-
Pin.lastWarningText = text
61-
}
62-
63-
6433
extension PinLayoutImpl {
6534
internal func pointContext(method: String, point: CGPoint) -> String {
6635
return "\(method)(to: CGPoint(x: \(point.x), y: \(point.y)))"
@@ -146,7 +115,8 @@ extension PinLayoutImpl {
146115
}
147116

148117
internal func viewDescription(_ view: PView) -> String {
149-
return "(\(viewName(view)), Frame: \(view.frame))"
118+
let rect = Coordinates.getViewRect(view, keepTransform: keepTransform)
119+
return "(\(viewName(view)), Frame: \(rect))"
150120
}
151121

152122
internal func viewName(_ view: PView) -> String {
@@ -156,4 +126,35 @@ extension PinLayoutImpl {
156126
internal func insetsDescription(_ insets: PEdgeInsets) -> String {
157127
return "UIEdgeInsets(top: \(insets.top), left: \(insets.left), bottom: \(insets.bottom), right: \(insets.right))"
158128
}
129+
130+
internal func pinLayoutDisplayConsoleWarning(_ text: String, _ view: PView) {
131+
var displayText = "\n👉 \(text)"
132+
133+
let rect = Coordinates.getViewRect(view, keepTransform: keepTransform)
134+
let x = numberFormatter.string(from: NSNumber(value: Float(rect.origin.x)))!
135+
let y = numberFormatter.string(from: NSNumber(value: Float(rect.origin.y)))!
136+
let width = numberFormatter.string(from: NSNumber(value: Float(rect.size.width)))!
137+
let height = numberFormatter.string(from: NSNumber(value: Float(rect.size.height)))!
138+
let viewName = "\(type(of: view))"
139+
displayText += "\n(Layouted view info: Type: \(viewName), Frame: x: \(x), y: \(y), width: \(width), height: \(height))"
140+
141+
var currentView = view
142+
var hierarchy: [String] = []
143+
while let parent = currentView.superview {
144+
hierarchy.insert("\(type(of: parent))", at: 0)
145+
currentView = parent
146+
}
147+
if hierarchy.count > 0 {
148+
#if swift(>=4.1)
149+
displayText += ", Superviews: \(hierarchy.compactMap({ $0 }).joined(separator: " -> "))"
150+
#else
151+
displayText += ", Superviews: \(hierarchy.flatMap({ $0 }).joined(separator: " -> "))"
152+
#endif
153+
}
154+
155+
displayText += ", Tag: \(view.tag))\n"
156+
157+
print(displayText)
158+
Pin.lastWarningText = text
159+
}
159160
}

Sources/Impl/PinLayoutImpl.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,8 @@ class PinLayoutImpl: PinLayout {
643643
}
644644

645645
func width(of view: PView) -> PinLayout {
646-
return setWidth(view.bounds.width, { return "width(of: \(viewDescription(view)))" })
646+
let rect = Coordinates.getViewRect(view, keepTransform: keepTransform)
647+
return setWidth(rect.width, { return "width(of: \(viewDescription(view)))" })
647648
}
648649

649650
func minWidth(_ width: CGFloat) -> PinLayout {
@@ -679,7 +680,8 @@ class PinLayoutImpl: PinLayout {
679680
}
680681

681682
func height(of view: PView) -> PinLayout {
682-
return setHeight(view.bounds.height, { return "height(of: \(viewDescription(view)))" })
683+
let rect = Coordinates.getViewRect(view, keepTransform: keepTransform)
684+
return setHeight(rect.height, { return "height(of: \(viewDescription(view)))" })
683685
}
684686

685687
func minHeight(_ height: CGFloat) -> PinLayout {

0 commit comments

Comments
 (0)