Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class ActivityDetailsView: UIView {
return nil
}

// MARK: Interface Elements
// MARK: Visual Components
private lazy var vStack: UIStackView = {
let stack = UIStackView()
stack.translatesAutoresizingMaskIntoConstraints = false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//
// ContactListView.swift
// FinanceApp
//
// Created by Rodrigo Borges on 30/12/21.
//

import UIKit

final class ContactListTableViewCell: UITableViewCell {
static let identifier = "ContactCellIdentifier"

//MARK: - Init
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.accessoryType = .disclosureIndicator
setupView()
}

required init?(coder: NSCoder) {
return nil
}

//MARK: - Visual Components
private lazy var container: UIStackView = {
let element = UIStackView(frame: .zero)
element.translatesAutoresizingMaskIntoConstraints = false
element.axis = .horizontal
element.alignment = .center
element.distribution = .fill
element.spacing = 16

return element
}()

private lazy var userImage: UIImageView = {
let element = UIImageView()
element.translatesAutoresizingMaskIntoConstraints = false
element.image = UIImage(named: "avatar-placeholder")
element.tintColor = .blue
element.layer.cornerRadius = 25
element.layer.masksToBounds = true

return element
}()

private lazy var labelStackView: UIStackView = {
let element = UIStackView()
element.translatesAutoresizingMaskIntoConstraints = false
element.axis = .vertical
element.alignment = .leading
element.distribution = .fill
element.spacing = 4

return element
}()

private lazy var nameLabel: UILabel = {
let element = UILabel()
element.translatesAutoresizingMaskIntoConstraints = false
element.text = "Name"
element.font = UIFont.boldSystemFont(ofSize: 16)

return element
}()

private lazy var phoneNumberLabel: UILabel = {
let element = UILabel()
element.translatesAutoresizingMaskIntoConstraints = false
element.text = "+55 11 99999-9999"
element.textColor = .lightGray

return element
}()
}

//MARK: - ViewCodable
extension ContactListTableViewCell: ViewCodable {

func buildHierarchy() {
addSubview(container)
container.addArrangedSubview(userImage)
container.addArrangedSubview(labelStackView)
labelStackView.addArrangedSubview(nameLabel)
labelStackView.addArrangedSubview(phoneNumberLabel)
}

func setupConstraints() {

let userImageSize: CGFloat = 50

NSLayoutConstraint.activate([
container.topAnchor.constraint(equalTo: topAnchor),
container.trailingAnchor.constraint(equalTo: trailingAnchor),
container.bottomAnchor.constraint(equalTo: bottomAnchor),
container.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16),

userImage.heightAnchor.constraint(equalToConstant: userImageSize),
userImage.widthAnchor.constraint(equalToConstant: userImageSize)
])
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,75 @@
// ContactListView.swift
// FinanceApp
//
// Created by Rodrigo Borges on 30/12/21.
// Created by Gabriel de Castro Chaves on 14/10/22.
//

import UIKit

class ContactListView: UIView {
final class ContactListView: UIView {

static let cellSize = CGFloat(80)

// MARK: - Viusal Components
private lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero)
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.register(ContactListTableViewCell.self, forCellReuseIdentifier: ContactListTableViewCell.identifier)
tableView.dataSource = self
tableView.delegate = self

return tableView
}()

// MARK: - Init
init() {
super.init(frame: .zero)
self.backgroundColor = .white
setupView()
tableView.reloadData()
}

required init?(coder: NSCoder) {
return nil
}

}

// MARK: - ViewCodable
extension ContactListView: ViewCodable {

func buildHierarchy() {
addSubview(tableView)
}

func setupConstraints() {
NSLayoutConstraint.activate([
tableView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
tableView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor),
tableView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor),
])
}

}

// MARK: - TableView
extension ContactListView: UITableViewDataSource, UITableViewDelegate {

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 20
}

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

guard let cell = tableView.dequeueReusableCell(withIdentifier: ContactListTableViewCell.identifier, for: indexPath) as? ContactListTableViewCell else { return UITableViewCell() }
return cell
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return ContactListView.cellSize
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@

import UIKit

class ContactListViewController: UIViewController {

final class ContactListViewController: UIViewController {

private let container = ContactListView()

override func loadView() {
self.view = ContactListView()
self.view = container
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ struct HomeViewConfiguration {
let homeData: HomeData
}

protocol HomeViewDelegate: AnyObject {
func didSelectActivity()
}

final class HomeView: UIView {
private var activities: [Activity] = []

var delegate: HomeViewDelegate?

private lazy var accountSummaryView: AccountSummaryView = {
let element = AccountSummaryView()
element.translatesAutoresizingMaskIntoConstraints = false
Expand All @@ -26,6 +31,7 @@ final class HomeView: UIView {
tableView.register(ActivityCellView.self, forCellReuseIdentifier: ActivityCellView.reuseIdentifier)
tableView.register(UITableViewCell.self, forCellReuseIdentifier: UITableViewCell.reuseIdentifier)
tableView.dataSource = self
tableView.delegate = self
return tableView
}()

Expand Down Expand Up @@ -74,7 +80,7 @@ private extension HomeView {
}
}

extension HomeView: UITableViewDataSource {
extension HomeView: UITableViewDataSource, UITableViewDelegate {
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return activities.count
}
Expand All @@ -89,5 +95,10 @@ extension HomeView: UITableViewDataSource {
cell.updateValues(activity: activities[indexPath.row])
return cell
}


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
delegate?.didSelectActivity()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class HomeViewController: UIViewController {
}()

override func viewDidLoad() {
homeView.delegate = self
customNavBar()
profilePictureNavBar()

Expand Down Expand Up @@ -56,3 +57,10 @@ class HomeViewController: UIViewController {
navigationItem.rightBarButtonItem = rightBarButton
}
}


extension HomeViewController: HomeViewDelegate {
func didSelectActivity() {
present(ContactListViewController(), animated: true)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// ContactListTableViewCellTests.swift
// FinanceAppTests
//
// Created by Gabriel de Castro Chaves on 14/10/22.
//

@testable import FinanceApp
import SnapshotTesting
import XCTest

final class ContactListTableViewCellTests: XCTestCase {

private let cell = ContactListTableViewCell()

override class func setUp() {
// SnapshotTesting.isRecording = true
}

private func testRenderView() {
cell.backgroundColor = .white
assertSnapshot(matching: cell, as: .image(size: CGSize(width: UIScreen.main.bounds.width,
height: 64)))
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// ContactListViewTests.swift
// FinanceAppTests
//
// Created by Gabriel de Castro Chaves on 14/10/22.
//

@testable import FinanceApp
import SnapshotTesting
import XCTest

final class ContactListViewTests: XCTestCase {

override class func setUp() {
// SnapshotTesting.isRecording = true
}

private func testRenderView() {
let component = ContactListView()
assertSnapshot(matching: component, as: .image(size: CGSize(width: UIScreen.main.bounds.width,
height: UIScreen.main.bounds.height)))
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.