Skip to content

Commit d9f2a4c

Browse files
authored
Merge pull request #121 from square/entin/distribution-trailing-closure
Enable trailing closures for distribution builder with parameters
2 parents e5e3185 + 81a5ce6 commit d9f2a4c

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

Paralayout/UIView+Distribution.swift

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ extension UIView {
161161
/// **Examples:**
162162
///
163163
/// To stack two elements with a 10 pt margin between them:
164-
/// ```
164+
/// ```swift
165165
/// // This is effectively the same as [ 1.flexible, icon, 10.fixed, label, 1.flexible ].
166166
/// applyVerticalSubviewDistribution {
167167
/// icon
@@ -171,7 +171,7 @@ extension UIView {
171171
/// ```
172172
///
173173
/// To evenly spread out items:
174-
/// ```
174+
/// ```swift
175175
/// // This is effectively the same as [ 1.flexible, button1, 1.flexible, button2, 1.flexible, button3 ].
176176
/// applyVerticalSubviewDistribution {
177177
/// button1
@@ -181,7 +181,7 @@ extension UIView {
181181
/// ```
182182
///
183183
/// To stack two elements with 50% more space below than above:
184-
/// ```
184+
/// ```swift
185185
/// applyVerticalSubviewDistribution {
186186
/// 2.flexible
187187
/// label
@@ -192,7 +192,7 @@ extension UIView {
192192
/// ```
193193
///
194194
/// To arrange a pair of label on the top and bottom edges of a view, with another label centered between them:
195-
/// ```
195+
/// ```swift
196196
/// applyVerticalSubviewDistribution {
197197
/// 8.fixed
198198
/// headerLabel
@@ -205,45 +205,45 @@ extension UIView {
205205
/// ```
206206
///
207207
/// To arrange UI in a view with an interior margin:
208-
/// ```
209-
/// applyVerticalSubviewDistribution {
208+
/// ```swift
209+
/// applyVerticalSubviewDistribution(inRect: bounds.insetBy(dx: 20, dy: 40)) {
210210
/// icon
211211
/// 10.fixed
212212
/// label
213-
/// }, inRect: bounds.insetBy(dx: 20, dy: 40))
213+
/// }
214214
/// ```
215215
///
216216
/// To arrange UI vertically aligned by their leading edge 10 pt in from the leading edge of their superview:
217-
/// ```
218-
/// applyVerticalSubviewDistribution {
217+
/// ```swift
218+
/// applyVerticalSubviewDistribution(orthogonalOffset: .leading(inset: 10)) {
219219
/// icon
220220
/// 1.flexible
221221
/// button
222-
/// }, orthogonalOffset: .leading(inset: 10))
222+
/// }
223223
/// ```
224224
///
225225
/// To arrange UI vertically without simultaneously centering it horizontally (the `icon` would need independent
226226
/// horizontal positioning):
227-
/// ```
228-
/// applyVerticalSubviewDistribution {
227+
/// ```swift
228+
/// applyVerticalSubviewDistribution(orthogonalOffset: nil) {
229229
/// 1.flexible
230230
/// icon
231231
/// 2.flexible
232-
/// }, orthogonalOffset: nil)
232+
/// }
233233
/// ```
234234
///
235235
/// - precondition: All views in the `distribution` must be subviews of the receiver.
236236
/// - precondition: The `distribution` must not include any given view more than once.
237237
///
238-
/// - parameter distribution: An array of distribution specifiers, ordered from the top edge to the bottom edge.
239238
/// - parameter layoutBounds: The region in the receiver in which to distribute the view in the receiver's
240239
/// coordinate space. Specify `nil` to use the receiver's bounds. Defaults to `nil`.
241240
/// - parameter orthogonalAlignment: The horizontal alignment to apply to the views. If `nil`, views are left in
242241
/// their horizontal position prior to the distribution. Defaults to centered with no offset.
242+
/// - parameter distribution: An array of distribution specifiers, ordered from the top edge to the bottom edge.
243243
public func applyVerticalSubviewDistribution(
244-
@ViewDistributionBuilder _ distribution: () -> [ViewDistributionSpecifying],
245244
inRect layoutBounds: CGRect? = nil,
246-
orthogonalAlignment: HorizontalDistributionAlignment? = .centered(offset: 0)
245+
orthogonalAlignment: HorizontalDistributionAlignment? = .centered(offset: 0),
246+
@ViewDistributionBuilder _ distribution: () -> [ViewDistributionSpecifying]
247247
) {
248248
applyVerticalSubviewDistribution(
249249
distribution(),
@@ -343,7 +343,7 @@ extension UIView {
343343
/// **Examples:**
344344
///
345345
/// To stack two elements with a 10 pt margin between them:
346-
/// ```
346+
/// ```swift
347347
/// // This is effectively the same as [ 1.flexible, icon, 10.fixed, label, 1.flexible ].
348348
/// applyHorizontalSubviewDistribution {
349349
/// icon
@@ -353,7 +353,7 @@ extension UIView {
353353
/// ```
354354
///
355355
/// To evenly spread out items:
356-
/// ```
356+
/// ```swift
357357
/// // This is effectively the same as [ 1.flexible, button1, 1.flexible, button2, 1.flexible, button3 ].
358358
/// applyHorizontalSubviewDistribution {
359359
/// button1
@@ -363,7 +363,7 @@ extension UIView {
363363
/// ```
364364
///
365365
/// To stack two elements with 50% more space after than before:
366-
/// ```
366+
/// ```swift
367367
/// applyHorizontalSubviewDistribution {
368368
/// 2.flexible
369369
/// label
@@ -374,7 +374,7 @@ extension UIView {
374374
/// ```
375375
///
376376
/// To arrange a pair of buttons on the left and right edges of a view, with a label centered between them:
377-
/// ```
377+
/// ```swift
378378
/// applyHorizontalSubviewDistribution {
379379
/// 8.fixed
380380
/// backButton
@@ -387,46 +387,46 @@ extension UIView {
387387
/// ```
388388
///
389389
/// To arrange UI in a view with an interior margin:
390-
/// ```
391-
/// applyHorizontalSubviewDistribution {
390+
/// ```swift
391+
/// applyHorizontalSubviewDistribution(inRect: bounds.insetBy(dx: 20, dy: 40)) {
392392
/// icon
393393
/// 10.fixed
394394
/// label
395-
/// }, inRect: bounds.insetBy(dx: 20, dy: 40))
395+
/// }
396396
/// ```
397397
///
398398
/// To arrange UI horizontally aligned by their top edge 10 pt in from the top edge of their superview:
399-
/// ```
400-
/// applyHorizontalSubviewDistribution {
399+
/// ```swift
400+
/// applyHorizontalSubviewDistribution(orthogonalOffset: .top(inset: 10)) {
401401
/// icon
402402
/// 1.flexible
403403
/// button
404-
/// }, orthogonalOffset: .top(inset: 10))
404+
/// }
405405
/// ```
406406
///
407407
/// To arrange UI horizontally without simultaneously centering it vertically (the `icon` would need independent
408408
/// vertical positioning):
409-
/// ```
410-
/// applyHorizontalSubviewDistribution {
409+
/// ```swift
410+
/// applyHorizontalSubviewDistribution(orthogonalOffset: nil) {
411411
/// 1.flexible
412412
/// icon
413413
/// 2.flexible
414-
/// }, orthogonalOffset: nil)
414+
/// }
415415
/// ```
416416
///
417417
/// - precondition: All views in the `distribution` must be subviews of the receiver.
418418
/// - precondition: The `distribution` must not include any given view more than once.
419419
///
420-
/// - parameter distribution: An array of distribution specifiers, ordered from the leading edge to the trailing
421-
/// edge.
422420
/// - parameter layoutBounds: The region in the receiver in which to distribute the view in the receiver's
423421
/// coordinate space. Specify `nil` to use the receiver's bounds. Defaults to `nil`.
424422
/// - parameter orthogonalAlignment: The vertical alignment to apply to the views. If `nil`, views are left in
425423
/// their vertical position prior to the distribution. Defaults to centered with no offset.
424+
/// - parameter distribution: An array of distribution specifiers, ordered from the leading edge to the trailing
425+
/// edge.
426426
public func applyHorizontalSubviewDistribution(
427-
@ViewDistributionBuilder _ distribution: () -> [ViewDistributionSpecifying],
428427
inRect layoutBounds: CGRect? = nil,
429-
orthogonalAlignment: VerticalDistributionAlignment? = .centered(offset: 0)
428+
orthogonalAlignment: VerticalDistributionAlignment? = .centered(offset: 0),
429+
@ViewDistributionBuilder _ distribution: () -> [ViewDistributionSpecifying]
430430
) {
431431
applyHorizontalSubviewDistribution(
432432
distribution(),

0 commit comments

Comments
 (0)