Skip to content

Commit 3f35520

Browse files
authored
Merge pull request #65 from gabrieldcc/feature/ContactListView
Feature/ Implementar ContactListView && Implementar ContactCellView
2 parents da0c630 + c1171f5 commit 3f35520

File tree

11 files changed

+246
-8
lines changed

11 files changed

+246
-8
lines changed

solutions/devsprint-caio-santos-7/FinanceApp/Screens/ActivityDetails/ActivityDetailsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class ActivityDetailsView: UIView {
2020
return nil
2121
}
2222

23-
// MARK: Interface Elements
23+
// MARK: Visual Components
2424
private lazy var vStack: UIStackView = {
2525
let stack = UIStackView()
2626
stack.translatesAutoresizingMaskIntoConstraints = false
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//
2+
// ContactListView.swift
3+
// FinanceApp
4+
//
5+
// Created by Rodrigo Borges on 30/12/21.
6+
//
7+
8+
import UIKit
9+
10+
final class ContactListTableViewCell: UITableViewCell {
11+
static let identifier = "ContactCellIdentifier"
12+
13+
//MARK: - Init
14+
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
15+
super.init(style: style, reuseIdentifier: reuseIdentifier)
16+
self.accessoryType = .disclosureIndicator
17+
setupView()
18+
}
19+
20+
required init?(coder: NSCoder) {
21+
return nil
22+
}
23+
24+
//MARK: - Visual Components
25+
private lazy var container: UIStackView = {
26+
let element = UIStackView(frame: .zero)
27+
element.translatesAutoresizingMaskIntoConstraints = false
28+
element.axis = .horizontal
29+
element.alignment = .center
30+
element.distribution = .fill
31+
element.spacing = 16
32+
33+
return element
34+
}()
35+
36+
private lazy var userImage: UIImageView = {
37+
let element = UIImageView()
38+
element.translatesAutoresizingMaskIntoConstraints = false
39+
element.image = UIImage(named: "avatar-placeholder")
40+
element.tintColor = .blue
41+
element.layer.cornerRadius = 25
42+
element.layer.masksToBounds = true
43+
44+
return element
45+
}()
46+
47+
private lazy var labelStackView: UIStackView = {
48+
let element = UIStackView()
49+
element.translatesAutoresizingMaskIntoConstraints = false
50+
element.axis = .vertical
51+
element.alignment = .leading
52+
element.distribution = .fill
53+
element.spacing = 4
54+
55+
return element
56+
}()
57+
58+
private lazy var nameLabel: UILabel = {
59+
let element = UILabel()
60+
element.translatesAutoresizingMaskIntoConstraints = false
61+
element.text = "Name"
62+
element.font = UIFont.boldSystemFont(ofSize: 16)
63+
64+
return element
65+
}()
66+
67+
private lazy var phoneNumberLabel: UILabel = {
68+
let element = UILabel()
69+
element.translatesAutoresizingMaskIntoConstraints = false
70+
element.text = "+55 11 99999-9999"
71+
element.textColor = .lightGray
72+
73+
return element
74+
}()
75+
}
76+
77+
//MARK: - ViewCodable
78+
extension ContactListTableViewCell: ViewCodable {
79+
80+
func buildHierarchy() {
81+
addSubview(container)
82+
container.addArrangedSubview(userImage)
83+
container.addArrangedSubview(labelStackView)
84+
labelStackView.addArrangedSubview(nameLabel)
85+
labelStackView.addArrangedSubview(phoneNumberLabel)
86+
}
87+
88+
func setupConstraints() {
89+
90+
let userImageSize: CGFloat = 50
91+
92+
NSLayoutConstraint.activate([
93+
container.topAnchor.constraint(equalTo: topAnchor),
94+
container.trailingAnchor.constraint(equalTo: trailingAnchor),
95+
container.bottomAnchor.constraint(equalTo: bottomAnchor),
96+
container.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16),
97+
98+
userImage.heightAnchor.constraint(equalToConstant: userImageSize),
99+
userImage.widthAnchor.constraint(equalToConstant: userImageSize)
100+
])
101+
}
102+
103+
}

solutions/devsprint-caio-santos-7/FinanceApp/Screens/ContactList/ContactListView.swift

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,75 @@
22
// ContactListView.swift
33
// FinanceApp
44
//
5-
// Created by Rodrigo Borges on 30/12/21.
5+
// Created by Gabriel de Castro Chaves on 14/10/22.
66
//
77

88
import UIKit
99

