Skip to content

Commit 054a3cf

Browse files
committed
Fix H/V content size calculate error
1 parent deb50e2 commit 054a3cf

3 files changed

Lines changed: 10 additions & 16 deletions

File tree

Demo/Demo/Base.lproj/Main.storyboard

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
</viewController>
7575
<placeholder placeholderIdentifier="IBFirstResponder" id="NVa-Eg-Ijb" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
7676
</objects>
77-
<point key="canvasLocation" x="3648" y="-550"/>
77+
<point key="canvasLocation" x="1849" y="-581"/>
7878
</scene>
7979
<!--H/VStackView-->
8080
<scene sceneID="Lai-fH-3ho">

Sources/StackKit/HStackView.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,11 @@ open class HStackView: UIView, StackView {
6262
}
6363

6464
public var contentSize: CGSize {
65-
let rect = effectiveSubviews.map({ $0.frame }).reduce(CGRect.zero) { result, rect in
66-
result.union(rect)
67-
}
65+
let width = effectiveSubviews.map({ $0.frame }).reduce(CGRect.zero, { $0.union($1) }).width
66+
let height = effectiveSubviews.map({ $0.bounds.height }).max() ?? 0
67+
6868
let offsetXLength = effectiveSubviews.map({ $0.frame.minX }).filter({ $0 < 0 }).min() ?? 0
69-
return CGSize(
70-
width: rect.width + paddingRight + offsetXLength,
71-
height: rect.height + paddingVertically
72-
)
69+
return CGSize(width: width + paddingRight + offsetXLength, height: height + paddingVertically)
7370
}
7471

7572
open func hideIfNoEffectiveViews() {

Sources/StackKit/VStackView.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,11 @@ open class VStackView: UIView, StackView {
6262
}
6363

6464
public var contentSize: CGSize {
65-
let rect = effectiveSubviews.map({ $0.frame }).reduce(CGRect.zero) { partialResult, rect in
66-
partialResult.union(rect)
67-
}
68-
let offsetYLength: CGFloat = effectiveSubviews.map({ $0.frame.origin.y }).filter({ $0 < 0 }).min() ?? 0
69-
return CGSize(
70-
width: rect.width + paddingHorizontally,
71-
height: rect.height + paddingBottom + offsetYLength
72-
)
65+
let width = effectiveSubviews.map({ $0.bounds.width }).max() ?? 0
66+
let height = effectiveSubviews.map({ $0.frame }).reduce(CGRect.zero, { $0.union($1) }).height
67+
68+
let offsetYLength: CGFloat = effectiveSubviews.map({ $0.frame.minY }).filter({ $0 < 0 }).min() ?? 0
69+
return CGSize(width: width + paddingHorizontally, height: height + paddingBottom + offsetYLength)
7370
}
7471

7572
open func hideIfNoEffectiveViews() {

0 commit comments

Comments
 (0)