Skip to content

Commit 874e675

Browse files
committed
Update
1 parent 5469f21 commit 874e675

File tree

3 files changed

+4
-22
lines changed

3 files changed

+4
-22
lines changed

Demo/Demo/WrapStackLayerDemoViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class WrapStackLayerDemoViewController: UIViewController {
4040
// Do any additional setup after loading the view.
4141
let widths: [CGFloat] = [20, 30, 50, 120, 40, 230, 50, 60, 10]
4242
fixedWrapStackLayer.addContent {
43-
for _ in (0 ... 2) {
43+
for _ in (0 ... 20) {
4444
makeUIView(size: CGSize(width: widths.randomElement() ?? 10, height: 30))
4545
}
4646
}
@@ -74,7 +74,7 @@ class WrapStackLayerDemoViewController: UIViewController {
7474
override func viewDidLayoutSubviews() {
7575
super.viewDidLayoutSubviews()
7676

77-
fixedWrapStackLayer.pin.top(120).horizontally().sizeToFit(.content)
77+
fixedWrapStackLayer.pin.top(120).maxWidth(220).sizeToFit(.width)
7878
adaptiveWrapStackLayer.pin.top(to: fixedWrapStackLayer.edge.bottom).marginTop(50).horizontally().sizeToFit(.width)
7979
autoWrapStackLayer.pin.top(to: adaptiveWrapStackLayer.edge.bottom).marginTop(50).horizontally().sizeToFit(.width)
8080
}

Sources/StackKit/WrapStackLayer.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,7 @@ open class WrapStackLayer: CALayer {
222222
}
223223

224224
public func sizeThatFits(_ size: CGSize) -> CGSize {
225-
if size.width != .greatestFiniteMagnitude {
226-
self.frame.size.width = size.width
227-
}
228-
if size.height != .greatestFiniteMagnitude {
229-
self.frame.size.height = size.height
230-
}
225+
self.frame.size = size
231226
self.layoutSublayers()
232227

233228
let effectiveViewsSize = effectiveSublayers.map({ $0.frame }).reduce(CGRect.zero) { result, rect in
@@ -242,10 +237,6 @@ open class WrapStackLayer: CALayer {
242237
return _size
243238
}
244239

245-
public func sizeToFit() {
246-
frame.size = sizeThatFits(.zero)
247-
}
248-
249240
public func layoutSizeToFit(_ layout: WrapStackLayout) {
250241
let size: CGSize
251242
switch layout {

Sources/StackKit/WrapStackView.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,9 @@ open class WrapStackView: UIView {
215215
}
216216

217217
open override func sizeThatFits(_ size: CGSize) -> CGSize {
218-
if size.width != .greatestFiniteMagnitude {
219-
self.frame.size.width = size.width
220-
}
221-
if size.height != .greatestFiniteMagnitude {
222-
self.frame.size.height = size.height
223-
}
224218
layoutSubviews()
225219

226-
let effectiveViewsSize = effectiveSubviews.map({ $0.frame }).reduce(CGRect.zero) { result, rect in
227-
result.union(rect)
228-
}.size
229-
220+
let effectiveViewsSize = effectiveSubviews.map({ $0.frame }).reduce(CGRect.zero, { $0.union($1) }).size
230221
var _size = effectiveViewsSize
231222
if !effectiveSubviews.isEmpty {
232223
_size.height += contentInsets.bottom

0 commit comments

Comments
 (0)