Skip to content

Commit

Permalink
Add #if swift(>=5.4)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfed committed Apr 21, 2024
1 parent 0476333 commit d23ce15
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ final class ViewDistributionSnapshotTests: SnapshotTestCase {
assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: ["vertical"]))
}

#if swift(>=5.4)
func testDistributionBuilder() {
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
containerView.backgroundColor = .white
Expand All @@ -68,6 +69,7 @@ final class ViewDistributionSnapshotTests: SnapshotTestCase {
}
assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: ["vertical"]))
}
#endif

func testDistributionIgnoresTransform() {
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
Expand Down Expand Up @@ -96,6 +98,7 @@ final class ViewDistributionSnapshotTests: SnapshotTestCase {
assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: []))
}

#if swift(>=5.4)
func testDistributionBuilderIgnoresTransform() {
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
containerView.backgroundColor = .white
Expand All @@ -120,6 +123,7 @@ final class ViewDistributionSnapshotTests: SnapshotTestCase {
}
assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: []))
}
#endif

func testDistributionUsingCapInsets() {
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 80))
Expand Down Expand Up @@ -153,6 +157,7 @@ final class ViewDistributionSnapshotTests: SnapshotTestCase {
assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: []))
}

#if swift(>=5.4)
func testDistributionBuilderUsingCapInsets() {
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 80))
containerView.backgroundColor = .white
Expand Down Expand Up @@ -182,6 +187,7 @@ final class ViewDistributionSnapshotTests: SnapshotTestCase {

assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: []))
}
#endif

func testHorizontalDistributionFollowsLayoutDirection() {
let view = HorizontalDistributionView(frame: CGRect(x: 0, y: 0, width: 160, height: 60))
Expand Down
4 changes: 4 additions & 0 deletions Paralayout/UIView+Distribution.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ extension UIView {
}
}

#if swift(>=5.4)
/// Arranges subviews along the vertical axis according to a distribution with fixed and/or flexible spacers.
///
/// * If there are no flexible elements, this will treat the distribution as vertically centered (i.e. with two
Expand Down Expand Up @@ -250,6 +251,7 @@ extension UIView {
orthogonalAlignment: orthogonalAlignment
)
}
#endif

/// Arranges subviews along the horizontal axis according to a distribution with fixed and/or flexible spacers.
///
Expand Down Expand Up @@ -330,6 +332,7 @@ extension UIView {
}
}

#if swift(>=5.4)
/// Arranges subviews along the horizontal axis according to a distribution with fixed and/or flexible spacers.
///
/// * If there are no flexible elements, this will treat the distribution as horizontally centered (i.e. with two
Expand Down Expand Up @@ -431,6 +434,7 @@ extension UIView {
orthogonalAlignment: orthogonalAlignment
)
}
#endif

// MARK: - Private Methods

Expand Down
2 changes: 2 additions & 0 deletions Paralayout/ViewDistributionBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import UIKit

#if swift(>=5.4)
@resultBuilder
public struct ViewDistributionBuilder {

Expand Down Expand Up @@ -88,3 +89,4 @@ public struct ViewDistributionBuilder {
components.flatMap { $0 }
}
}
#endif

0 comments on commit d23ce15

Please sign in to comment.