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

Organize code #247

Merged
merged 6 commits into from
Dec 7, 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
23 changes: 0 additions & 23 deletions Sources/Layout/UIView+Frames.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,3 @@ extension UIView {
return self
}
}

extension UIView.AutoresizingMask {

public static var topLeft: Self {
[.flexibleRightMargin, .flexibleBottomMargin]
}

public static var topRight: Self {
[.flexibleLeftMargin, .flexibleBottomMargin]
}

public static var bottomLeft: Self {
[.flexibleTopMargin, .flexibleRightMargin]
}

public static var bottomRight: Self {
[.flexibleTopMargin, .flexibleLeftMargin]
}

public static var scaleWithSuperview: Self {
[.flexibleWidth, .flexibleHeight]
}
}
34 changes: 34 additions & 0 deletions Sources/Layout/UIView-AutoresizingMask.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// swiftlint:disable:this file_name
//
// All Contributions by Match Group
//
// Copyright © 2023 Tinder (Match Group, LLC)
//
// Licensed under the Match Group Modified 3-Clause BSD License.
// See https://github.com/Tinder/Layout/blob/main/LICENSE for license information.
//

import UIKit

extension UIView.AutoresizingMask {

public static var topLeft: Self {
[.flexibleRightMargin, .flexibleBottomMargin]
}

public static var topRight: Self {
[.flexibleLeftMargin, .flexibleBottomMargin]
}

public static var bottomLeft: Self {
[.flexibleTopMargin, .flexibleRightMargin]
}

public static var bottomRight: Self {
[.flexibleTopMargin, .flexibleLeftMargin]
}

public static var scaleWithSuperview: Self {
[.flexibleWidth, .flexibleHeight]
}
}
101 changes: 15 additions & 86 deletions Tests/LayoutTests/UIView+FramesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,115 +14,44 @@ import XCTest

