@@ -14,6 +14,16 @@ final public class ReportListViewController: UIViewController {
1414 private let menuView = ReportMenuView ( )
1515 private var coordinator : ReportListCoordinatorInterface
1616
17+ private lazy var tableView : UITableView = {
18+ let tableView = UITableView ( )
19+ tableView. register ( ReportListCell . self, forCellReuseIdentifier: ReportListCell . className)
20+ tableView. delegate = self
21+ tableView. separatorInset = . init( top: . zero, left: . zero, bottom: . zero, right: . zero)
22+ return tableView
23+ } ( )
24+
25+ private var dataSource : UITableViewDiffableDataSource < ReportListSectionKind , ReportListCellModel > ?
26+
1727 public init ( coordinator: ReportListCoordinatorInterface ) {
1828 self . coordinator = coordinator
1929 super. init ( nibName: nil , bundle: nil )
@@ -31,6 +41,10 @@ final public class ReportListViewController: UIViewController {
3141 private func setUp( ) {
3242 setConstraintsLayout ( )
3343 setNavigationBar ( )
44+ setDataSource ( )
45+ applySnapshot ( [
46+ ReportListSection ( sectionKind: . report, items: [ ReportListCellModel . report ( " a " , true ) , ReportListCellModel . report ( " aa " , true ) ] )
47+ ] )
3448 }
3549
3650 @objc func didTapBackButton( _ sender: Any ? ) {
@@ -42,12 +56,16 @@ final public class ReportListViewController: UIViewController {
4256private extension ReportListViewController {
4357
4458 func setConstraintsLayout( ) {
45- view. addSubviews ( menuView)
59+ view. addSubviews ( menuView, tableView )
4660 NSLayoutConstraint . activate ( [
4761 menuView. topAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. topAnchor, constant: 5 ) ,
4862 menuView. leadingAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. leadingAnchor, constant: 20 ) ,
4963 menuView. trailingAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. trailingAnchor) ,
50- menuView. heightAnchor. constraint ( equalToConstant: 20 )
64+ menuView. heightAnchor. constraint ( equalToConstant: 20 ) ,
65+ tableView. leadingAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. leadingAnchor, constant: 20 ) ,
66+ tableView. trailingAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. trailingAnchor, constant: - 20 ) ,
67+ tableView. topAnchor. constraint ( equalTo: menuView. bottomAnchor, constant: 10 ) ,
68+ tableView. bottomAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. bottomAnchor)
5169 ] )
5270 }
5371
@@ -64,4 +82,33 @@ private extension ReportListViewController {
6482 navigationItem. leftBarButtonItem = cancelButton
6583 }
6684
85+ func setDataSource( ) {
86+ dataSource = UITableViewDiffableDataSource < ReportListSectionKind , ReportListCellModel > (
87+ tableView: tableView, cellProvider: { tableView, indexPath, item in
88+ switch item {
89+ case . report( let title, let isSelected) :
90+ let cell = tableView. dequeueReusableCell ( withIdentifier: ReportListCell . className, for: indexPath) as? ReportListCell
91+ cell? . selectionStyle = . none
92+ return cell
93+ }
94+ } )
95+ }
96+
97+ func applySnapshot( _ sections: [ ReportListSection ] ) {
98+ var snapshot = NSDiffableDataSourceSnapshot < ReportListSectionKind , ReportListCellModel > ( )
99+ sections. forEach {
100+ snapshot. appendSections ( [ $0. sectionKind] )
101+ snapshot. appendItems ( $0. items)
102+ }
103+ dataSource? . apply ( snapshot, animatingDifferences: false )
104+ }
105+
106+ }
107+
108+ extension ReportListViewController : UITableViewDelegate {
109+
110+ public func tableView( _ tableView: UITableView , heightForRowAt indexPath: IndexPath ) -> CGFloat {
111+ return 44
112+ }
113+
67114}
0 commit comments