10-
class ContactListView: UIView {
10+
final class ContactListView: UIView {
11+
12+
static let cellSize = CGFloat(80)
13+
14+
// MARK: - Viusal Components
15+
private lazy var tableView: UITableView = {
16+
let tableView = UITableView(frame: .zero)
17+
tableView.translatesAutoresizingMaskIntoConstraints = false
18+
tableView.register(ContactListTableViewCell.self, forCellReuseIdentifier: ContactListTableViewCell.identifier)
19+
tableView.dataSource = self
20+
tableView.delegate = self
1121

22+
return tableView
23+
}()
24+
25+
// MARK: - Init
26+
init() {
27+
super.init(frame: .zero)
28+
self.backgroundColor = .white
29+
setupView()
30+
tableView.reloadData()
31+
}
32+
33+
required init?(coder: NSCoder) {
34+
return nil
35+
}
36+
1237
}
38+
39+
// MARK: - ViewCodable
40+
extension ContactListView: ViewCodable {
41+
42+
func buildHierarchy() {
43+
addSubview(tableView)
44+
}
45+
46+
func setupConstraints() {
47+
NSLayoutConstraint.activate([
48+
tableView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
49+
tableView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
50+
tableView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor),
51+
tableView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor),
52+
])
53+
}
54+
55+
}
56+
57+
// MARK: - TableView
58+
extension ContactListView: UITableViewDataSource, UITableViewDelegate {
59+
60+
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
61+
return 20
62+
}
63+
64+
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
65+
66+
guard let cell = tableView.dequeueReusableCell(withIdentifier: ContactListTableViewCell.identifier, for: indexPath) as? ContactListTableViewCell else { return UITableViewCell() }
67+
return cell
68+
}
69+
70+
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
71+
return ContactListView.cellSize
72+
}
73+
74+
}
75+
76+

solutions/devsprint-caio-santos-7/FinanceApp/Screens/ContactList/ContactListViewController.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77

88
import UIKit
99

10-
class ContactListViewController: UIViewController {
11-
10+
final class ContactListViewController: UIViewController {
11+
12+
private let container = ContactListView()
13+
1214
override func loadView() {
13-
self.view = ContactListView()
15+
self.view = container
1416
}
1517
}
18+
19+

solutions/devsprint-caio-santos-7/FinanceApp/Screens/Home/HomeView.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ struct HomeViewConfiguration {
1111
let homeData: HomeData
1212
}
1313

14+
protocol HomeViewDelegate: AnyObject {
15+
func didSelectActivity()
16+
}
17+
1418
final class HomeView: UIView {
1519
private var activities: [Activity] = []
16-
20+
var delegate: HomeViewDelegate?
21+
1722
private lazy var accountSummaryView: AccountSummaryView = {
1823
let element = AccountSummaryView()
1924
element.translatesAutoresizingMaskIntoConstraints = false
@@ -26,6 +31,7 @@ final class HomeView: UIView {
2631
tableView.register(ActivityCellView.self, forCellReuseIdentifier: ActivityCellView.reuseIdentifier)
2732
tableView.register(UITableViewCell.self, forCellReuseIdentifier: UITableViewCell.reuseIdentifier)
2833
tableView.dataSource = self
34+
tableView.delegate = self
2935
return tableView
3036
}()
3137

@@ -74,7 +80,7 @@ private extension HomeView {
7480
}
7581
}
7682

77-
extension HomeView: UITableViewDataSource {
83+
extension HomeView: UITableViewDataSource, UITableViewDelegate {
7884
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
7985
return activities.count
8086
}
@@ -89,5 +95,10 @@ extension HomeView: UITableViewDataSource {
8995
cell.updateValues(activity: activities[indexPath.row])
9096
return cell
9197
}
98+
99+
100+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
101+
delegate?.didSelectActivity()
102+
}
92103
}
93104

solutions/devsprint-caio-santos-7/FinanceApp/Screens/Home/HomeViewController.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class HomeViewController: UIViewController {
1717
}()
1818

1919
override func viewDidLoad() {
20+
homeView.delegate = self
2021
customNavBar()
2122
profilePictureNavBar()
2223

@@ -56,3 +57,10 @@ class HomeViewController: UIViewController {
5657
navigationItem.rightBarButtonItem = rightBarButton
5758
}
5859
}
60+
61+
62+
extension HomeViewController: HomeViewDelegate {
63+
func didSelectActivity() {
64+
present(ContactListViewController(), animated: true)
65+
}
66+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// ContactListTableViewCellTests.swift
3+
// FinanceAppTests
4+
//
5+
// Created by Gabriel de Castro Chaves on 14/10/22.
6+
//
7+
8+
@testable import FinanceApp
9+
import SnapshotTesting
10+
import XCTest
11+
12+
final class ContactListTableViewCellTests: XCTestCase {
13+
14+
private let cell = ContactListTableViewCell()
15+
16+
override class func setUp() {
17+
// SnapshotTesting.isRecording = true
18+
}
19+
20+
private func testRenderView() {
21+
cell.backgroundColor = .white
22+
assertSnapshot(matching: cell, as: .image(size: CGSize(width: UIScreen.main.bounds.width,
23+
height: 64)))
24+
}
25+
}
Loading
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// ContactListViewTests.swift
3+
// FinanceAppTests
4+
//
5+
// Created by Gabriel de Castro Chaves on 14/10/22.
6+
//
7+
8+
@testable import FinanceApp
9+
import SnapshotTesting
10+
import XCTest
11+
12+
final class ContactListViewTests: XCTestCase {
13+
14+
override class func setUp() {
15+
// SnapshotTesting.isRecording = true
16+
}
17+
18+
private func testRenderView() {
19+
let component = ContactListView()
20+
assertSnapshot(matching: component, as: .image(size: CGSize(width: UIScreen.main.bounds.width,
21+
height: UIScreen.main.bounds.height)))
22+
}
23+
}

0 commit comments

Comments
 (0)