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

Delete toSafeArea methods #155

Merged
merged 2 commits into from
Oct 17, 2023
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
100 changes: 0 additions & 100 deletions Sources/Layout/LayoutItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,106 +402,6 @@ extension LayoutItem {
}
}

/// Constrains the edges to the superview's safeAreaGuide with `insets`
///
/// - Postcondition:
/// Device must be running iOS 11 or higher
/// - Parameters:
/// - insets: (optional) insets of view
/// - priority: (optional) priority of constraint
public func toSafeArea(
insets: NSDirectionalEdgeInsets = .zero,
priority: UILayoutPriority = .required
) -> LayoutItem {
self
.toSafeArea(.top, insets.top, priority: priority)
.toSafeArea(.trailing, -insets.trailing, priority: priority)
.toSafeArea(.bottom, -insets.bottom, priority: priority)
.toSafeArea(.leading, insets.leading, priority: priority)
}

/// Constrains the edges to the superview's safeAreaGuide with an `inset`
///
/// - Postcondition:
/// Device must be running iOS 11 or higher
/// - Parameters:
/// - inset: inset of view
/// - priority: (optional) priority of constraint
public func toSafeArea(
_ inset: CGFloat,
priority: UILayoutPriority = .required
) -> LayoutItem {
toSafeArea(insets: NSDirectionalEdgeInsets(top: inset, leading: inset, bottom: inset, trailing: inset),
priority: priority)
}

/// Constrains the `attribute` to the superview's corresponding safeAreaGuide `attribute`
///
/// - Postcondition:
/// Device must be running iOS 11 or higher
/// - Note:
/// Equation: view.attribute = superview.attribute + constant
/// - Parameters:
/// - attribute: attribute to constrain
/// - constant: (optional) constant
/// - priority: (optional) priority of constraint
public func toSafeArea(
_ attribute: XAxisAttribute,
_ constant: CGFloat = 0,
priority: UILayoutPriority = .required
) -> LayoutItem {
toSafeAreaAttribute(attribute, constant, priority: priority)
}

/// Constrains the `attribute` to the superview's corresponding safeAreaGuide `attribute`
///
/// - Postcondition:
/// Device must be running iOS 11 or higher
/// - Note:
/// Equation: view.attribute = superview.attribute + constant
/// - Parameters:
/// - attribute: attribute to constrain
/// - constant: (optional) constant
/// - priority: (optional) priority of constraint
public func toSafeArea(
_ attribute: YAxisAttribute,
_ constant: CGFloat = 0,
priority: UILayoutPriority = .required
) -> LayoutItem {
toSafeAreaAttribute(attribute, constant, priority: priority)
}

/// Constrains the `attribute` to the superview's corresponding safeAreaGuide `attribute`
///
/// - Postcondition:
/// Device must be running iOS 11 or higher
/// - Note:
/// Equation: view.attribute = superview.attribute + constant
/// - Parameters:
/// - attribute: attribute to constrain
/// - constant: (optional) constant
/// - priority: (optional) priority of constraint
public func toSafeArea(
_ attribute: DimensionAttribute,
_ constant: CGFloat = 0,
priority: UILayoutPriority = .required
) -> LayoutItem {
toSafeAreaAttribute(attribute, constant, priority: priority)
}

private func toSafeAreaAttribute<T: AnchorAttribute>(
_ attribute: T,
_ constant: CGFloat = 0,
priority: UILayoutPriority = .required
) -> LayoutItem {
addingSuperviewConstraints {
if let safeAnchor = $0.safeAreaGuide?.anchor(for: attribute) {
let viewAnchor: NSLayoutAnchor<T.AnchorType> = $0.layoutItemView.anchor(for: attribute)
viewAnchor.constraint(equalTo: safeAnchor, constant: constant).withPriority(priority)
}
}
}

// swiftlint:enable anonymous_argument_in_multiline_closure

private func constraint(
Expand Down
200 changes: 0 additions & 200 deletions Tests/LayoutTests/LayoutItemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -456,206 +456,6 @@ final class LayoutItemTests: XCTestCase {
}
}

