From 5d3f0c23f64151fb8a502fa2de28e9040914539a Mon Sep 17 00:00:00 2001 From: SSOOYA Date: Sun, 4 Jun 2023 16:48:22 +0900 Subject: [PATCH] =?UTF-8?q?[refactor]=20#245:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=82=AC=EC=9D=B4=EB=93=9C=EB=A9=94=EB=89=B4=20delegate=20?= =?UTF-8?q?=ED=8C=A8=ED=84=B4=20=ED=99=9C=EC=9A=A9=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81=20+=20ViewModel=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ChattingSideSheetViewController.swift | 63 ++++++++++--------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/Zatch/Presentation/ViewControllers/Chatting/ChattingSideSheetViewController.swift b/Zatch/Presentation/ViewControllers/Chatting/ChattingSideSheetViewController.swift index 16cd6b6f..4d40c2cf 100644 --- a/Zatch/Presentation/ViewControllers/Chatting/ChattingSideSheetViewController.swift +++ b/Zatch/Presentation/ViewControllers/Chatting/ChattingSideSheetViewController.swift @@ -7,12 +7,27 @@ import UIKit -class ChattingSideSheetViewController: UIViewController, UIGestureRecognizerDelegate { +protocol ChattingSideMenuDelegate: AnyObject{ + func willShowDeclarationBottomSheet(index: Int) + func willShowExitRoomAlert() +} + +class ChattingSideSheetViewController: UIViewController, UIGestureRecognizerDelegate, DeclarationDelegate { + + weak var delegate: ChattingSideMenuDelegate? + + private let viewModel: any BlockUserInterface + + init(viewModel: BlockUserInterface){ + self.viewModel = viewModel + super.init(nibName: nil, bundle: nil) + } - //MARK: - Properties - var declarationHandler: ((IndexPath) -> Void)? + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } - let mainView = ChattingSideSheetView() + private let mainView = ChattingSideSheetView() override func viewDidLoad() { super.viewDidLoad() @@ -26,9 +41,12 @@ class ChattingSideSheetViewController: UIViewController, UIGestureRecognizerDele } private func initialzie(){ - mainView.tableView.separatorStyle = .none - mainView.tableView.delegate = self - mainView.tableView.dataSource = self + setTableViewDelegate() + mainView.exitStackView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(exitBtnDidTap))) + } + + private func setTableViewDelegate(){ + mainView.tableView.initializeDelegate(self) } private func layout(){ @@ -39,38 +57,25 @@ class ChattingSideSheetViewController: UIViewController, UIGestureRecognizerDele } } - @objc func declarationBtnDidClicked(_ sender: UIButton){ - - let cell = sender.superview?.superview?.superview as! ChattingMemberTableViewCell - - let index = mainView.tableView.indexPath(for: cell) - - self.declarationHandler!(index!) + func willShowDelclarationBottomSheet(index: Int) { + delegate?.willShowDeclarationBottomSheet(index: index) } + @objc private func exitBtnDidTap(){ + delegate?.willShowExitRoomAlert() + } } extension ChattingSideSheetViewController: UITableViewDelegate, UITableViewDataSource{ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{ - return 3 + viewModel.chattingmMembers.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - if(indexPath.row == 0){ - guard let cell = tableView.dequeueReusableCell(withIdentifier: ChattingMemberTableViewCell.cellIdentifier, for: indexPath) as? ChattingMemberTableViewCell else{ - fatalError() - } - cell.setMeTag() - cell.setCrownImage() // TODO: - 방장 데이터 불러오면 선언 위치 바꾸기 - return cell - }else{ - guard let cell = tableView.dequeueReusableCell(withIdentifier: ChattingMemberTableViewCell.cellIdentifier, for: indexPath) as? ChattingMemberTableViewCell else{ - fatalError() - } - cell.setDeclarationBtn() - cell.declarationBtn.addTarget(self, action: #selector(declarationBtnDidClicked), for: .touchUpInside) - return cell + tableView.dequeueReusableCell(for: indexPath, cellType: ChattingMemberTableViewCell.self).then{ + $0.delegate = self + $0.bindingData(viewModel.chattingmMembers[indexPath.row]) } } }