Skip to content

Commit

Permalink
Delete toSafeArea methods (#155)
Browse files Browse the repository at this point in the history
* Delete toSafeArea methods

* Delete all snapshots and record
  • Loading branch information
tinder-garricnahapetian authored Oct 17, 2023
1 parent 0906b18 commit c5224d8
Show file tree
Hide file tree
Showing 112 changed files with 0 additions and 465 deletions.
100 changes: 0 additions & 100 deletions Sources/Layout/LayoutItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -440,106 +440,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 @@ -488,206 +488,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

0 comments on commit c5224d8

Please sign in to comment.