From 65813f408d6b3ff8ab02295f016ff40f1494a3e6 Mon Sep 17 00:00:00 2001 From: mini-min <2alswo7@khu.ac.kr> Date: Mon, 13 Jan 2025 22:20:43 +0900 Subject: [PATCH] [Refactor] #239 - Refactor Clip Coordinator --- .../Coordinators/ClipCoordinator.swift | 14 +++++++++++++- .../View/DetailClipViewController.swift | 18 ++++++++++-------- .../ViewController/LinkWebViewController.swift | 9 +++++---- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/TOASTER-iOS/Application/Coordinator/Coordinators/ClipCoordinator.swift b/TOASTER-iOS/Application/Coordinator/Coordinators/ClipCoordinator.swift index f4a251d..8c1ac37 100644 --- a/TOASTER-iOS/Application/Coordinator/Coordinators/ClipCoordinator.swift +++ b/TOASTER-iOS/Application/Coordinator/Coordinators/ClipCoordinator.swift @@ -51,6 +51,18 @@ private extension ClipCoordinator { func showDetailClipVC(id: Int, name: String) { let vc = viewControllerFactory.makeDetailClipVC() vc.setupCategory(id: id, name: name) - router.push(vc, animated: true) + vc.onLinkSelected = { [weak self] linkURL, isRead, id in + self?.showLinkWebVC(linkURL: linkURL, isRead: isRead, id: id) + } + router.push(vc, animated: true, hideBottomBarWhenPushed: true) + } + + func showLinkWebVC(linkURL: String, isRead: Bool, id: Int) { + let vc = viewControllerFactory.makeLinkWebVC() + vc.setupDataBind(linkURL: linkURL, isRead: isRead, id: id) + vc.onBack = { [weak self] in + self?.router.pop(animated: true) + } + router.push(vc, animated: true, hideBottomBarWhenPushed: true) } } diff --git a/TOASTER-iOS/Present/DetailClip/View/DetailClipViewController.swift b/TOASTER-iOS/Present/DetailClip/View/DetailClipViewController.swift index f5bb031..3caf32e 100644 --- a/TOASTER-iOS/Present/DetailClip/View/DetailClipViewController.swift +++ b/TOASTER-iOS/Present/DetailClip/View/DetailClipViewController.swift @@ -13,6 +13,12 @@ import Then final class DetailClipViewController: UIViewController { + // MARK: - View Controllable + + var onLinkSelected: ((String, Bool, Int) -> Void)? + + // MARK: - Data Streams + private let viewModel: DetailClipViewModel! private var cancelBag = CancelBag() @@ -366,14 +372,10 @@ extension DetailClipViewController: UICollectionViewDataSource { extension DetailClipViewController: UICollectionViewDelegate { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { indexNumber = indexPath.item - let nextVC = ViewControllerFactory.shared.makeLinkWebVC() - nextVC.hidesBottomBarWhenPushed = true - nextVC.setupDataBind( - linkURL: viewModel.toastList.toastList[indexPath.item].url, - isRead: viewModel.toastList.toastList[indexPath.item].isRead, - id: viewModel.toastList.toastList[indexPath.item].id - ) - self.navigationController?.pushViewController(nextVC, animated: true) + let linkURL = viewModel.toastList.toastList[indexPath.item].url + let isRead = viewModel.toastList.toastList[indexPath.item].isRead + let id = viewModel.toastList.toastList[indexPath.item].id + onLinkSelected?(linkURL, isRead, id) } } diff --git a/TOASTER-iOS/Present/LinkWeb/ViewController/LinkWebViewController.swift b/TOASTER-iOS/Present/LinkWeb/ViewController/LinkWebViewController.swift index 286d3c0..0e2be2c 100644 --- a/TOASTER-iOS/Present/LinkWeb/ViewController/LinkWebViewController.swift +++ b/TOASTER-iOS/Present/LinkWeb/ViewController/LinkWebViewController.swift @@ -13,6 +13,10 @@ import Then final class LinkWebViewController: UIViewController { + // MARK: - View Controllable + + var onBack: (() -> Void)? + // MARK: - Properties private var viewModel: LinkWebViewModel! @@ -175,10 +179,7 @@ private extension LinkWebViewController { func setupNavigationBarAction() { /// 네비게이션바 뒤로가기 버튼 클릭 액션 클로저 - navigationView.popButtonTapped { - self.navigationController?.popViewController(animated: true) - self.showNavigationBar() - } + navigationView.popButtonTapped { self.onBack?() } /// 네비게이션바 새로고침 버튼 클릭 액션 클로저 navigationView.reloadButtonTapped { self.webView.reload() }