77
88import UIKit
99
10- struct HomeViewConfiguration {
11- let homeData : HomeData
12- }
10+ struct HomeViewConfiguration {
11+ let homeData : HomeData
12+ }
1313
14- final class HomeView : UIView {
1514 private var activities : [ Activity ] = [ ]
1615
16+ final class HomeView : UIView {
17+
1718 private lazy var accountSummaryView : AccountSummaryView = {
1819 let element = AccountSummaryView ( )
1920 element. translatesAutoresizingMaskIntoConstraints = false
2021 return element
2122 } ( )
2223
23- private lazy var tableView : UITableView = {
24- let tableView = UITableView ( frame: . zero)
25- tableView. translatesAutoresizingMaskIntoConstraints = false
26- tableView. register ( ActivityCellView . self, forCellReuseIdentifier: ActivityCellView . reuseIdentifier)
27- tableView. register ( UITableViewCell . self, forCellReuseIdentifier: UITableViewCell . reuseIdentifier)
28- tableView. dataSource = self
29- return tableView
24+ private lazy var activityListView : ActivityListView = {
25+ let element = ActivityListView ( )
26+ element. translatesAutoresizingMaskIntoConstraints = false
27+ return element
3028 } ( )
31-
29+
3230 init ( ) {
3331 super. init ( frame: . zero)
32+ self . activityListView. configTableViewProtocol ( delegate: self , dataSource: self )
3433 self . setupViews ( )
3534 }
3635
@@ -39,12 +38,12 @@ final class HomeView: UIView {
3938 }
4039
4140 func updateView( with configuration: HomeViewConfiguration ) {
42- activities = configuration. homeData. activity
4341 accountSummaryView. updateValues ( balance: configuration. homeData. balance,
4442 savings: configuration. homeData. savings,
4543 spending: configuration. homeData. spending)
46- tableView . reloadData ( )
44+ activityListView . updateTableView ( with : configuration )
4745 }
46+
4847}
4948
5049private extension HomeView {
@@ -57,7 +56,7 @@ private extension HomeView {
5756
5857 func configureSubviews( ) {
5958 addSubview ( accountSummaryView)
60- addSubview ( tableView )
59+ addSubview ( activityListView )
6160 }
6261
6362 func configureSubviewsConstraints( ) {
@@ -66,15 +65,15 @@ private extension HomeView {
6665 accountSummaryView. leadingAnchor. constraint ( equalTo: safeAreaLayoutGuide. leadingAnchor, constant: 16 ) ,
6766 accountSummaryView. trailingAnchor. constraint ( equalTo: safeAreaLayoutGuide. trailingAnchor, constant: - 16 ) ,
6867
69- tableView . topAnchor. constraint ( equalTo: accountSummaryView. bottomAnchor, constant: 16 ) ,
70- tableView . leadingAnchor. constraint ( equalTo: safeAreaLayoutGuide. leadingAnchor) ,
71- tableView . trailingAnchor. constraint ( equalTo: safeAreaLayoutGuide. trailingAnchor) ,
72- tableView . bottomAnchor. constraint ( equalTo: safeAreaLayoutGuide. bottomAnchor)
68+ activityListView . topAnchor. constraint ( equalTo: accountSummaryView. bottomAnchor, constant: 16 ) ,
69+ activityListView . leadingAnchor. constraint ( equalTo: safeAreaLayoutGuide. leadingAnchor) ,
70+ activityListView . trailingAnchor. constraint ( equalTo: safeAreaLayoutGuide. trailingAnchor) ,
71+ activityListView . bottomAnchor. constraint ( equalTo: safeAreaLayoutGuide. bottomAnchor)
7372 ] )
7473 }
7574}
7675
77- extension HomeView : UITableViewDataSource {
76+ extension HomeView : UITableViewDelegate , UITableViewDataSource {
7877 public func tableView( _ tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {
7978 return activities. count
8079 }
@@ -84,10 +83,12 @@ extension HomeView: UITableViewDataSource {
8483 indexPath. row < activities. count else {
8584 return . init( )
8685 }
87-
88-
8986 cell. updateValues ( activity: activities [ indexPath. row] )
9087 return cell
9188 }
89+
90+ func tableView( _ tableView: UITableView , didSelectRowAt indexPath: IndexPath ) {
91+ print ( " Função para disparar ação de toque na atividade " )
92+ }
9293}
9394
0 commit comments