Skip to content

Commit c9f1866

Browse files
author
Cleber Silva dos Reis
committed
feat[ProfileHeaderView]: header view
1 parent da0c630 commit c9f1866

File tree

4 files changed

+142
-1
lines changed

4 files changed

+142
-1
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
//
2+
// UserProfileHeaderView.swift
3+
// FinanceApp
4+
//
5+
// Created by Cleber Reis on 18/10/22.
6+
//
7+
8+
import UIKit
9+
10+
final class UserProfileHeaderView: UIView {
11+
12+
private lazy var stackViewProfile: UIStackView = {
13+
let stack = UIStackView()
14+
stack.translatesAutoresizingMaskIntoConstraints = false
15+
stack.axis = .vertical
16+
stack.spacing = 8
17+
stack.alignment = .center
18+
19+
return stack
20+
}()
21+
22+
private lazy var profileImage: UIImageView = {
23+
let image = UIImageView()
24+
image.translatesAutoresizingMaskIntoConstraints = false
25+
image.image = UIImage(named: "avatar-placeholder")
26+
image.contentMode = .scaleAspectFill
27+
image.layer.cornerRadius = 40
28+
image.layer.masksToBounds = true
29+
30+
return image
31+
}()
32+
33+
private lazy var titleLabel: UILabel = {
34+
let label = UILabel()
35+
label.translatesAutoresizingMaskIntoConstraints = false
36+
label.font = .systemFont(ofSize: 18, weight: .bold)
37+
label.text = "Irma Flores"
38+
label.textColor = .black
39+
40+
return label
41+
}()
42+
43+
private lazy var agencyLabel: UILabel = {
44+
let label = UILabel()
45+
label.translatesAutoresizingMaskIntoConstraints = false
46+
label.text = "Agency 001"
47+
label.font = .systemFont(ofSize: 14, weight: .regular)
48+
label.textColor = .lightGray
49+
50+
return label
51+
}()
52+
53+
private lazy var accountLabel: UILabel = {
54+
let label = UILabel()
55+
label.translatesAutoresizingMaskIntoConstraints = false
56+
label.text = "Account 123456-7"
57+
label.font = .systemFont(ofSize: 14, weight: .regular)
58+
label.textColor = .lightGray
59+
60+
return label
61+
}()
62+
63+
private lazy var bankLabel: UILabel = {
64+
let label = UILabel()
65+
label.translatesAutoresizingMaskIntoConstraints = false
66+
label.text = "DEVPASS Bank"
67+
label.font = .systemFont(ofSize: 14, weight: .regular)
68+
label.textColor = .lightGray
69+
70+
return label
71+
}()
72+
73+
override init(frame: CGRect) {
74+
super.init(frame: frame)
75+
backgroundColor = .systemGray5
76+
setupView()
77+
}
78+
79+
@available(*, unavailable)
80+
required init?(coder: NSCoder) {
81+
fatalError("init(coder:) has not been implemented")
82+
}
83+
}
84+
85+
extension UserProfileHeaderView: ViewCodable {
86+
87+
func buildHierarchy() {
88+
addSubview(stackViewProfile)
89+
stackViewProfile.addArrangedSubview(profileImage)
90+
stackViewProfile.addArrangedSubview(titleLabel)
91+
stackViewProfile.addArrangedSubview(agencyLabel)
92+
stackViewProfile.addArrangedSubview(accountLabel)
93+
stackViewProfile.addArrangedSubview(bankLabel)
94+
}
95+
96+
func setupConstraints() {
97+
NSLayoutConstraint.activate([
98+
stackViewProfile.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor, constant: 16),
99+
stackViewProfile.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
100+
stackViewProfile.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
101+
stackViewProfile.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor, constant: -16),
102+
103+
profileImage.heightAnchor.constraint(equalToConstant: 80),
104+
profileImage.widthAnchor.constraint(equalToConstant: 80),
105+
])
106+
}
107+
108+
109+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// UserProfileHeaderViewTests.swift
3+
// FinanceAppTests
4+
//
5+
// Created by Cleber Reis on 18/10/22.
6+
//
7+
8+
9+
@testable import FinanceApp
10+
import SnapshotTesting
11+
import XCTest
12+
13+
final class UserProfileHeaderViewTests: XCTestCase {
14+
15+
private var sut: UserProfileHeaderView?
16+
17+
override func setUp() {
18+
sut = UserProfileHeaderView()
19+
20+
let frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 250)
21+
sut?.frame = frame
22+
}
23+
24+
func test_WhenInitUserProfileHeaderView_ThenView_ShouldHaveValidSnapshot() throws {
25+
let unwrappedSut = try XCTUnwrap(sut)
26+
assertSnapshot(matching: unwrappedSut, as: .image)
27+
}
28+
29+
override func tearDown() {
30+
sut = nil
31+
}
32+
}

solutions/devsprint-caio-santos-7/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ SPEC CHECKSUMS:
1313

1414
PODFILE CHECKSUM: 943c16186866fd17226e49884f6360bcda0046f8
1515

16-
COCOAPODS: 1.11.3
16+
COCOAPODS: 1.11.2

0 commit comments

Comments
 (0)