Skip to content

Commit

Permalink
Remove anonymous_argument_in_multiline_closure (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinder-garricnahapetian authored Nov 1, 2023
1 parent 68d2920 commit dddc48f
Showing 1 changed file with 29 additions and 33 deletions.
62 changes: 29 additions & 33 deletions Sources/Layout/LayoutItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@ extension LayoutItem {
return self
}

// swiftlint:disable anonymous_argument_in_multiline_closure

private func addingSuperviewConstraints(
@ConstraintsBuilder constraints: @escaping SuperviewConstraints
) -> LayoutItem {
ViewLayoutItem(layoutItemView: layoutItemView) { [superviewConstraints] in
superviewConstraints($0) + constraints($0)
ViewLayoutItem(layoutItemView: layoutItemView) { [superviewConstraints] layoutItem in
superviewConstraints(layoutItem) + constraints(layoutItem)
}
}

Expand All @@ -86,9 +84,9 @@ extension LayoutItem {
height: CGFloat,
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints {
$0.layoutItemView.widthConstraint(width).withPriority(priority)
$0.layoutItemView.heightConstraint(height).withPriority(priority)
addingSuperviewConstraints { layoutItem in
layoutItem.layoutItemView.widthConstraint(width).withPriority(priority)
layoutItem.layoutItemView.heightConstraint(height).withPriority(priority)
}
}

Expand Down Expand Up @@ -117,8 +115,8 @@ extension LayoutItem {
width: CGFloat,
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints {
$0.layoutItemView.widthConstraint(is: relation, width).withPriority(priority)
addingSuperviewConstraints { layoutItem in
layoutItem.layoutItemView.widthConstraint(is: relation, width).withPriority(priority)
}
}

Expand All @@ -133,8 +131,8 @@ extension LayoutItem {
height: CGFloat,
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints {
$0.layoutItemView.heightConstraint(is: relation, height).withPriority(priority)
addingSuperviewConstraints { layoutItem in
layoutItem.layoutItemView.heightConstraint(is: relation, height).withPriority(priority)
}
}

Expand All @@ -154,9 +152,9 @@ extension LayoutItem {
_ length: CGFloat,
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints {
$0.layoutItemView.widthConstraint(length).withPriority(priority)
$0.layoutItemView.heightConstraint(length).withPriority(priority)
addingSuperviewConstraints { layoutItem in
layoutItem.layoutItemView.widthConstraint(length).withPriority(priority)
layoutItem.layoutItemView.heightConstraint(length).withPriority(priority)
}
}

Expand All @@ -169,9 +167,9 @@ extension LayoutItem {
_ ratio: CGFloat,
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints {
$0.layoutItemView.width
.constraint(equalTo: $0.layoutItemView.height, multiplier: ratio)
addingSuperviewConstraints { layoutItem in
layoutItem.layoutItemView.width
.constraint(equalTo: layoutItem.layoutItemView.height, multiplier: ratio)
.withPriority(priority)
}
}
Expand All @@ -185,8 +183,8 @@ extension LayoutItem {
offset: UIOffset = .zero,
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints {
$0.layoutItemView.centerConstraints(offsetBy: offset).withPriority(priority)
addingSuperviewConstraints { layoutItem in
layoutItem.layoutItemView.centerConstraints(offsetBy: offset).withPriority(priority)
}
}

Expand Down Expand Up @@ -222,8 +220,8 @@ extension LayoutItem {
constant: CGFloat = 0,
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints {
$0.layoutItemView
addingSuperviewConstraints { layoutItem in
layoutItem.layoutItemView
.constraint(for: attribute.canonicalAttribute,
is: relation,
toSuperview: attribute,
Expand Down Expand Up @@ -463,14 +461,14 @@ extension LayoutItem {
minInset: CGFloat,
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints {
if let superview: UIView = $0.layoutItemView.superview {
$0.layoutItemView
addingSuperviewConstraints { layoutItem in
if let superview: UIView = layoutItem.layoutItemView.superview {
layoutItem.layoutItemView
.constraint(for: .bottom,
to: .bottomMargin,
of: superview)
.withPriority(priority - min(1, priority.rawValue / 2))
$0.layoutItemView
layoutItem.layoutItemView
.bottom
.constraint(is: .lessThanOrEqual,
to: superview.bottom,
Expand Down Expand Up @@ -511,16 +509,16 @@ extension LayoutItem {
between top: NSLayoutYAxisAnchor,
and bottom: NSLayoutYAxisAnchor
) -> LayoutItem {
addingSuperviewConstraints {
if let superview = $0.layoutItemView.superview {
addingSuperviewConstraints { layoutItem in
if let superview = layoutItem.layoutItemView.superview {
let guide: UILayoutGuide = {
let guide: UILayoutGuide = .init()
superview.addLayoutGuide(guide)
return guide
}()
guide.top.constraint(to: top)
guide.bottom.constraint(to: bottom)
$0.layoutItemView.centerY.constraint(to: guide.centerY)
layoutItem.layoutItemView.centerY.constraint(to: guide.centerY)
}
}
}
Expand Down Expand Up @@ -555,22 +553,20 @@ extension LayoutItem {
between leading: NSLayoutXAxisAnchor,
and trailing: NSLayoutXAxisAnchor
) -> LayoutItem {
addingSuperviewConstraints {
if let superview = $0.layoutItemView.superview {
addingSuperviewConstraints { layoutItem in
if let superview = layoutItem.layoutItemView.superview {
let guide: UILayoutGuide = {
let guide: UILayoutGuide = .init()
superview.addLayoutGuide(guide)
return guide
}()
guide.leading.constraint(to: leading)
guide.trailing.constraint(to: trailing)
$0.layoutItemView.centerX.constraint(to: guide.centerX)
layoutItem.layoutItemView.centerX.constraint(to: guide.centerX)
}
}
}

// swiftlint:enable anonymous_argument_in_multiline_closure

/// Constrains the view's directional edges to the superview's safe area with insets.
///
/// - Parameters:
Expand Down

0 comments on commit dddc48f

Please sign in to comment.