diff --git a/Interface/Component/SectionHeader/SectionHeaderView.swift b/Interface/Component/SectionHeader/SectionHeaderView.swift new file mode 100644 index 0000000..e1e266f --- /dev/null +++ b/Interface/Component/SectionHeader/SectionHeaderView.swift @@ -0,0 +1,59 @@ +// +// SectionHeaderView.swift +// Interface +// +// Created by erick.lozano.borges on 11/02/21. +// + +import UIKit + +class SectionHeaderView: UIView { + + // MARK: - Views + private let label: UILabel = { + let label = UILabel(frame: .zero) + label.numberOfLines = 1 + label.font = Font.header + label.textColor = Color.Text.secondary + return label + }() + + // MARK: - Properties + public var text: String? { + didSet { + label.text = text + } + } + + // MARK: - Life Cycle + init() { + super.init(frame: .zero) + setupViews() + } + + @available(*, unavailable) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} + +// MARK: - Auto Layout + +extension SectionHeaderView: ViewCodable { + func setupViewHierarchy() { + addSubview(label) + } + + func setupConstraints() { + label.layout.applyConstraint { make in + make.topAnchor(equalTo: topAnchor, constant: 8) + make.bottomAnchor(equalTo: bottomAnchor, constant: -8) + make.leadingAnchor(equalTo: leadingAnchor, constant: 16) + make.trailingAnchor(equalTo: trailingAnchor, constant: -16) + } + } + + public func setupAditionalConfiguration() { + backgroundColor = Color.Background.sectionHeader + } +} diff --git a/Interface/Component/SectionHeaderView/SectionHeaderView.swift b/Interface/Component/SectionHeaderView/SectionHeaderView.swift deleted file mode 100644 index bd90966..0000000 --- a/Interface/Component/SectionHeaderView/SectionHeaderView.swift +++ /dev/null @@ -1,8 +0,0 @@ -// -// SectionHeaderView.swift -// Interface -// -// Created by erick.lozano.borges on 11/02/21. -// - -import Foundation diff --git a/Interface/Component/TagView/TagView.swift b/Interface/Component/Tag/TagView.swift similarity index 100% rename from Interface/Component/TagView/TagView.swift rename to Interface/Component/Tag/TagView.swift diff --git a/InterfaceTests/Component/SectionHeader/SectionHeaderViewSpec.swift b/InterfaceTests/Component/SectionHeader/SectionHeaderViewSpec.swift new file mode 100644 index 0000000..ec12bab --- /dev/null +++ b/InterfaceTests/Component/SectionHeader/SectionHeaderViewSpec.swift @@ -0,0 +1,35 @@ +// +// SectionHeaderViewSpec.swift +// Interface +// +// Created by erick.lozano.borges on 11/02/21. +// + +import Quick +import Nimble +import Nimble_Snapshots + +@testable import Interface + +class SectionHeaderSpec: QuickSpec { + override func spec() { + + describe("SectionHeader") { + + var sut: SectionHeaderView! + + context("when initialized") { + beforeEach { + sut = SectionHeaderView() + sut.text = "Section Title" + sut.setDynamicSize(forHeight: 38.0) + } + + it("shuold layout itself properly") { + expect(sut) == snapshot("SectionHeader_Layout") + } + } + } + } +} + diff --git a/InterfaceTests/Component/TagView/TagViewSpec.swift b/InterfaceTests/Component/Tag/TagViewSpec.swift similarity index 100% rename from InterfaceTests/Component/TagView/TagViewSpec.swift rename to InterfaceTests/Component/Tag/TagViewSpec.swift diff --git a/InterfaceTests/ReferenceImages/SectionHeaderViewSpec/SectionHeader_Layout@2x.png b/InterfaceTests/ReferenceImages/SectionHeaderViewSpec/SectionHeader_Layout@2x.png new file mode 100644 index 0000000..0774524 Binary files /dev/null and b/InterfaceTests/ReferenceImages/SectionHeaderViewSpec/SectionHeader_Layout@2x.png differ diff --git a/The-Norris.xcodeproj/project.pbxproj b/The-Norris.xcodeproj/project.pbxproj index 4d5f797..87eefc1 100644 --- a/The-Norris.xcodeproj/project.pbxproj +++ b/The-Norris.xcodeproj/project.pbxproj @@ -19,6 +19,8 @@ 3726981725D1FE45004FD4F9 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3726981625D1FE45004FD4F9 /* SceneDelegate.swift */; }; 3726981E25D1FE4B004FD4F9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3726981D25D1FE4B004FD4F9 /* Assets.xcassets */; }; 3726982125D1FE4B004FD4F9 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3726981F25D1FE4B004FD4F9 /* LaunchScreen.storyboard */; }; + 3726DE9D25D5DCC7008EFE9E /* SectionHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3726DE9C25D5DCC7008EFE9E /* SectionHeaderView.swift */; }; + 3726DEAF25D5DE1B008EFE9E /* SectionHeaderViewSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3726DEAE25D5DE1B008EFE9E /* SectionHeaderViewSpec.swift */; }; 37316AD125D49A6E005C4688 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37316AD025D49A6E005C4688 /* Color.swift */; }; 37316AD725D49BD3005C4688 /* Font.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37316AD625D49BD3005C4688 /* Font.swift */; }; 37316AE325D49C87005C4688 /* ViewCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37316AE225D49C87005C4688 /* ViewCodable.swift */; }; @@ -101,6 +103,8 @@ 3726982225D1FE4B004FD4F9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 3726982725D1FE4C004FD4F9 /* The-NorrisTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "The-NorrisTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 3726982D25D1FE4C004FD4F9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 3726DE9C25D5DCC7008EFE9E /* SectionHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionHeaderView.swift; sourceTree = ""; }; + 3726DEAE25D5DE1B008EFE9E /* SectionHeaderViewSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionHeaderViewSpec.swift; sourceTree = ""; }; 37316AD025D49A6E005C4688 /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = ""; }; 37316AD625D49BD3005C4688 /* Font.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Font.swift; sourceTree = ""; }; 37316AE225D49C87005C4688 /* ViewCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewCodable.swift; sourceTree = ""; }; @@ -273,6 +277,22 @@ path = "The-NorrisTests"; sourceTree = ""; }; + 3726DE9B25D5DC98008EFE9E /* SectionHeader */ = { + isa = PBXGroup; + children = ( + 3726DE9C25D5DCC7008EFE9E /* SectionHeaderView.swift */, + ); + path = SectionHeader; + sourceTree = ""; + }; + 3726DEA425D5DDDF008EFE9E /* SectionHeader */ = { + isa = PBXGroup; + children = ( + 3726DEAE25D5DE1B008EFE9E /* SectionHeaderViewSpec.swift */, + ); + path = SectionHeader; + sourceTree = ""; + }; 37316ACF25D49A64005C4688 /* Resources */ = { isa = PBXGroup; children = ( @@ -311,33 +331,35 @@ 37316BA025D4A952005C4688 /* Component */ = { isa = PBXGroup; children = ( - 37316BA125D4A95D005C4688 /* TagView */, + 3726DE9B25D5DC98008EFE9E /* SectionHeader */, + 37316BA125D4A95D005C4688 /* Tag */, ); path = Component; sourceTree = ""; }; - 37316BA125D4A95D005C4688 /* TagView */ = { + 37316BA125D4A95D005C4688 /* Tag */ = { isa = PBXGroup; children = ( 37316BA225D4A96B005C4688 /* TagView.swift */, ); - path = TagView; + path = Tag; sourceTree = ""; }; 37316BAA25D4ACCD005C4688 /* Component */ = { isa = PBXGroup; children = ( - 37316BAB25D4ACD5005C4688 /* TagView */, + 3726DEA425D5DDDF008EFE9E /* SectionHeader */, + 37316BAB25D4ACD5005C4688 /* Tag */, ); path = Component; sourceTree = ""; }; - 37316BAB25D4ACD5005C4688 /* TagView */ = { + 37316BAB25D4ACD5005C4688 /* Tag */ = { isa = PBXGroup; children = ( 37316BAC25D4ACE2005C4688 /* TagViewSpec.swift */, ); - path = TagView; + path = Tag; sourceTree = ""; }; 37316BB725D4AF2B005C4688 /* Utilities */ = { @@ -659,6 +681,7 @@ 37316B9925D4A716005C4688 /* Asset.swift in Sources */, 37316AD125D49A6E005C4688 /* Color.swift in Sources */, 37316B8C25D49E95005C4688 /* UIView+Anchors.swift in Sources */, + 3726DE9D25D5DCC7008EFE9E /* SectionHeaderView.swift in Sources */, 37316BA325D4A96B005C4688 /* TagView.swift in Sources */, 37316AE325D49C87005C4688 /* ViewCodable.swift in Sources */, 37316B8325D49DFF005C4688 /* ViewCodableDsl.swift in Sources */, @@ -672,6 +695,7 @@ files = ( 376C821B25D5D1DB00965BC6 /* Configuration.swift in Sources */, 37316BAD25D4ACE2005C4688 /* TagViewSpec.swift in Sources */, + 3726DEAF25D5DE1B008EFE9E /* SectionHeaderViewSpec.swift in Sources */, 37316BB925D4AF3F005C4688 /* UIView+DynamicSize.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0;