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

Move ViewLayoutItem to ViewLayoutItem.swift #171

Merged
merged 12 commits into from
Nov 1, 2023
19 changes: 0 additions & 19 deletions Sources/Layout/LayoutItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -34,22 +32,6 @@ public protocol LayoutItem: AnyObject, LayoutBoundary, LayoutCenter, LayoutSize,
var superviewConstraints: SuperviewConstraints { get }
}

// 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? {
Expand Down Expand Up @@ -752,7 +734,6 @@ extension LayoutItem {
}
}

// swiftlint:disable:next no_grouping_extension
extension ViewLayoutItem {

public var left: NSLayoutXAxisAnchor { layoutItemView.left }
Expand Down
24 changes: 24 additions & 0 deletions Sources/Layout/ViewLayoutItem.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
45 changes: 45 additions & 0 deletions Tests/LayoutTests/ViewLayoutItemTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// 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 testInitalizer() {

// GIVEN

let superview: UIView = .init()
let view: UIView = .init()
let constraint: NSLayoutConstraint = .init()
var layoutItems: [LayoutItem] = []

tinder-garricnahapetian marked this conversation as resolved.
Show resolved Hide resolved
// WHEN

let viewLayoutItem: ViewLayoutItem = .init(layoutItemView: view) { layoutItem in
layoutItems.append(layoutItem)
return [constraint]
}

// THEN

expect(viewLayoutItem.layoutItemView) == view

// WHEN

let superviewConstraints: [NSLayoutConstraint] = viewLayoutItem.superviewConstraints(superview)

// THEN

expect(superviewConstraints === [constraint]) == true
tinder-garricnahapetian marked this conversation as resolved.
Show resolved Hide resolved
expect(layoutItems === [superview]) == true
}
}