Skip to content

Commit b053325

Browse files
Improve pragma marks and method ordering (#319)
1 parent 1c25f83 commit b053325

File tree

5 files changed

+48
-32
lines changed

5 files changed

+48
-32
lines changed

Sources/Layout/Layout.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ public final class Layout { // swiftlint:disable:this type_body_length
750750
constraints.forEach { $0.prioritize(priority) }
751751
}
752752

753-
// MARK: - Update
753+
// MARK: - Animation
754754

755755
/// Updates the constraints of the ``view`` of the layout.
756756
///

Sources/Layout/LayoutItem.swift

+4
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ extension LayoutItem {
144144
self.size(width: size.width, height: size.height, priority: priority)
145145
}
146146

147+
// MARK: - Width
148+
147149
/// Adds a constraint defining the width of the ``layoutItemView``.
148150
///
149151
/// - Parameters:
@@ -178,6 +180,8 @@ extension LayoutItem {
178180
}
179181
}
180182

183+
// MARK: - Height
184+
181185
/// Adds a constraint defining the height of the ``layoutItemView``.
182186
///
183187
/// - Parameters:

Sources/Layout/UIKit/UIView+AutoLayout.swift

+21-15
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ extension UIView {
5656

5757
// MARK: - Size
5858

59+
/// Creates constraints defining the size of the receiver.
60+
///
61+
/// - Parameter size: The constant size value. When `nil`, the size of the receiver is used.
62+
///
63+
/// - Returns: The created constraints.
64+
public func sizeConstraints(
65+
_ size: CGSize? = nil
66+
) -> [NSLayoutConstraint] {
67+
[
68+
width.constraint(size?.width ?? bounds.width),
69+
height.constraint(size?.height ?? bounds.height)
70+
]
71+
}
72+
73+
// MARK: - Width
74+
5975
/// Creates a constraint defining the width of the receiver.
6076
///
6177
/// - Parameters:
@@ -81,6 +97,8 @@ extension UIView {
8197
width.constraint(constant ?? bounds.width)
8298
}
8399

100+
// MARK: - Height
101+
84102
/// Creates a constraint defining the height of the receiver.
85103
///
86104
/// - Parameters:
@@ -106,21 +124,7 @@ extension UIView {
106124
height.constraint(constant ?? bounds.height)
107125
}
108126

109-
/// Creates constraints defining the size of the receiver.
110-
///
111-
/// - Parameter size: The constant size value. When `nil`, the size of the receiver is used.
112-
///
113-
/// - Returns: The created constraints.
114-
public func sizeConstraints(
115-
_ size: CGSize? = nil
116-
) -> [NSLayoutConstraint] {
117-
[
118-
width.constraint(size?.width ?? bounds.width),
119-
height.constraint(size?.height ?? bounds.height)
120-
]
121-
}
122-
123-
// MARK: - Aspect Ratio
127+
// MARK: - Square
124128

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

136+
// MARK: - Aspect Ratio
137+
132138
/// Creates a constraint defining the aspect ratio of the receiver.
133139
///
134140
/// - Parameter ratio: The aspect ratio.

Tests/LayoutTests/LayoutItemTests.swift

+21-15
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ final class LayoutItemTests: XCTestCase {
105105
}
106106
}
107107

108+
// MARK: - Width
109+
108110
func testWidthIsRelationToConstantPriority() {
109111

110112
// swiftlint:disable:next closure_body_length
@@ -193,6 +195,8 @@ final class LayoutItemTests: XCTestCase {
193195
}
194196
}
195197

198+
// MARK: - Height
199+
196200
func testHeightIsRelationToConstantPriority() {
197201

198202
// swiftlint:disable:next closure_body_length
@@ -281,52 +285,54 @@ final class LayoutItemTests: XCTestCase {
281285
}
282286
}
283287

284-
// MARK: - Aspect Ratio
288+
// MARK: - Square
285289

286-
func testSquare() {
290+
func testSquareWithLengthPriority() {
287291
assertLayout { view in
288292
view.layout {
289293

290-
// Square with Width
294+
// Square Length with Default Priority
291295

292296
pinkView
293297
.to([.top, .leading])
294-
.width(100)
295-
.square()
298+
.square(200, priority: .high)
299+
.square(100)
296300

297-
// Square with Height
301+
// Square Length with Priority
298302

299303
yellowView
300304
.to([.top, .trailing])
301-
.height(100)
302-
.square()
305+
.square(25, priority: .low)
306+
.square(100, priority: .high)
303307
}
304308
.activate()
305309
}
306310
}
307311

308-
func testSquareWithLengthPriority() {
312+
func testSquare() {
309313
assertLayout { view in
310314
view.layout {
311315

312-
// Square Length with Default Priority
316+
// Square with Width
313317

314318
pinkView
315319
.to([.top, .leading])
316-
.square(200, priority: .high)
317-
.square(100)
320+
.width(100)
321+
.square()
318322

319-
// Square Length with Priority
323+
// Square with Height
320324

321325
yellowView
322326
.to([.top, .trailing])
323-
.square(25, priority: .low)
324-
.square(100, priority: .high)
327+
.height(100)
328+
.square()
325329
}
326330
.activate()
327331
}
328332
}
329333

334+
// MARK: - Aspect Ratio
335+
330336
func testAspectRatioWithRatioPriority() {
331337
assertLayout { view in
332338
view.layout {

Tests/LayoutTests/LayoutTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ final class LayoutTests: XCTestCase {
14021402
expect(layout.constraints[1].priority) == UILayoutPriority.high
14031403
}
14041404

1405-
// MARK: - Update
1405+
// MARK: - Animation
14061406

14071407
func testUpdate() {
14081408

0 commit comments

Comments
 (0)