final class UIViewFramesTests: XCTestCase {

func testDisablingIntrinsicSize() {

// GIVEN

let view: UIView = givenView()

// THEN

expect(view.contentHuggingPriority(for: .horizontal)) == .defaultLow
expect(view.contentHuggingPriority(for: .vertical)) == .defaultLow
expect(view.contentCompressionResistancePriority(for: .horizontal)) == .defaultHigh
expect(view.contentCompressionResistancePriority(for: .vertical)) == .defaultHigh

// WHEN

_ = view.disablingIntrinsicSize()

// THEN

expect(view.contentHuggingPriority(for: .horizontal)) == .disabled
expect(view.contentHuggingPriority(for: .vertical)) == .disabled
expect(view.contentCompressionResistancePriority(for: .horizontal)) == .disabled
expect(view.contentCompressionResistancePriority(for: .vertical)) == .disabled
}

func testUsingFramesTopLeft() {
func testUsingFrames() {

// GIVEN

let view: UIView = givenView()

// WHEN

_ = view.usingFrames(.topLeft)

// THEN

expect(view.autoresizingMask) == [.flexibleRightMargin, .flexibleBottomMargin]
expect(view.translatesAutoresizingMaskIntoConstraints) == true
}

func testUsingFramesTopRight() {

// GIVEN

let view: UIView = givenView()

// WHEN

_ = view.usingFrames(.topRight)

// THEN

expect(view.autoresizingMask) == [.flexibleLeftMargin, .flexibleBottomMargin]
expect(view.translatesAutoresizingMaskIntoConstraints) == true
}

func testUsingFramesBottomLeft() {

// GIVEN

let view: UIView = givenView()
let view: UIView = .init()
view.translatesAutoresizingMaskIntoConstraints = false

// WHEN

_ = view.usingFrames(.bottomLeft)
_ = view.usingFrames()

// THEN

expect(view.autoresizingMask) == [.flexibleTopMargin, .flexibleRightMargin]
expect(view.translatesAutoresizingMaskIntoConstraints) == true
}

func testUsingFramesBottomRight() {
func testDisablingIntrinsicSize() {

// GIVEN

let view: UIView = givenView()

// WHEN

_ = view.usingFrames(.bottomRight)
let view: UIView = .init()

// THEN

expect(view.autoresizingMask) == [.flexibleTopMargin, .flexibleLeftMargin]
expect(view.translatesAutoresizingMaskIntoConstraints) == true
}

func testUsingFramesScaleWithSuperview() {

// GIVEN

let view: UIView = givenView()
expect(view.contentHuggingPriority(for: .horizontal)) == .defaultLow
expect(view.contentHuggingPriority(for: .vertical)) == .defaultLow
expect(view.contentCompressionResistancePriority(for: .horizontal)) == .defaultHigh
expect(view.contentCompressionResistancePriority(for: .vertical)) == .defaultHigh

// WHEN

_ = view.usingFrames(.scaleWithSuperview)
_ = view.disablingIntrinsicSize()

// THEN

expect(view.autoresizingMask) == [.flexibleWidth, .flexibleHeight]
expect(view.translatesAutoresizingMaskIntoConstraints) == true
}

private func givenView() -> UIView {
let view: UIView = .init()
view.autoresizingMask = []
view.translatesAutoresizingMaskIntoConstraints = false
return view
expect(view.contentHuggingPriority(for: .horizontal)) == .disabled
expect(view.contentHuggingPriority(for: .vertical)) == .disabled
expect(view.contentCompressionResistancePriority(for: .horizontal)) == .disabled
expect(view.contentCompressionResistancePriority(for: .vertical)) == .disabled
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Nimble
import UIKit
import XCTest

final class UIViewLayoutAnchorTests: XCTestCase {
final class UIViewNSLayoutAnchorTests: XCTestCase {

func testAnchorForXAxisAttribute() {

Expand Down
73 changes: 73 additions & 0 deletions Tests/LayoutTests/UIView-AutoresizingMaskTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// swiftlint:disable:this file_name
//
// All Contributions by Match Group
//
// Copyright © 2023 Tinder (Match Group, LLC)
//
// Licensed under the Match Group Modified 3-Clause BSD License.
// See https://github.com/Tinder/Layout/blob/main/LICENSE for license information.
//

import Foundation

@testable import Layout
import Nimble
import XCTest

final class UIViewAutoresizingTests: XCTestCase {

func testTopLeftResizingMask() {

// GIVEN

let topLeftResizingMask: UIView.AutoresizingMask = .topLeft

// THEN

expect(topLeftResizingMask) == [.flexibleRightMargin, .flexibleBottomMargin]
}

func testTopRightResizingMask() {

// GIVEN

let topRightResizingMask: UIView.AutoresizingMask = .topRight

// THEN

expect(topRightResizingMask) == [.flexibleLeftMargin, .flexibleBottomMargin]
}

func testBottomLeftResizingMask() {

// GIVEN

let bottomLeftResizingMask: UIView.AutoresizingMask = .bottomLeft

// THEN

expect(bottomLeftResizingMask) == [.flexibleTopMargin, .flexibleRightMargin]
}

func testBottomRightResizingMask() {

// GIVEN

let bottomRightResizingMask: UIView.AutoresizingMask = .bottomRight

// THEN

expect(bottomRightResizingMask) == [.flexibleTopMargin, .flexibleLeftMargin]
}

func testScaleWithSuperviewResizingMask() {

// GIVEN

let scaleWithSuperviewResizingMask: UIView.AutoresizingMask = .scaleWithSuperview

// THEN

expect(scaleWithSuperviewResizingMask) == [.flexibleWidth, .flexibleHeight]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Nimble
import XCTest

@MainActor
final class LayoutAnchoringTests: XCTestCase {
final class UIViewControllerTests: XCTestCase {

func testViewControllerSafeAreaLayoutGuides() {

Expand Down