From 219e752ac3199698d47ce0575b87c8bf37c87afc Mon Sep 17 00:00:00 2001 From: Garric Nahapetian Date: Tue, 17 Oct 2023 15:20:13 -0700 Subject: [PATCH 01/10] Move ViewLayoutItem to ViewLayoutItem.swift --- Sources/Layout/LayoutItem.swift | 19 ------------------- Sources/Layout/ViewLayoutItem.swift | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 Sources/Layout/ViewLayoutItem.swift diff --git a/Sources/Layout/LayoutItem.swift b/Sources/Layout/LayoutItem.swift index 1491087b..760782da 100644 --- a/Sources/Layout/LayoutItem.swift +++ b/Sources/Layout/LayoutItem.swift @@ -13,8 +13,6 @@ import UIKit public typealias SuperviewConstraints = (LayoutItem) -> [NSLayoutConstraint] -// swiftlint:disable file_types_order - /// Items to be used with the `Layout` API /// /// - Note: @@ -43,22 +41,6 @@ extension UIView: LayoutItem { } } -// swiftlint:enable file_types_order - -internal final class ViewLayoutItem: LayoutItem { - - internal let layoutItemView: UIView - internal let superviewConstraints: SuperviewConstraints - - internal init( - layoutItemView: UIView, - superviewConstraints: @escaping SuperviewConstraints - ) { - self.layoutItemView = layoutItemView - self.superviewConstraints = superviewConstraints - } -} - extension LayoutItem { public var identifier: String? { @@ -521,7 +503,6 @@ extension LayoutItem { } } -// swiftlint:disable:next no_grouping_extension extension ViewLayoutItem: LayoutAnchoring { public var left: NSLayoutXAxisAnchor { layoutItemView.left } diff --git a/Sources/Layout/ViewLayoutItem.swift b/Sources/Layout/ViewLayoutItem.swift new file mode 100644 index 00000000..ba50a0ad --- /dev/null +++ b/Sources/Layout/ViewLayoutItem.swift @@ -0,0 +1,24 @@ +// +// 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 + +internal final class ViewLayoutItem: LayoutItem { + + internal let layoutItemView: UIView + internal let superviewConstraints: SuperviewConstraints + + internal init( + layoutItemView: UIView, + superviewConstraints: @escaping SuperviewConstraints + ) { + self.layoutItemView = layoutItemView + self.superviewConstraints = superviewConstraints + } +} From dec2c3d11fc28b4b5d37c836ab40c7e9d8220a75 Mon Sep 17 00:00:00 2001 From: Garric Nahapetian Date: Wed, 25 Oct 2023 15:05:00 -0700 Subject: [PATCH 02/10] Add testInit --- Sources/Layout/LayoutItem.swift | 1 - Tests/LayoutTests/ViewLayoutItemTests.swift | 34 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 Tests/LayoutTests/ViewLayoutItemTests.swift diff --git a/Sources/Layout/LayoutItem.swift b/Sources/Layout/LayoutItem.swift index 740b3eb2..a7c7ac35 100644 --- a/Sources/Layout/LayoutItem.swift +++ b/Sources/Layout/LayoutItem.swift @@ -743,7 +743,6 @@ extension LayoutItem { } } -// swiftlint:disable:next no_grouping_extension extension ViewLayoutItem { public var left: NSLayoutXAxisAnchor { layoutItemView.left } diff --git a/Tests/LayoutTests/ViewLayoutItemTests.swift b/Tests/LayoutTests/ViewLayoutItemTests.swift new file mode 100644 index 00000000..cfbce69c --- /dev/null +++ b/Tests/LayoutTests/ViewLayoutItemTests.swift @@ -0,0 +1,34 @@ +// +// 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. +// + +@testable import Layout +import Nimble +import XCTest + +final class ViewLayoutItemTests: XCTestCase { + + func testInit() { + + // GIVEN + + let parentView: UIView = .init() + let childView: UIView = .init() + let constraint: NSLayoutConstraint = .init() + + // WHEN + + let viewLayoutItem: ViewLayoutItem = .init(layoutItemView: childView) { _ in [constraint] } + + // THEN + + expect(viewLayoutItem.layoutItemView) == childView + expect(viewLayoutItem.superviewConstraints(parentView).count) == 1 + expect(viewLayoutItem.superviewConstraints(parentView)[0]).to(match(constraint)) + } +} From 6ba821a59e1c10a7e42090f12bd997c84f64d4fd Mon Sep 17 00:00:00 2001 From: Garric Nahapetian <31713341+tinder-garricnahapetian@users.noreply.github.com> Date: Mon, 30 Oct 2023 18:25:54 -0700 Subject: [PATCH 03/10] Improve tests Co-authored-by: Christopher Fuller --- Tests/LayoutTests/ViewLayoutItemTests.swift | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Tests/LayoutTests/ViewLayoutItemTests.swift b/Tests/LayoutTests/ViewLayoutItemTests.swift index cfbce69c..601867c9 100644 --- a/Tests/LayoutTests/ViewLayoutItemTests.swift +++ b/Tests/LayoutTests/ViewLayoutItemTests.swift @@ -17,18 +17,16 @@ final class ViewLayoutItemTests: XCTestCase { // GIVEN - let parentView: UIView = .init() - let childView: UIView = .init() + let view: UIView = .init() let constraint: NSLayoutConstraint = .init() // WHEN - let viewLayoutItem: ViewLayoutItem = .init(layoutItemView: childView) { _ in [constraint] } + let viewLayoutItem: ViewLayoutItem = .init(layoutItemView: view) { _ in [constraint] } // THEN - expect(viewLayoutItem.layoutItemView) == childView - expect(viewLayoutItem.superviewConstraints(parentView).count) == 1 - expect(viewLayoutItem.superviewConstraints(parentView)[0]).to(match(constraint)) + expect(viewLayoutItem.layoutItemView) == view + expect(viewLayoutItem.superviewConstraints(UIView())) === [constraint] } } From 673d368317de03839c915e175f9f17802b557489 Mon Sep 17 00:00:00 2001 From: Garric Nahapetian Date: Mon, 30 Oct 2023 18:57:27 -0700 Subject: [PATCH 04/10] Fix test --- Tests/LayoutTests/ViewLayoutItemTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/LayoutTests/ViewLayoutItemTests.swift b/Tests/LayoutTests/ViewLayoutItemTests.swift index 601867c9..bff9e200 100644 --- a/Tests/LayoutTests/ViewLayoutItemTests.swift +++ b/Tests/LayoutTests/ViewLayoutItemTests.swift @@ -27,6 +27,6 @@ final class ViewLayoutItemTests: XCTestCase { // THEN expect(viewLayoutItem.layoutItemView) == view - expect(viewLayoutItem.superviewConstraints(UIView())) === [constraint] + expect(viewLayoutItem.superviewConstraints(UIView())[0]) === constraint } } From 4bfe704f2448b5619784773e36d27043c18dfd18 Mon Sep 17 00:00:00 2001 From: Garric Nahapetian Date: Tue, 31 Oct 2023 08:14:41 -0700 Subject: [PATCH 05/10] Fix test --- Tests/LayoutTests/ViewLayoutItemTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/LayoutTests/ViewLayoutItemTests.swift b/Tests/LayoutTests/ViewLayoutItemTests.swift index bff9e200..5b7d3419 100644 --- a/Tests/LayoutTests/ViewLayoutItemTests.swift +++ b/Tests/LayoutTests/ViewLayoutItemTests.swift @@ -27,6 +27,6 @@ final class ViewLayoutItemTests: XCTestCase { // THEN expect(viewLayoutItem.layoutItemView) == view - expect(viewLayoutItem.superviewConstraints(UIView())[0]) === constraint + expect(viewLayoutItem.superviewConstraints(UIView()) === [constraint]) == true } } From f3ce4d2269ae29e7973acf78a358190466534c7e Mon Sep 17 00:00:00 2001 From: Garric Nahapetian Date: Tue, 31 Oct 2023 10:50:38 -0700 Subject: [PATCH 06/10] Improve test --- Tests/LayoutTests/ViewLayoutItemTests.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Tests/LayoutTests/ViewLayoutItemTests.swift b/Tests/LayoutTests/ViewLayoutItemTests.swift index 5b7d3419..8a3663c6 100644 --- a/Tests/LayoutTests/ViewLayoutItemTests.swift +++ b/Tests/LayoutTests/ViewLayoutItemTests.swift @@ -13,20 +13,25 @@ import XCTest final class ViewLayoutItemTests: XCTestCase { - func testInit() { + func testInitalize() { // GIVEN let view: UIView = .init() + let superview: UIView = .init() let constraint: NSLayoutConstraint = .init() // WHEN - let viewLayoutItem: ViewLayoutItem = .init(layoutItemView: view) { _ in [constraint] } + let viewLayoutItem: ViewLayoutItem = .init(layoutItemView: view) { layoutItem in + expect(layoutItem) === superview + return [constraint] + } + let superviewConstraints: [NSLayoutConstraint] = viewLayoutItem.superviewConstraints(superview) // THEN expect(viewLayoutItem.layoutItemView) == view - expect(viewLayoutItem.superviewConstraints(UIView()) === [constraint]) == true + expect(superviewConstraints === [constraint]) == true } } From ecf46c1d063300a6f13322a128407f52fb54d9f0 Mon Sep 17 00:00:00 2001 From: Garric Nahapetian <31713341+tinder-garricnahapetian@users.noreply.github.com> Date: Tue, 31 Oct 2023 11:59:53 -0700 Subject: [PATCH 07/10] Improve test Co-authored-by: Christopher Fuller --- Tests/LayoutTests/ViewLayoutItemTests.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Tests/LayoutTests/ViewLayoutItemTests.swift b/Tests/LayoutTests/ViewLayoutItemTests.swift index 8a3663c6..b70b8056 100644 --- a/Tests/LayoutTests/ViewLayoutItemTests.swift +++ b/Tests/LayoutTests/ViewLayoutItemTests.swift @@ -13,18 +13,19 @@ import XCTest final class ViewLayoutItemTests: XCTestCase { - func testInitalize() { + func testInitalizer() { // GIVEN - let view: UIView = .init() let superview: UIView = .init() + let view: UIView = .init() let constraint: NSLayoutConstraint = .init() + var layoutItems: [LayoutItem] = [] // WHEN let viewLayoutItem: ViewLayoutItem = .init(layoutItemView: view) { layoutItem in - expect(layoutItem) === superview + layoutItems.append(layoutItem) return [constraint] } let superviewConstraints: [NSLayoutConstraint] = viewLayoutItem.superviewConstraints(superview) @@ -33,5 +34,6 @@ final class ViewLayoutItemTests: XCTestCase { expect(viewLayoutItem.layoutItemView) == view expect(superviewConstraints === [constraint]) == true + expect(layoutItems === [view]) == true } } From 0af1bf5b6bdb7c6ffea7921cb8f3cd36e68191ac Mon Sep 17 00:00:00 2001 From: Garric Nahapetian Date: Tue, 31 Oct 2023 12:02:08 -0700 Subject: [PATCH 08/10] Improve test --- Tests/LayoutTests/ViewLayoutItemTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/LayoutTests/ViewLayoutItemTests.swift b/Tests/LayoutTests/ViewLayoutItemTests.swift index b70b8056..d406d7aa 100644 --- a/Tests/LayoutTests/ViewLayoutItemTests.swift +++ b/Tests/LayoutTests/ViewLayoutItemTests.swift @@ -32,8 +32,8 @@ final class ViewLayoutItemTests: XCTestCase { // THEN + expect(layoutItems === [superview]) == true expect(viewLayoutItem.layoutItemView) == view expect(superviewConstraints === [constraint]) == true - expect(layoutItems === [view]) == true } } From 758d83aa09156bd11d32a5ae713cab90c87b6fa0 Mon Sep 17 00:00:00 2001 From: Garric Nahapetian <31713341+tinder-garricnahapetian@users.noreply.github.com> Date: Tue, 31 Oct 2023 12:57:09 -0700 Subject: [PATCH 09/10] Improve test Co-authored-by: Christopher Fuller --- Tests/LayoutTests/ViewLayoutItemTests.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Tests/LayoutTests/ViewLayoutItemTests.swift b/Tests/LayoutTests/ViewLayoutItemTests.swift index d406d7aa..2e42256c 100644 --- a/Tests/LayoutTests/ViewLayoutItemTests.swift +++ b/Tests/LayoutTests/ViewLayoutItemTests.swift @@ -28,12 +28,17 @@ final class ViewLayoutItemTests: XCTestCase { layoutItems.append(layoutItem) return [constraint] } + // THEN + + expect(viewLayoutItem.layoutItemView) == view + + // WHEN + let superviewConstraints: [NSLayoutConstraint] = viewLayoutItem.superviewConstraints(superview) // THEN - expect(layoutItems === [superview]) == true - expect(viewLayoutItem.layoutItemView) == view expect(superviewConstraints === [constraint]) == true + expect(layoutItems === [superview]) == true } } From d09951c7bf6351f8730bb0112b0af612231e9215 Mon Sep 17 00:00:00 2001 From: Garric Nahapetian <31713341+tinder-garricnahapetian@users.noreply.github.com> Date: Tue, 31 Oct 2023 14:28:12 -0700 Subject: [PATCH 10/10] Fix formatting --- Tests/LayoutTests/ViewLayoutItemTests.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/LayoutTests/ViewLayoutItemTests.swift b/Tests/LayoutTests/ViewLayoutItemTests.swift index 2e42256c..a38f26db 100644 --- a/Tests/LayoutTests/ViewLayoutItemTests.swift +++ b/Tests/LayoutTests/ViewLayoutItemTests.swift @@ -28,6 +28,7 @@ final class ViewLayoutItemTests: XCTestCase { layoutItems.append(layoutItem) return [constraint] } + // THEN expect(viewLayoutItem.layoutItemView) == view