Closed glm4 closed 4 years ago
I added this provisional solution in Surkus:
func showSpinner() {
view.endEditing(true)
guard view.viewWithTag(spinnerTag) == nil else { return }
let spinner = UIActivityIndicatorView(style: .large)
spinner.frame = view.frame
spinner.color = .skAmaranth
spinner.backgroundColor = UIColor.skGray.withAlphaComponent(0.5)
spinner.tag = spinnerTag
view.addSubview(spinner)
spinner.startAnimating()
}
func hideSpinner() {
guard let spinner = view.viewWithTag(spinnerTag) else { return }
spinner.removeFromSuperview()
}
There must be better alternatives for sure, but it was a quick way to do it without having any designs for it.
protocol ActivityIndicatorPresenter: class {
var activityIndicator: UIActivityIndicatorView { get }
func showActivityIndicator(_ show: Bool)
}
extension ActivityIndicatorPresenter where Self: UIViewController {
func showActivityIndicator(_ show: Bool) {
guard show else {
activityIndicator.removeFromSuperview()
return
}
view.addSubview(activityIndicator)
activityIndicator.color = .black
activityIndicator.frame = view.bounds
activityIndicator.startAnimating()
}
}
I implemented something very close to @mato2593 solution in avinew
This has the advantage of doing
showActivityIndicator(viewModel.state == .loading)
instead of doing show or hide in each case
stop throwing up code and open a PR 😄
Possible solutions: