Skip to content

Commit c55f4f6

Browse files
committed
Fix recursive usage of auto sizing
1 parent ff9caff commit c55f4f6

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Sources/Extensions/UIView+PinLayout.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,23 @@ extension UIView: AutoSizeCalculable {
127127
}
128128

129129
public func autoSizeThatFits(_ size: CGSize, layoutClosure: () -> Void) -> CGSize {
130-
Pin.autoSizingInProgress = true
131-
autoSizingRect = CGRect(origin: CGPoint.zero, size: size)
130+
let isAlreadyAutoSizing = Pin.autoSizingInProgress
131+
132+
if (!isAlreadyAutoSizing) {
133+
Pin.autoSizingInProgress = true
134+
autoSizingRect = CGRect(origin: CGPoint.zero, size: size)
135+
}
136+
132137
layoutClosure()
133138

134139
let boundingRect = subviews.compactMap({ $0.autoSizingRectWithMargins }).reduce(CGRect.zero) { (result: CGRect, autoSizingRect: CGRect) -> CGRect in
135140
return result.union(autoSizingRect)
136141
}
137142

138-
Pin.autoSizingInProgress = false
143+
if !isAlreadyAutoSizing {
144+
Pin.autoSizingInProgress = false
145+
}
146+
139147
return boundingRect.size
140148
}
141149
}

0 commit comments

Comments
 (0)