func testToSafeAreaInsetZero() {
assertLayout { view in
view.layout(pinkView.toSafeArea(0))
}
}

func testToSafeAreaInsetTen() {
assertLayout { view in
view.layout(pinkView.toSafeArea(10))
}
}

func testToSafeAreaInsetPriority() {
assertLayout { view in
view.layout {
pinkView
.toSafeArea(10, priority: .low)
.toSafeArea(0, priority: .high)
blueView
.toSafeArea(0, priority: .low)
.toSafeArea(10, priority: .high)
}
}
}

func testToSafeArea() {
assertLayout { view in
view.layout(pinkView.toSafeArea())
}
}

func testToSafeAreaInsets() {

// GIVEN

let insets: NSDirectionalEdgeInsets = .init(top: 10, leading: 10, bottom: 10, trailing: 10)

// THEN

assertLayout { view in
view.layout(pinkView.toSafeArea(insets: insets))
}
}

func testToSafeAreaInsetsPriority() {

// GIVEN

let insets: NSDirectionalEdgeInsets = .init(top: 10, leading: 10, bottom: 10, trailing: 10)

// THEN

assertLayout { view in
view.layout {
pinkView
.toSafeArea(insets: insets, priority: .low)
.toSafeArea(priority: .high)
blueView
.toSafeArea(priority: .low)
.toSafeArea(insets: insets, priority: .high)
}
}
}

func testToSafeArea_andWithInsets_andWithPriority() {

// GIVEN

let smallInsets: NSDirectionalEdgeInsets = .init(top: 25, leading: 25, bottom: 25, trailing: 25)
let largeInsets: NSDirectionalEdgeInsets = .init(top: 50, leading: 50, bottom: 50, trailing: 50)

// THEN

assertLayout { view in
view.layout {

// To Safe Area

pinkView
.toSafeArea()

// To Safe Area with Insets

yellowView
.toSafeArea(insets: smallInsets)

// To Safe Area with Priority

blueView
.toSafeArea(insets: smallInsets, priority: .low)
.toSafeArea(insets: largeInsets, priority: .high)
}
}
}

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

// To Safe Area Inset

pinkView
.toSafeArea(25)

// To Safe Area Inset with Priority

yellowView
.toSafeArea(25, priority: .low)
.toSafeArea(50, priority: .high)
}
}
}

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

// To Safe Area XAttribute

pinkView
.size(width: 100, height: 100)
.to(.top)
.toSafeArea(.leading)

// To Safe Area XAttribute with Constant

yellowView
.size(width: 100, height: 100)
.to(.top)
.toSafeArea(.trailing, -100)

// To Safe Area XAttribute with Priority

blueView
.size(width: 100, height: 100)
.to(.bottom)
.toSafeArea(.leading, 50, priority: .low)
.toSafeArea(.leading, 100, priority: .high)
}
}
}

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

// To Safe Area YAttribute

pinkView
.size(width: 100, height: 100)
.to(.leading)
.toSafeArea(.top)

// To Safe Area YAttribute with Constant

yellowView
.size(width: 100, height: 100)
.to(.trailing)
.toSafeArea(.top, 100)

// To Safe Area YAttribute with Priority

blueView
.size(width: 100, height: 100)
.to(.leading)
.toSafeArea(.bottom, -50, priority: .low)
.toSafeArea(.bottom, -100, priority: .high)
}
}
}

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

// To Safe Area DimensionAttribute

pinkView
.size(width: 50)
.to([.leading, .bottom])
.toSafeArea(.height)

// To Safe Area DimensionAttribute with Constant

yellowView
.size(height: 50)
.to([.top, .leading])
.toSafeArea(.width, -50)

// To Safe Area DimensionAttribute with Priority

blueView
.size(width: 50)
.to([.trailing, .bottom])
.toSafeArea(.height, -250, priority: .low)
.toSafeArea(.height, -50, priority: .high)
}
}
}

func testViewLayoutItemLayoutAnchoring() {

// GIVEN
Expand Down
Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.
Loading