Skip to content

Commit 2a67100

Browse files
authored
Merge pull request #8 from theisegeberg/feature/configureStack
Added configure to stack in order to pull out UIStackView for later use
2 parents 2d1f730 + 653b0c2 commit 2a67100

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

Sources/Layout/Layoutless.swift

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -361,23 +361,26 @@ extension LayoutProtocol where Node: UIView {
361361
// MARK: Stacking
362362

363363
/// Stack an array of views in a stack view.
364-
public func stack(_ views: [AnyLayout], axis: NSLayoutConstraint.Axis, spacing: CGFloat = 0, distribution: UIStackView.Distribution = .fill, alignment: UIStackView.Alignment = .fill) -> Layout<UIStackView> {
365-
return Layout { revertable in
366-
let stackView = UIStackView()
367-
stackView.axis = axis
368-
stackView.spacing = spacing
369-
stackView.distribution = distribution
370-
stackView.alignment = alignment
371-
views.forEach { revertable.append($0.layout(in: stackView)) }
372-
return stackView
373-
}
364+
public func stack(_ views: [AnyLayout], axis: NSLayoutConstraint.Axis, spacing: CGFloat = 0, distribution: UIStackView.Distribution = .fill, alignment: UIStackView.Alignment = .fill, configure: @escaping (UIStackView) -> Void = { _ in }) -> Layout<UIStackView> {
365+
return Layout { revertable in
366+
let stackView = UIStackView()
367+
stackView.axis = axis
368+
stackView.spacing = spacing
369+
stackView.distribution = distribution
370+
stackView.alignment = alignment
371+
views.forEach {
372+
revertable.append($0.layout(in: stackView))
373+
}
374+
configure(stackView)
375+
return stackView
376+
}
374377
}
375378

376379
/// Stack an array of views in a stack view.
377-
public func stack(_ axis: NSLayoutConstraint.Axis, spacing: CGFloat = 0, distribution: UIStackView.Distribution = .fill, alignment: UIStackView.Alignment = .fill) -> ((AnyLayout...) -> Layout<UIStackView>) {
378-
return { (views: AnyLayout...) -> Layout<UIStackView> in
379-
return stack(views, axis: axis, spacing: spacing, distribution: distribution, alignment: alignment)
380-
}
380+
public func stack(_ axis: NSLayoutConstraint.Axis, spacing: CGFloat = 0, distribution: UIStackView.Distribution = .fill, alignment: UIStackView.Alignment = .fill, configure: @escaping (UIStackView) -> Void = { _ in }) -> ((AnyLayout...) -> Layout<UIStackView>) {
381+
return { (views: AnyLayout...) -> Layout<UIStackView> in
382+
return stack(views, axis: axis, spacing: spacing, distribution: distribution, alignment: alignment,configure: configure)
383+
}
381384
}
382385

383386
// MARK: Grouping

0 commit comments

Comments
 (0)