diff --git a/Sources/Layout/UIView+Frames.swift b/Sources/Layout/UIView+Frames.swift index 417456d2..7fb27d31 100644 --- a/Sources/Layout/UIView+Frames.swift +++ b/Sources/Layout/UIView+Frames.swift @@ -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] - } -} diff --git a/Sources/Layout/UIView+LayoutAnchor.swift b/Sources/Layout/UIView+NSLayoutAnchor.swift similarity index 100% rename from Sources/Layout/UIView+LayoutAnchor.swift rename to Sources/Layout/UIView+NSLayoutAnchor.swift diff --git a/Sources/Layout/UIView-AutoresizingMask.swift b/Sources/Layout/UIView-AutoresizingMask.swift new file mode 100644 index 00000000..d185dd2e --- /dev/null +++ b/Sources/Layout/UIView-AutoresizingMask.swift @@ -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] + } +} diff --git a/Tests/LayoutTests/UIView+FramesTests.swift b/Tests/LayoutTests/UIView+FramesTests.swift index 37f1b402..c10e4205 100644 --- a/Tests/LayoutTests/UIView+FramesTests.swift +++ b/Tests/LayoutTests/UIView+FramesTests.swift @@ -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 } } diff --git a/Tests/LayoutTests/UIView+LayoutAnchorTests.swift b/Tests/LayoutTests/UIView+NSLayoutAnchorTests.swift similarity index 95% rename from Tests/LayoutTests/UIView+LayoutAnchorTests.swift rename to Tests/LayoutTests/UIView+NSLayoutAnchorTests.swift index d3e0271e..5b1afac3 100644 --- a/Tests/LayoutTests/UIView+LayoutAnchorTests.swift +++ b/Tests/LayoutTests/UIView+NSLayoutAnchorTests.swift @@ -13,7 +13,7 @@ import Nimble import UIKit import XCTest -final class UIViewLayoutAnchorTests: XCTestCase { +final class UIViewNSLayoutAnchorTests: XCTestCase { func testAnchorForXAxisAttribute() { diff --git a/Tests/LayoutTests/UIView-AutoresizingMaskTests.swift b/Tests/LayoutTests/UIView-AutoresizingMaskTests.swift new file mode 100644 index 00000000..655ac97a --- /dev/null +++ b/Tests/LayoutTests/UIView-AutoresizingMaskTests.swift @@ -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] + } +} diff --git a/Tests/LayoutTests/LayoutAnchoringTests.swift b/Tests/LayoutTests/UIViewControllerTests.swift similarity index 93% rename from Tests/LayoutTests/LayoutAnchoringTests.swift rename to Tests/LayoutTests/UIViewControllerTests.swift index 5aaec512..cd8beb41 100644 --- a/Tests/LayoutTests/LayoutAnchoringTests.swift +++ b/Tests/LayoutTests/UIViewControllerTests.swift @@ -12,7 +12,7 @@ import Nimble import XCTest @MainActor -final class LayoutAnchoringTests: XCTestCase { +final class UIViewControllerTests: XCTestCase { func testViewControllerSafeAreaLayoutGuides() {