Integrated the "activityIndicator" outlet into the FeedListViewController view controller in the Feed framework.

This commit is contained in:
Javier Cicchelli 2024-03-21 11:26:57 +01:00
parent 0b5ca9ef9f
commit d1f3ffacc0

View File

@ -22,6 +22,14 @@ public class FeedListViewController: UITableViewController {
private var cancellables: Set<AnyCancellable> = []
// 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) {