Skip to content

Commit faeb598

Browse files
committed
Code review modifications
1 parent 089ebe9 commit faeb598

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

Sources/AutoSizeCalculable.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import AppKit
55
#endif
66

77
public protocol AutoSizeCalculable {
8-
var autoSizingRect: CGRect? { get set }
9-
var autoSizingRectWithMargins: CGRect? { get set }
10-
8+
func setAutoSizingRect(_ rect: CGRect, margins: PEdgeInsets)
119
func autoSizeThatFits(_ size: CGSize, layoutClosure: () -> Void) -> CGSize
1210
}

Sources/Extensions/UIView+PinLayout.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ extension UIView: Layoutable, SizeCalculable {
6161
public func setRect(_ rect: CGRect, keepTransform: Bool) {
6262
let adjustedRect = Coordinates<View>.adjustRectToDisplayScale(rect)
6363

64-
guard !Pin.autoSizingInProgress else {
65-
autoSizingRect = adjustedRect
66-
return
67-
}
68-
6964
if keepTransform {
7065
/*
7166
To adjust the view's position and size, we don't set the UIView's frame directly, because we want to keep the
@@ -108,7 +103,7 @@ extension UIView: AutoSizeCalculable {
108103
static var pinlayoutAutoSizingRectWithMargins = UnsafeMutablePointer<Int8>.allocate(capacity: 1)
109104
}
110105

111-
public var autoSizingRect: CGRect? {
106+
private var autoSizingRect: CGRect? {
112107
get {
113108
return objc_getAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutAutoSizingRect) as? CGRect
114109
}
@@ -117,7 +112,7 @@ extension UIView: AutoSizeCalculable {
117112
}
118113
}
119114

120-
public var autoSizingRectWithMargins: CGRect? {
115+
private var autoSizingRectWithMargins: CGRect? {
121116
get {
122117
return objc_getAssociatedObject(self, &pinlayoutAssociatedKeys.pinlayoutAutoSizingRectWithMargins) as? CGRect
123118
}
@@ -126,6 +121,11 @@ extension UIView: AutoSizeCalculable {
126121
}
127122
}
128123

124+
public func setAutoSizingRect(_ rect: CGRect, margins: PEdgeInsets) {
125+
self.autoSizingRect = Coordinates<View>.adjustRectToDisplayScale(rect)
126+
self.autoSizingRectWithMargins = Coordinates<View>.adjustRectToDisplayScale(rect.inset(by: margins))
127+
}
128+
129129
public func autoSizeThatFits(_ size: CGSize, layoutClosure: () -> Void) -> CGSize {
130130
Pin.autoSizingInProgress = true
131131
autoSizingRect = CGRect(origin: CGPoint.zero, size: size)

Sources/Impl/PinLayout+Layouting.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,9 @@ extension PinLayout {
134134
newRect.size.height = view.getRect(keepTransform: keepTransform).height
135135
}
136136

137-
if Pin.autoSizingInProgress, var autoSizeCalculable = view as? AutoSizeCalculable {
137+
if Pin.autoSizingInProgress, let autoSizeCalculable = view as? AutoSizeCalculable {
138138
let marginInsets = UIEdgeInsets(top: -_marginTop, left: -_marginLeft, bottom: -_marginBottom, right: -_marginRight)
139-
let rectWithMargins = newRect.inset(by: marginInsets)
140-
autoSizeCalculable.autoSizingRectWithMargins = rectWithMargins
139+
autoSizeCalculable.setAutoSizingRect(newRect, margins: marginInsets)
141140
}
142141

143142
/*

0 commit comments

Comments
 (0)