Skip to content

Commit

Permalink
Merge branch 'main' into add-landscape-orientation-tests
Browse files Browse the repository at this point in the history
# Conflicts:
#	Tests/LayoutTests/LayoutItemTests.swift
#	Tests/LayoutTests/LayoutTests.swift
#	Tests/LayoutTests/UIView+AutoLayoutTests.swift
  • Loading branch information
tinder-emanharoutunian committed Dec 5, 2023
2 parents ff3bda8 + 4b4ad21 commit 2f1b4db
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 466 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/cocoapods.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
DIRECTORY_NAME=$(echo "${PWD##*/}" | tr '[:upper:]' '[:lower:]')
"$(find ".build/artifacts/${DIRECTORY_NAME}" -type f -name swiftlint -perm +111 -print -quit)" \
lint --strict --reporter github-actions-logging
- name: Resolve package dependencies
run: xcodebuild -resolvePackageDependencies
- name: Build
run: xcodebuild build-for-testing -scheme "Layout" -destination "name=$SIMULATOR,OS=latest"
- name: Run tests
Expand Down
22 changes: 0 additions & 22 deletions Layout.podspec

This file was deleted.

2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
 
[![Bazel](https://github.com/Tinder/Layout/actions/workflows/bazel.yml/badge.svg?event=push)](https://github.com/Tinder/Layout/actions/workflows/bazel.yml)
 
[![CocoaPods](https://github.com/Tinder/Layout/actions/workflows/cocoapods.yml/badge.svg?event=push)](https://github.com/Tinder/Layout/actions/workflows/cocoapods.yml)
 
[![Artifactory](https://github.com/Tinder/Layout/actions/workflows/artifactory.yml/badge.svg?event=push)](https://github.com/Tinder/Layout/actions/workflows/artifactory.yml)

# Layout
Expand Down
178 changes: 89 additions & 89 deletions Sources/Layout/LayoutItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,95 @@ extension LayoutItem {
to(axis.attribute, multiplier: multiplier, constant: offset, priority: priority)
}

/// Vertically centers the view between two anchors.
///
/// - Parameters:
/// - between: the top layout anchor (1)
/// - and: the bottom layout anchor (2)
/// - Example:
/// ```
/// view.layout(
/// label
/// .to(.centerX)
/// .center(between: view.safeAreaLayoutGuide.top, and: siblingView.top),
/// siblingView.center()
/// ).activate()
///
/// +---------(1)---------+
/// | |
/// | label |
/// | |
/// | +--(2)--+ |
/// | | | |
/// | | | |
/// | | | |
/// | +-------+ |
/// | |
/// | |
/// +---------------------+
/// ```
public func center(
between top: NSLayoutYAxisAnchor,
and bottom: NSLayoutYAxisAnchor
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let superview = layoutItem.layoutItemView.superview {
let guide: UILayoutGuide = {
let guide: UILayoutGuide = .init()
superview.addLayoutGuide(guide)
return guide
}()
guide.top.constraint(to: top)
guide.bottom.constraint(to: bottom)
layoutItem.layoutItemView.centerY.constraint(to: guide.centerY)
}
}
}

/// Horizontally centers the view between two anchors.
///
/// - Parameters:
/// - between: the leading layout anchor (1)
/// - and: the trailing layout anchor (2)
/// - Example:
/// ```
/// view.layout(
/// label
/// .to(.centerY)
/// .center(between: siblingView.trailing, and: view.safeAreaLayoutGuide.trailing),
/// siblingView.center().square(50)
/// ).activate()
///
/// +------------------------------+
/// | |
/// | |
/// | +------+ |
/// | | | |
/// | | (1) label (2)
/// | | | |
/// | +------+ |
/// | |
/// | |
/// +------------------------------+
/// ```
public func center(
between leading: NSLayoutXAxisAnchor,
and trailing: NSLayoutXAxisAnchor
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let superview = layoutItem.layoutItemView.superview {
let guide: UILayoutGuide = {
let guide: UILayoutGuide = .init()
superview.addLayoutGuide(guide)
return guide
}()
guide.leading.constraint(to: leading)
guide.trailing.constraint(to: trailing)
layoutItem.layoutItemView.centerX.constraint(to: guide.centerX)
}
}
}

/// Constrains the `attribute` to the superview's corresponding `attribute`
///
/// - Note:
Expand Down Expand Up @@ -478,95 +567,6 @@ extension LayoutItem {
}
}

/// Vertically centers the view between two anchors.
///
/// - Parameters:
/// - between: the top layout anchor (1)
/// - and: the bottom layout anchor (2)
/// - Example:
/// ```
/// view.layout(
/// label
/// .to(.centerX)
/// .center(between: view.safeAreaLayoutGuide.top, and: siblingView.top),
/// siblingView.center()
/// ).activate()
///
/// +---------(1)---------+
/// | |
/// | label |
/// | |
/// | +--(2)--+ |
/// | | | |
/// | | | |
/// | | | |
/// | +-------+ |
/// | |
/// | |
/// +---------------------+
/// ```
public func center(
between top: NSLayoutYAxisAnchor,
and bottom: NSLayoutYAxisAnchor
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let superview = layoutItem.layoutItemView.superview {
let guide: UILayoutGuide = {
let guide: UILayoutGuide = .init()
superview.addLayoutGuide(guide)
return guide
}()
guide.top.constraint(to: top)
guide.bottom.constraint(to: bottom)
layoutItem.layoutItemView.centerY.constraint(to: guide.centerY)
}
}
}

/// Horizontally centers the view between two anchors.
///
/// - Parameters:
/// - between: the leading layout anchor (1)
/// - and: the trailing layout anchor (2)
/// - Example:
/// ```
/// view.layout(
/// label
/// .to(.centerY)
/// .center(between: siblingView.trailing, and: view.safeAreaLayoutGuide.trailing),
/// siblingView.center().square(50)
/// ).activate()
///
/// +------------------------------+
/// | |
/// | |
/// | +------+ |
/// | | | |
/// | | (1) label (2)
/// | | | |
/// | +------+ |
/// | |
/// | |
/// +------------------------------+
/// ```
public func center(
between leading: NSLayoutXAxisAnchor,
and trailing: NSLayoutXAxisAnchor
) -> LayoutItem {
addingSuperviewConstraints { layoutItem in
if let superview = layoutItem.layoutItemView.superview {
let guide: UILayoutGuide = {
let guide: UILayoutGuide = .init()
superview.addLayoutGuide(guide)
return guide
}()
guide.leading.constraint(to: leading)
guide.trailing.constraint(to: trailing)
layoutItem.layoutItemView.centerX.constraint(to: guide.centerX)
}
}
}

/// Constrains the view's directional edges to the superview's safe area with insets.
///
/// - Parameters:
Expand Down
10 changes: 5 additions & 5 deletions Sources/Layout/UIView+Autolayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ extension UIView {

public func constrain(
to superview: UIView,
directionalEdgeInsets: DirectionalInsets = .zero
insets: DirectionalInsets = .zero
) {
translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
leading.constraint(equalTo: superview.leading, constant: directionalEdgeInsets.leading),
trailing.constraint(equalTo: superview.trailing, constant: -directionalEdgeInsets.trailing),
top.constraint(equalTo: superview.top, constant: directionalEdgeInsets.top),
bottom.constraint(equalTo: superview.bottom, constant: -directionalEdgeInsets.bottom)
leading.constraint(equalTo: superview.leading, constant: insets.leading),
trailing.constraint(equalTo: superview.trailing, constant: -insets.trailing),
top.constraint(equalTo: superview.top, constant: insets.top),
bottom.constraint(equalTo: superview.bottom, constant: -insets.bottom)
])
}

Expand Down
Loading

0 comments on commit 2f1b4db

Please sign in to comment.