Skip to content

Commit

Permalink
Improve pragma marks and method ordering (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinder-cfuller authored Jan 31, 2024
1 parent 1c25f83 commit b053325
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Sources/Layout/Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ public final class Layout { // swiftlint:disable:this type_body_length
constraints.forEach { $0.prioritize(priority) }
}

// MARK: - Update
// MARK: - Animation

/// Updates the constraints of the ``view`` of the layout.
///
Expand Down
4 changes: 4 additions & 0 deletions Sources/Layout/LayoutItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ extension LayoutItem {
self.size(width: size.width, height: size.height, priority: priority)
}

// MARK: - Width

/// Adds a constraint defining the width of the ``layoutItemView``.
///
/// - Parameters:
Expand Down Expand Up @@ -178,6 +180,8 @@ extension LayoutItem {
}
}

// MARK: - Height

/// Adds a constraint defining the height of the ``layoutItemView``.
///
/// - Parameters:
Expand Down
36 changes: 21 additions & 15 deletions Sources/Layout/UIKit/UIView+AutoLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ extension UIView {

// MARK: - Size

/// Creates constraints defining the size of the receiver.
///
/// - Parameter size: The constant size value. When `nil`, the size of the receiver is used.
///
/// - Returns: The created constraints.
public func sizeConstraints(
_ size: CGSize? = nil
) -> [NSLayoutConstraint] {
[
width.constraint(size?.width ?? bounds.width),
height.constraint(size?.height ?? bounds.height)
]
}

// MARK: - Width

/// Creates a constraint defining the width of the receiver.
///
/// - Parameters:
Expand All @@ -81,6 +97,8 @@ extension UIView {
width.constraint(constant ?? bounds.width)
}

// MARK: - Height

/// Creates a constraint defining the height of the receiver.
///
/// - Parameters:
Expand All @@ -106,21 +124,7 @@ extension UIView {
height.constraint(constant ?? bounds.height)
}

/// Creates constraints defining the size of the receiver.
///
/// - Parameter size: The constant size value. When `nil`, the size of the receiver is used.
///
/// - Returns: The created constraints.
public func sizeConstraints(
_ size: CGSize? = nil
) -> [NSLayoutConstraint] {
[
width.constraint(size?.width ?? bounds.width),
height.constraint(size?.height ?? bounds.height)
]
}

// MARK: - Aspect Ratio
// MARK: - Square

/// Creates a constraint defining the aspect ratio of the receiver to be square.
///
Expand All @@ -129,6 +133,8 @@ extension UIView {
constraint(for: .width, to: .height, of: self)
}

// MARK: - Aspect Ratio

/// Creates a constraint defining the aspect ratio of the receiver.
///
/// - Parameter ratio: The aspect ratio.
Expand Down
36 changes: 21 additions & 15 deletions Tests/LayoutTests/LayoutItemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ final class LayoutItemTests: XCTestCase {
}
}

// MARK: - Width

func testWidthIsRelationToConstantPriority() {

// swiftlint:disable:next closure_body_length
Expand Down Expand Up @@ -193,6 +195,8 @@ final class LayoutItemTests: XCTestCase {
}
}

// MARK: - Height

func testHeightIsRelationToConstantPriority() {

// swiftlint:disable:next closure_body_length
Expand Down Expand Up @@ -281,52 +285,54 @@ final class LayoutItemTests: XCTestCase {
}
}

// MARK: - Aspect Ratio
// MARK: - Square

func testSquare() {
func testSquareWithLengthPriority() {
assertLayout { view in
view.layout {

// Square with Width
// Square Length with Default Priority

pinkView
.to([.top, .leading])
.width(100)
.square()
.square(200, priority: .high)
.square(100)

// Square with Height
// Square Length with Priority

yellowView
.to([.top, .trailing])
.height(100)
.square()
.square(25, priority: .low)
.square(100, priority: .high)
}
.activate()
}
}

func testSquareWithLengthPriority() {
func testSquare() {
assertLayout { view in
view.layout {

// Square Length with Default Priority
// Square with Width

pinkView
.to([.top, .leading])
.square(200, priority: .high)
.square(100)
.width(100)
.square()

// Square Length with Priority
// Square with Height

yellowView
.to([.top, .trailing])
.square(25, priority: .low)
.square(100, priority: .high)
.height(100)
.square()
}
.activate()
}
}

// MARK: - Aspect Ratio

func testAspectRatioWithRatioPriority() {
assertLayout { view in
view.layout {
Expand Down
2 changes: 1 addition & 1 deletion Tests/LayoutTests/LayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ final class LayoutTests: XCTestCase {
expect(layout.constraints[1].priority) == UILayoutPriority.high
}

// MARK: - Update
// MARK: - Animation

func testUpdate() {

Expand Down

0 comments on commit b053325

Please sign in to comment.