Skip to content

Commit

Permalink
Rename size methods to width and height (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinder-cfuller authored Jan 18, 2024
1 parent c6aef7e commit ba473a9
Show file tree
Hide file tree
Showing 25 changed files with 70 additions and 70 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ override func viewDidLoad() {
.center(.horizontal)
imageView
.toSideEdges(inset: 20)
.size(height: 200)
.height(constant: 200)
button
.center(.horizontal)
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/Layout/LayoutItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,23 @@ extension LayoutItem {

// swiftlint:disable function_default_parameter_at_end

public func size(
public func width(
is relation: NSLayoutConstraint.Relation = .equal,
width: CGFloat,
constant: CGFloat,
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
layoutItem.layoutItemView.widthConstraint(is: relation, width).withPriority(priority)
layoutItem.layoutItemView.widthConstraint(is: relation, constant).withPriority(priority)
}
}

public func size(
public func height(
is relation: NSLayoutConstraint.Relation = .equal,
height: CGFloat,
constant: CGFloat,
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
layoutItem.layoutItemView.heightConstraint(is: relation, height).withPriority(priority)
layoutItem.layoutItemView.heightConstraint(is: relation, constant).withPriority(priority)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/LayoutTests/LayoutExampleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ final class LayoutExampleTests: XCTestCase {
.center(.horizontal)
imageView
.toSideEdges(inset: 20)
.size(height: 200)
.height(constant: 200)
button
.center(.horizontal)
}
Expand Down
106 changes: 53 additions & 53 deletions Tests/LayoutTests/LayoutItemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ final class LayoutItemTests: XCTestCase {
}
}

func testSizeWidth_andWithConstraintRelation_andWithPriority() {
func testWidth_andWithConstraintRelation_andWithPriority() {

// swiftlint:disable:next closure_body_length
assertLayout { view in
Expand All @@ -96,51 +96,51 @@ final class LayoutItemTests: XCTestCase {

pinkView
.to([.top, .leading])
.size(height: 100)
.size(is: .greaterThanOrEqual, width: 100, priority: .high)
.size(width: 50)
.height(constant: 100)
.width(is: .greaterThanOrEqual, constant: 100, priority: .high)
.width(constant: 50)

// Size Width with Priority

yellowView
.to([.top, .trailing])
.size(height: 100)
.size(width: 1, priority: .low)
.size(width: 50, priority: .high)
.height(constant: 100)
.width(constant: 1, priority: .low)
.width(constant: 50, priority: .high)

// Size Width with GreaterThanOrEqual Relation and Priority

blueView
.to([.bottom, .leading])
.size(height: 100)
.size(width: 40, priority: .high)
.size(is: .greaterThanOrEqual, width: 50)
.height(constant: 100)
.width(constant: 40, priority: .high)
.width(is: .greaterThanOrEqual, constant: 50)

// Size Width with LessThanOrEqual Relation and Priority

greenView
.to([.bottom, .trailing])
.size(height: 100)
.size(width: 60, priority: .high)
.size(is: .lessThanOrEqual, width: 50)
.height(constant: 100)
.width(constant: 60, priority: .high)
.width(is: .lessThanOrEqual, constant: 50)

// Size Width with GreaterThanOrEqual Relation

redView
.to(.centerY, constant: -50)
.to(.centerX)
.size(height: 100)
.size(width: 60)
.size(is: .greaterThanOrEqual, width: 50)
.height(constant: 100)
.width(constant: 60)
.width(is: .greaterThanOrEqual, constant: 50)

// Size Width with LessThanOrEqual Relation

orangeView
.to(.centerY, constant: 50)
.to(.centerX)
.size(height: 100)
.size(width: 40)
.size(is: .lessThanOrEqual, width: 50)
.height(constant: 100)
.width(constant: 40)
.width(is: .lessThanOrEqual, constant: 50)
}
}
}
Expand All @@ -157,51 +157,51 @@ final class LayoutItemTests: XCTestCase {

pinkView
.to([.top, .leading])
.size(width: 50)
.size(is: .greaterThanOrEqual, height: 150, priority: .high)
.size(height: 100)
.width(constant: 50)
.height(is: .greaterThanOrEqual, constant: 150, priority: .high)
.height(constant: 100)

// Size Height with Priority

yellowView
.to([.top, .trailing])
.size(width: 50)
.size(height: 1, priority: .low)
.size(height: 100, priority: .high)
.width(constant: 50)
.height(constant: 1, priority: .low)
.height(constant: 100, priority: .high)

// Size Height with GreaterThanOrEqual Relation

blueView
.to([.bottom, .leading])
.size(width: 50)
.size(height: 75, priority: .high)
.size(is: .greaterThanOrEqual, height: 100)
.width(constant: 50)
.height(constant: 75, priority: .high)
.height(is: .greaterThanOrEqual, constant: 100)

// Size Height with LessThanOrEqual Relation

greenView
.to([.bottom, .trailing])
.size(width: 50)
.size(height: 125, priority: .high)
.size(is: .lessThanOrEqual, width: 50)
.width(constant: 50)
.height(constant: 125, priority: .high)
.height(is: .lessThanOrEqual, constant: 50)

// Size Height with GreaterThanOrEqual Relation and Priority

redView
.to([.centerY], constant: -50)
.to([.centerX])
.size(width: 50)
.size(height: 110, priority: .high)
.size(is: .greaterThanOrEqual, height: 100)
.width(constant: 50)
.height(constant: 110, priority: .high)
.height(is: .greaterThanOrEqual, constant: 100)

// Size Height with LessThanOrEqual Relation and Priority

orangeView
.to([.centerY], constant: 50)
.to([.centerX])
.size(width: 50)
.size(height: 90, priority: .high)
.size(is: .lessThanOrEqual, height: 100)
.width(constant: 50)
.height(constant: 90, priority: .high)
.height(is: .lessThanOrEqual, constant: 100)
}
}
}
Expand All @@ -214,14 +214,14 @@ final class LayoutItemTests: XCTestCase {

pinkView
.to([.top, .leading])
.size(width: 100)
.width(constant: 100)
.square()

// Square with Height

yellowView
.to([.top, .trailing])
.size(height: 100)
.height(constant: 100)
.square()
}
}
Expand Down Expand Up @@ -256,15 +256,15 @@ final class LayoutItemTests: XCTestCase {

pinkView
.to([.top, .leading])
.size(height: 100)
.height(constant: 100)
.aspectRatio(0.5, priority: .high)
.aspectRatio(0.75)

// Aspect Ratio with Priority

yellowView
.to([.top, .trailing])
.size(height: 100)
.height(constant: 100)
.aspectRatio(0.25, priority: .low)
.aspectRatio(0.75, priority: .high)
}
Expand Down Expand Up @@ -529,20 +529,20 @@ final class LayoutItemTests: XCTestCase {
// To Edges Top, Leading and Trailing with Default Priority

pinkView
.size(height: 100)
.height(constant: 100)
.toEdges([.top, .leading, .trailing], inset: 50, priority: .high)
.toEdges([.top, .leading, .trailing])

// To Edges Bottom, Leading and Trailing with Inset

yellowView
.size(height: 100)
.height(constant: 100)
.toEdges([.bottom, .leading, .trailing], inset: 25)

// To Edges Leading and Trailing with Vertical Center, Inset and Priority

blueView
.size(height: 100)
.height(constant: 100)
.to(.centerY)
.toEdges([.leading, .trailing], inset: 25, priority: .low)
.toEdges([.leading, .trailing], inset: 50, priority: .high)
Expand All @@ -563,19 +563,19 @@ final class LayoutItemTests: XCTestCase {
// To Edges Top, Left and Right

yellowView
.size(height: 100)
.height(constant: 100)
.toEdges(canonical: [.top, .left, .right])

// To Edges Bottom, Left and Right with Inset

blueView
.size(height: 100)
.height(constant: 100)
.toEdges(canonical: [.bottom, .left, .right], inset: 25)

// To Edges Left and Right with Vertical Center, Inset and Priority

orangeView
.size(height: 100)
.height(constant: 100)
.to(.centerY)
.toEdges(canonical: [.left, .right], inset: 25, priority: .low)
.toEdges(canonical: [.left, .right], inset: 50, priority: .high)
Expand All @@ -590,22 +590,22 @@ final class LayoutItemTests: XCTestCase {
// To Side Edges with Default Inset and Priority

pinkView
.size(height: 100)
.height(constant: 100)
.to(.top)
.toSideEdges(inset: 50, priority: .high)
.toSideEdges()

// To Side Edges with Inset

yellowView
.size(height: 100)
.height(constant: 100)
.to(.centerY)
.toSideEdges(inset: 50)

// To Side Edges with Inset and Priority

blueView
.size(height: 100)
.height(constant: 100)
.to(.bottom)
.toSideEdges(inset: 0, priority: .low)
.toSideEdges(inset: 50, priority: .high)
Expand Down Expand Up @@ -715,22 +715,22 @@ final class LayoutItemTests: XCTestCase {

pinkView
.to(.top)
.size(height: 100)
.height(constant: 100)
.toSideMargins()
.toSideMargins(inset: 20, priority: .high)

// To Side Margins with Inset

blueView
.center(.vertical)
.size(height: 100)
.height(constant: 100)
.toSideMargins(inset: 20)

// To Side Margins with Inset and Priority

orangeView
.to(.bottom)
.size(height: 100)
.height(constant: 100)
.toSideMargins(inset: 20, priority: .low)
.toSideMargins(inset: 40, priority: .high)
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/LayoutTests/LayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ final class LayoutTests: XCTestCase {

let layout: Layout = view.layout {
pinkView
.size(height: 100)
.height(constant: 100)
yellowView
}

Expand Down Expand Up @@ -404,7 +404,7 @@ final class LayoutTests: XCTestCase {

let layout: Layout = view.layout {
pinkView
.size(height: 100)
.height(constant: 100)
yellowView
}

Expand Down Expand Up @@ -507,12 +507,12 @@ final class LayoutTests: XCTestCase {

let layout: Layout = view.layout {
pinkView
.size(height: 100)
.height(constant: 100)
.to([.top, .leading])
yellowView
.to([.bottom, .trailing])
blueView
.size(height: 100)
.height(constant: 100)
.to([.centerY, .centerX])
greenView
.to(.leading, constant: 10)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
| <View; name = Pink; frame = (x: 0, y: 0, width: 50, height: 100)>
| <View; name = Yellow; frame = (x: 325, y: 0, width: 50, height: 100)>
| <View; name = Blue; frame = (x: 0, y: 712, width: 50, height: 100)>
| <View; name = Green; frame = (x: 325, y: 687, width: 50, height: 125)>
| <View; name = Green; frame = (x: 325, y: 762, width: 50, height: 50)>
| <View; name = Red; frame = (x: 162.666667, y: 301, width: 50, height: 110)>
| <View; name = Orange; frame = (x: 162.666667, y: 411, width: 50, height: 90)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
| <View; name = Pink; frame = (x: 0, y: 0, width: 50, height: 100)>
| <View; name = Yellow; frame = (x: 340, y: 0, width: 50, height: 100)>
| <View; name = Blue; frame = (x: 0, y: 744, width: 50, height: 100)>
| <View; name = Green; frame = (x: 340, y: 719, width: 50, height: 125)>
| <View; name = Green; frame = (x: 340, y: 794, width: 50, height: 50)>
| <View; name = Red; frame = (x: 170, y: 317, width: 50, height: 110)>
| <View; name = Orange; frame = (x: 170, y: 427, width: 50, height: 90)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
| <View; name = Pink; frame = (x: 0, y: 0, width: 50, height: 100)>
| <View; name = Yellow; frame = (x: 325, y: 0, width: 50, height: 100)>
| <View; name = Blue; frame = (x: 0, y: 567, width: 50, height: 100)>
| <View; name = Green; frame = (x: 325, y: 542, width: 50, height: 125)>
| <View; name = Green; frame = (x: 325, y: 617, width: 50, height: 50)>
| <View; name = Red; frame = (x: 162.666667, y: 228.666667, width: 50, height: 110)>
| <View; name = Orange; frame = (x: 162.666667, y: 338.666667, width: 50, height: 90)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
| <View; name = Pink; frame = (x: 0, y: 0, width: 50, height: 100)>
| <View; name = Yellow; frame = (x: 270, y: 0, width: 50, height: 100)>
| <View; name = Blue; frame = (x: 0, y: 468, width: 50, height: 100)>
| <View; name = Green; frame = (x: 270, y: 443, width: 50, height: 125)>
| <View; name = Green; frame = (x: 270, y: 518, width: 50, height: 50)>
| <View; name = Red; frame = (x: 135, y: 179, width: 50, height: 110)>
| <View; name = Orange; frame = (x: 135, y: 289, width: 50, height: 90)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ba473a9

Please sign in to comment.