Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toEdges(top: leading: bottom: trailing:) and test #221

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Sources/Layout/LayoutItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,27 @@ extension LayoutItem {
}
}

/// Constrains the view's directional edges to the superview's edges with insets.
///
/// - Parameters:
/// - top: The top inset
/// - leading: The leading inset
/// - bottom: The bottom inset
/// - trailing: The trailing inset
/// - priority: The priority of the constraints
///
/// - Returns: The LayoutItem instance
public func toEdges(
top: CGFloat,
leading: CGFloat,
bottom: CGFloat,
trailing: CGFloat,
priority: UILayoutPriority = .required
) -> LayoutItem {
toEdges(insets: NSDirectionalEdgeInsets(top: top, leading: leading, bottom: bottom, trailing: trailing),
priority: priority)
}

/// Constrains the view's directional edges to the superview's edges with an inset.
///
/// - Parameters:
Expand Down
18 changes: 18 additions & 0 deletions Tests/LayoutTests/LayoutItemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,24 @@ final class LayoutItemTests: XCTestCase {
}
}

func testToEdgesWithTopLeadingBottomTrailingPriority() {
assertLayout { view in
view.layout {

// To Edges with Top, Leading, Bottom, Trailing

pinkView
.toEdges(top: 10, leading: 20, bottom: 10, trailing: 20)

// To Edges with Top, Leading, Bottom, Trailing with Priority

blueView
.toEdges(top: 30, leading: 30, bottom: 30, trailing: 30, priority: .low)
.toEdges(top: 50, leading: 50, bottom: 50, trailing: 50, priority: .high)
}
}
}

func testToEdgesWithDirectionalEdgesInsetPriority() {
assertLayout { view in
view.layout {
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
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 375, height: 812)>
| <View; name = Pink; frame = (x: 20, y: 10, width: 335, height: 792)>
| <View; name = Blue; frame = (x: 50, y: 50, width: 275, height: 712)>
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
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 390, height: 844)>
| <View; name = Pink; frame = (x: 20, y: 10, width: 350, height: 824)>
| <View; name = Blue; frame = (x: 50, y: 50, width: 290, height: 744)>
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
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 375, height: 667)>
| <View; name = Pink; frame = (x: 20, y: 10, width: 335, height: 647)>
| <View; name = Blue; frame = (x: 50, y: 50, width: 275, height: 567)>
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
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 320, height: 568)>
| <View; name = Pink; frame = (x: 20, y: 10, width: 280, height: 548)>
| <View; name = Blue; frame = (x: 50, y: 50, width: 220, height: 468)>
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
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 375, height: 812)>
| <View; name = Pink; frame = (x: 20, y: 10, width: 335, height: 792)>
| <View; name = Blue; frame = (x: 50, y: 50, width: 275, height: 712)>