From 80b760350436ee61824ad27b21bb3b303ee10483 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Thu, 21 Mar 2024 23:54:46 +0100 Subject: [PATCH] Implemented the "openItem(at: )" function for the FeedListViewModel view model in the Feed framework, and integrated it to the FeedListViewController view controller. --- .../Sources/Logic/View Models/FeedListViewModel.swift | 6 ++++++ .../UI/View Controllers/FeedListViewController.swift | 11 +++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedListViewModel.swift b/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedListViewModel.swift index 96ef07a..08671b7 100644 --- a/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedListViewModel.swift +++ b/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedListViewModel.swift @@ -117,6 +117,12 @@ extension FeedListViewController { ? items[index - 1] : items[index] } + + func openItem(at index: Int) { + guard let item = item(for: index) else { return } + + coordination?.open(item) + } } } diff --git a/Frameworks/Feed/Bundle/Sources/UI/View Controllers/FeedListViewController.swift b/Frameworks/Feed/Bundle/Sources/UI/View Controllers/FeedListViewController.swift index adbc9dc..4fee1d3 100644 --- a/Frameworks/Feed/Bundle/Sources/UI/View Controllers/FeedListViewController.swift +++ b/Frameworks/Feed/Bundle/Sources/UI/View Controllers/FeedListViewController.swift @@ -13,7 +13,7 @@ import ReviewsUIKit import SwiftUI import UIKit -class FeedListViewController: UITableViewController { +final class FeedListViewController: UITableViewController { // MARK: Constants private let viewModel: ViewModel @@ -131,17 +131,12 @@ class FeedListViewController: UITableViewController { _ tableView: UITableView, didSelectRowAt indexPath: IndexPath ) { - guard let item = viewModel.item(for: indexPath.row) else { return } - + viewModel.openItem(at: indexPath.row) + tableView.deselectRow( at: indexPath, animated: true ) - - navigationController?.pushViewController( - FeedItemViewController(item), - animated: true - ) } }