[Framework] loading indicator for the Feed list (#14)
This PR contains the work done to integrate a loading indicator to the `FeedListViewController` view controller. Reviewed-on: #14 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit is contained in:
parent
0b5ca9ef9f
commit
394245dd29
@ -47,8 +47,8 @@ extension FeedListViewController {
|
|||||||
// MARK: Computed
|
// MARK: Computed
|
||||||
var itemsCount: Int {
|
var itemsCount: Int {
|
||||||
isWordsShowing
|
isWordsShowing
|
||||||
? items.count
|
? items.count + 1
|
||||||
: items.count + 1
|
: items.count
|
||||||
}
|
}
|
||||||
|
|
||||||
var isWordsShowing: Bool {
|
var isWordsShowing: Bool {
|
||||||
|
@ -22,6 +22,14 @@ public class FeedListViewController: UITableViewController {
|
|||||||
private var cancellables: Set<AnyCancellable> = []
|
private var cancellables: Set<AnyCancellable> = []
|
||||||
|
|
||||||
// MARK: Outlets
|
// MARK: Outlets
|
||||||
|
private lazy var activityIndicator = {
|
||||||
|
let indicator = UIActivityIndicatorView()
|
||||||
|
|
||||||
|
indicator.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
|
||||||
|
return indicator
|
||||||
|
}()
|
||||||
|
|
||||||
private lazy var filterButton = {
|
private lazy var filterButton = {
|
||||||
UIBarButtonItem(
|
UIBarButtonItem(
|
||||||
title: NSLocalizedString(
|
title: NSLocalizedString(
|
||||||
@ -92,6 +100,7 @@ public class FeedListViewController: UITableViewController {
|
|||||||
|
|
||||||
setNavigationBar()
|
setNavigationBar()
|
||||||
setView()
|
setView()
|
||||||
|
setLayout()
|
||||||
registerTableCells()
|
registerTableCells()
|
||||||
bindViewModel()
|
bindViewModel()
|
||||||
|
|
||||||
@ -163,11 +172,20 @@ private extension FeedListViewController {
|
|||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|
||||||
|
viewModel.$isLoading
|
||||||
|
.filter { $0 == true }
|
||||||
|
.receive(on: RunLoop.main)
|
||||||
|
.sink { [weak self] _ in
|
||||||
|
self?.activityIndicator.startAnimating()
|
||||||
|
}
|
||||||
|
.store(in: &cancellables)
|
||||||
|
|
||||||
viewModel.$isLoading
|
viewModel.$isLoading
|
||||||
.dropFirst()
|
.dropFirst()
|
||||||
.filter { $0 == false }
|
.filter { $0 == false }
|
||||||
.receive(on: RunLoop.main)
|
.receive(on: RunLoop.main)
|
||||||
.sink { [weak self] _ in
|
.sink { [weak self] _ in
|
||||||
|
self?.activityIndicator.stopAnimating()
|
||||||
self?.pullControl.endRefreshing()
|
self?.pullControl.endRefreshing()
|
||||||
self?.tableView.reloadData()
|
self?.tableView.reloadData()
|
||||||
self?.tableView.scrollToRow(
|
self?.tableView.scrollToRow(
|
||||||
@ -232,6 +250,13 @@ private extension FeedListViewController {
|
|||||||
TopWordsCell.register(in: tableView)
|
TopWordsCell.register(in: tableView)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setLayout() {
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
activityIndicator.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
||||||
|
activityIndicator.centerYAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerYAnchor),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
func setNavigationBar() {
|
func setNavigationBar() {
|
||||||
navigationController?.navigationBar.prefersLargeTitles = true
|
navigationController?.navigationBar.prefersLargeTitles = true
|
||||||
navigationController?.navigationBar.isTranslucent = true
|
navigationController?.navigationBar.isTranslucent = true
|
||||||
@ -246,6 +271,11 @@ private extension FeedListViewController {
|
|||||||
|
|
||||||
func setView() {
|
func setView() {
|
||||||
tableView.refreshControl = pullControl
|
tableView.refreshControl = pullControl
|
||||||
|
|
||||||
|
view.addSubview(activityIndicator)
|
||||||
|
view.bringSubviewToFront(activityIndicator)
|
||||||
|
|
||||||
|
activityIndicator.startAnimating()
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateFilterMenu(_ option: FilterOption) {
|
func updateFilterMenu(_ option: FilterOption) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user