Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why NVActivityIndicatorPresenter is deprecated, whats the alternate approach? #315

Open
preetamjadakar opened this issue Jul 29, 2020 · 7 comments

Comments

@preetamjadakar
Copy link

preetamjadakar commented Jul 29, 2020

I see, in the latest release NVActivityIndicatorPresenter is deprecated, not sure why but I'm looking for its alternative.
My requirement is simple:
Something is deprecated meaning, planned for removal or not supported near future, so we can't just bear with the deprecation warnings.

  • Should block UI(including Tabbar/Navigation bar)
  • Can be called from any place,(not necessary from UIViewController sub-classes), but it should show on the visible screen
  • Should show indicator at the center of the window by default.

My current implementation is as below:
var activityData = ActivityData()
To show: NVActivityIndicatorPresenter.sharedInstance.startAnimating(activityData, nil)
To hide: NVActivityIndicatorPresenter.sharedInstance.stopAnimating()

@sharplet
Copy link

Here's the simpler version that I'm using as a workaround as I move away from using app-global activity indicators. Hope it helps. (Note that I chose to put this API on UIWindow instead of UIViewController to avoid relying on global state like UIWindow.keyWindow. As such it's not quite a drop-in replacement.)

import NVActivityIndicatorView
import UIKit

final class BlockingActivityIndicator: UIView {
  private let activityIndicator: NVActivityIndicatorView

  override init(frame: CGRect) {
    self.activityIndicator = NVActivityIndicatorView(
      frame: CGRect(
        origin: .zero,
        size: NVActivityIndicatorView.DEFAULT_BLOCKER_SIZE
      )
    )
    activityIndicator.startAnimating()
    activityIndicator.translatesAutoresizingMaskIntoConstraints = false
    super.init(frame: frame)
    backgroundColor = UIColor.systemBackground.withAlphaComponent(0.6)
    addSubview(activityIndicator)
    NSLayoutConstraint.activate([
      activityIndicator.centerXAnchor.constraint(equalTo: safeAreaLayoutGuide.centerXAnchor),
      activityIndicator.centerYAnchor.constraint(equalTo: safeAreaLayoutGuide.centerYAnchor),
    ])
  }

  required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
}

extension UIWindow {
  func startBlockingActivityIndicator() {
    guard !subviews.contains(where: { $0 is BlockingActivityIndicator }) else {
      return
    }

    let activityIndicator = BlockingActivityIndicator()
    activityIndicator.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    activityIndicator.frame = bounds

    UIView.transition(
      with: self,
      duration: 0.3,
      options: .transitionCrossDissolve,
      animations: {
        self.addSubview(activityIndicator)
      }
    )
  }
}

@preetamjadakar
Copy link
Author

Thanks @sharplet, this is still better and let's see what author has thought about this?

@ninjaprox
Copy link
Owner

@preetamjadakar Technically, it's still usable, you will get some warnings though. There are changes in the pod names so use pod 'NVActivityIndicatorView/Extended' instead as mentioned in 5.0.0 release note.

The above workaround should work. Originally, NVActivityIndicatorView only provides a set of loading animations, and to use it as a UI blocker, we should've used to in conjunction with other specialized UI blockers like MBProgressHUD or SVProgressHUD. Thanks to other folks' contributions, we have that function, which is NVActivityIndicatorPresenter, baked in NVActivityIndicatorView. Since there, NVActivityIndicatorPresenter is getting more robust, but it doesn't have proper care to address arisen issues—replying on UIWindow.keyWindow is an example. My rationale behind the deprecation is to keep things simple, to prevent new users from using it and therefore take it off the heat. Existing users should still be able to use it—with a small change as mentioned ealier—with warnings meaning it won't get new features added or bugs fixed soon.

Long story short, alternatives could be:

  • Keep using it with NVActivityIndicatorView/Extended, I'm not removing it anytime soon.
  • Craft the UI blocker yourself—maybe with the workaround above—or use it in conjunction with another HUB library.

Then what is NVActivityIndicatorPresenter future? As with existing issues and feature requests, maybe it's worth to be a separate pod—the question is if other pods out there are doing the job well, do we need another new one?—or if it gets enough attention, it'll still be NVActivityIndicatorView/Extended and as a nice add-on to NVActivityIndicatorView.

Thanks for understanding.

@gabors
Copy link

gabors commented Sep 30, 2020

This is a really odd decision @ninjaprox
For one I hate build warnings, your notes state to use NVActivityIndicatorViewExtended, but provide to example on how to use this with SwiftPM.

@singh-karan-7
Copy link

This is honestly, quite stupid. Why would you do this? What's even the point?

@PierreBrisorgueil
Copy link

PierreBrisorgueil commented Mar 18, 2021

Screenshot 2021-03-18 at 11 06 35

Screenshot 2021-03-18 at 11 06 41

Screenshot 2021-03-18 at 11 07 19

Keep using it with NVActivityIndicatorView/Extended, I'm not removing it anytime soon.

@ninjaprox am I wrong somewhere?

@isayeter
Copy link

Thanks for the example @Sharple , missing part to remove Activity for whom want to use @sharplet 's code.

    func finishBlockingActivityIndicator() {
        subviews.filter { $0 is BlockingActivityIndicator }.forEach { view in
            view.removeFromSuperview()
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants