From d1f3ffacc06ed4d1a402b2a37f501acba1f65f71 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Thu, 21 Mar 2024 11:26:57 +0100 Subject: [PATCH 1/2] Integrated the "activityIndicator" outlet into the FeedListViewController view controller in the Feed framework. --- .../FeedListViewController.swift | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Frameworks/Feed/Bundle/Sources/UI/View Controllers/FeedListViewController.swift b/Frameworks/Feed/Bundle/Sources/UI/View Controllers/FeedListViewController.swift index 6717ea6..78cfe49 100644 --- a/Frameworks/Feed/Bundle/Sources/UI/View Controllers/FeedListViewController.swift +++ b/Frameworks/Feed/Bundle/Sources/UI/View Controllers/FeedListViewController.swift @@ -22,6 +22,14 @@ public class FeedListViewController: UITableViewController { private var cancellables: Set = [] // MARK: Outlets + private lazy var activityIndicator = { + let indicator = UIActivityIndicatorView() + + indicator.translatesAutoresizingMaskIntoConstraints = false + + return indicator + }() + private lazy var filterButton = { UIBarButtonItem( title: NSLocalizedString( @@ -92,6 +100,7 @@ public class FeedListViewController: UITableViewController { setNavigationBar() setView() + setLayout() registerTableCells() bindViewModel() @@ -163,11 +172,20 @@ private extension FeedListViewController { } .store(in: &cancellables) + viewModel.$isLoading + .filter { $0 == true } + .receive(on: RunLoop.main) + .sink { [weak self] _ in + self?.activityIndicator.startAnimating() + } + .store(in: &cancellables) + viewModel.$isLoading .dropFirst() .filter { $0 == false } .receive(on: RunLoop.main) .sink { [weak self] _ in + self?.activityIndicator.stopAnimating() self?.pullControl.endRefreshing() self?.tableView.reloadData() self?.tableView.scrollToRow( @@ -232,6 +250,13 @@ private extension FeedListViewController { TopWordsCell.register(in: tableView) } + func setLayout() { + NSLayoutConstraint.activate([ + activityIndicator.centerXAnchor.constraint(equalTo: view.centerXAnchor), + activityIndicator.centerYAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerYAnchor), + ]) + } + func setNavigationBar() { navigationController?.navigationBar.prefersLargeTitles = true navigationController?.navigationBar.isTranslucent = true @@ -246,6 +271,11 @@ private extension FeedListViewController { func setView() { tableView.refreshControl = pullControl + + view.addSubview(activityIndicator) + view.bringSubviewToFront(activityIndicator) + + activityIndicator.startAnimating() } func updateFilterMenu(_ option: FilterOption) { -- 2.47.1 From f339985a9faa00a27d337a11ce2b48613456b56c Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Thu, 21 Mar 2024 11:27:59 +0100 Subject: [PATCH 2/2] Fixed a bug on the calculation of the "itemsCount" computed property for the FeedListViewModel view model in the Feed framework. --- .../Bundle/Sources/Logic/View Models/FeedListViewModel.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedListViewModel.swift b/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedListViewModel.swift index 059a3fa..5fd5a99 100644 --- a/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedListViewModel.swift +++ b/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedListViewModel.swift @@ -47,8 +47,8 @@ extension FeedListViewController { // MARK: Computed var itemsCount: Int { isWordsShowing - ? items.count - : items.count + 1 + ? items.count + 1 + : items.count } var isWordsShowing: Bool { -- 2.47.1