rootstrap / ios-base

Boilerplate for new iOS projects using Swift 5. Provides a handful of functionalities.
https://rootstrap.com/
MIT License
258 stars 63 forks source link

Current loading indicator not working in devices with notch #147

Closed glm4 closed 4 years ago

glm4 commented 4 years ago

Possible solutions:

mato2593 commented 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.

germanStabile commented 4 years ago
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

germanStabile commented 4 years ago

This has the advantage of doing

showActivityIndicator(viewModel.state == .loading)

instead of doing show or hide in each case

glm4 commented 4 years ago

stop throwing up code and open a PR 😄