Skip to content

Commit

Permalink
[closes #22] Add SectionHeaderView
Browse files Browse the repository at this point in the history
  • Loading branch information
ericklborges committed Feb 11, 2021
1 parent 1518b9a commit d2e6e69
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 14 deletions.
59 changes: 59 additions & 0 deletions Interface/Component/SectionHeader/SectionHeaderView.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
8 changes: 0 additions & 8 deletions Interface/Component/SectionHeaderView/SectionHeaderView.swift

This file was deleted.

File renamed without changes.
35 changes: 35 additions & 0 deletions InterfaceTests/Component/SectionHeader/SectionHeaderViewSpec.swift
Original file line number Diff line number Diff line change
@@ -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")
}
}
}
}
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 30 additions & 6 deletions The-Norris.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -101,6 +103,8 @@
3726982225D1FE4B004FD4F9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
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 = "<group>"; };
3726DE9C25D5DCC7008EFE9E /* SectionHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionHeaderView.swift; sourceTree = "<group>"; };
3726DEAE25D5DE1B008EFE9E /* SectionHeaderViewSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionHeaderViewSpec.swift; sourceTree = "<group>"; };
37316AD025D49A6E005C4688 /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
37316AD625D49BD3005C4688 /* Font.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Font.swift; sourceTree = "<group>"; };
37316AE225D49C87005C4688 /* ViewCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewCodable.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -273,6 +277,22 @@
path = "The-NorrisTests";
sourceTree = "<group>";
};
3726DE9B25D5DC98008EFE9E /* SectionHeader */ = {
isa = PBXGroup;
children = (
3726DE9C25D5DCC7008EFE9E /* SectionHeaderView.swift */,
);
path = SectionHeader;
sourceTree = "<group>";
};
3726DEA425D5DDDF008EFE9E /* SectionHeader */ = {
isa = PBXGroup;
children = (
3726DEAE25D5DE1B008EFE9E /* SectionHeaderViewSpec.swift */,
);
path = SectionHeader;
sourceTree = "<group>";
};
37316ACF25D49A64005C4688 /* Resources */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -311,33 +331,35 @@
37316BA025D4A952005C4688 /* Component */ = {
isa = PBXGroup;
children = (
37316BA125D4A95D005C4688 /* TagView */,
3726DE9B25D5DC98008EFE9E /* SectionHeader */,
37316BA125D4A95D005C4688 /* Tag */,
);
path = Component;
sourceTree = "<group>";
};
37316BA125D4A95D005C4688 /* TagView */ = {
37316BA125D4A95D005C4688 /* Tag */ = {
isa = PBXGroup;
children = (
37316BA225D4A96B005C4688 /* TagView.swift */,
);
path = TagView;
path = Tag;
sourceTree = "<group>";
};
37316BAA25D4ACCD005C4688 /* Component */ = {
isa = PBXGroup;
children = (
37316BAB25D4ACD5005C4688 /* TagView */,
3726DEA425D5DDDF008EFE9E /* SectionHeader */,
37316BAB25D4ACD5005C4688 /* Tag */,
);
path = Component;
sourceTree = "<group>";
};
37316BAB25D4ACD5005C4688 /* TagView */ = {
37316BAB25D4ACD5005C4688 /* Tag */ = {
isa = PBXGroup;
children = (
37316BAC25D4ACE2005C4688 /* TagViewSpec.swift */,
);
path = TagView;
path = Tag;
sourceTree = "<group>";
};
37316BB725D4AF2B005C4688 /* Utilities */ = {
Expand Down Expand Up @@ -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 */,
Expand All @@ -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;
Expand Down

0 comments on commit d2e6e69

Please sign in to comment.