Skip to content

Commit

Permalink
Remove constrain method (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinder-cfuller authored Dec 9, 2023
1 parent 5ea1e7d commit 27efce5
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,6 @@ extension UIView {
constant: constant)
}

public func constrain(
to superview: UIView,
insets: DirectionalInsets = .zero
) {
translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
leading.constraint(equalTo: superview.leading, constant: insets.leading),
trailing.constraint(equalTo: superview.trailing, constant: -insets.trailing),
top.constraint(equalTo: superview.top, constant: insets.top),
bottom.constraint(equalTo: superview.bottom, constant: -insets.bottom)
])
}

public func constraints(
is relation: NSLayoutConstraint.Relation = .equal,
toSuperview attributes: [NSLayoutConstraint.Attribute],
Expand Down
54 changes: 0 additions & 54 deletions Tests/LayoutTests/UIKit/UIView+AutoLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,60 +132,6 @@ final class UIViewAutoLayoutTests: XCTestCase {
expect(view.constraints.first { $0.firstAttribute == .height }?.constant) == height
}

func testConstrainToSuperviewWithDirectionalEdgeInsets_withDefaults() {

// GIVEN

let superview: UIView = .init()
let view: UIView = .init()
superview.addSubview(view)

// THEN

expect(superview.constraints).to(beEmpty())

// WHEN

view.constrain(to: superview)

// THEN

let constraints: [NSLayoutConstraint] = superview.constraints

expect(superview.constraints.count) == 4
expect(constraints[0].firstAttribute) == .leading
expect(constraints[0].constant) == 0
expect(constraints[1].firstAttribute) == .trailing
expect(constraints[1].constant) == 0
expect(constraints[2].firstAttribute) == .top
expect(constraints[2].constant) == 0
expect(constraints[3].firstAttribute) == .bottom
expect(constraints[3].constant) == 0
}

func testConstrainToSuperviewWithDirectionalEdgeInsets() {

// GIVEN

let superview: UIView = .init()
let view: UIView = .init()
superview.addSubview(view)
let insets: NSDirectionalEdgeInsets = .init(top: 1, leading: 2, bottom: 3, trailing: 4)
view.constrain(to: superview, insets: insets)
let constraints: [NSLayoutConstraint] = superview.constraints

// THEN

expect(constraints[0].firstAttribute) == .leading
expect(constraints[0].constant) == insets.leading
expect(constraints[1].firstAttribute) == .trailing
expect(constraints[1].constant) == -insets.trailing
expect(constraints[2].firstAttribute) == .top
expect(constraints[2].constant) == insets.top
expect(constraints[3].firstAttribute) == .bottom
expect(constraints[3].constant) == -insets.bottom
}

func testConstraintToSuperview() {

// GIVEN
Expand Down

0 comments on commit 27efce5

Please sign in to comment.