ninjaprox / NVActivityIndicatorView

A collection of awesome loading animations
MIT License
10.63k stars 1.16k forks source link

ActivityIndicatorView can not dismissing when UIAlertView is appearing on screen. #268

Closed barankaansert closed 5 years ago

barankaansert commented 5 years ago

Hi,

Thanks for an excallent tool. I have one issue about dismissing the indicator view. When you show any UIAlertatew at screen before you startAnimating activity indictor, the activity indicator is not dismissable.

Could you please help me with this issue? @ninjaprox

Thanks.

ninjaprox commented 5 years ago

Don't you mind if creating or sending over an example project with the issue? I can help investigate and fix it from there.

barankaansert commented 5 years ago

Actually basicly in viewDidLoad:

UIAlertView(title: "title", message: "message", delegate: nil, cancelButtonTitle: nil).show()

DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
    let loader = ActivityData(size: CGSize(width: 40, height: 40),
                              message: nil, messageFont: nil,
                              type: .circleStrokeSpin,
                              color: UIColor(red: 0.18, green: 0.72, blue: 0.93, alpha: 1.00),
                              padding: nil, displayTimeThreshold: nil,
                              minimumDisplayTime: 1,
                              backgroundColor: .clear,
                              textColor: nil)
    NVActivityIndicatorPresenter.sharedInstance.startAnimating(loader, nil)
}
ninjaprox commented 5 years ago

I checked the example, and the behavior seems different from what you described. The animation is hidden behind the alert view, yet it's still able to dismiss after stopAnimating(). Here is the code I used.

UIAlertView(title: "title", message: "message", delegate: nil, cancelButtonTitle: "OK").show()

DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
    let loader = ActivityData(size: CGSize(width: 40, height: 40),
                              message: nil,
                              messageFont: nil,
                              type: .circleStrokeSpin,
                              color: UIColor(red: 0.18, green: 0.72, blue: 0.93, alpha: 1.00),
                              padding: nil,
                              displayTimeThreshold: nil,
                              minimumDisplayTime: 1,
                              backgroundColor: .clear,
                              textColor: nil)

    NVActivityIndicatorPresenter.sharedInstance.startAnimating(loader, nil)
}

DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
    NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
}

Anyway, what use case are you having NVActivityIndicatorView with UIAlertView?

barankaansert commented 5 years ago

We are using fabric to distrubuting our Beta apps, so when new version is available on fabric, automatically appears "new version is available" alert on screen at old versions of app. App goes through to Main page and fetching some data and runs

NVActivityIndicatorPresenter.sharedInstance.startAnimating(loader, nil) when UIAlertView on screen. After that NVActivityIndicatorPresenter.sharedInstance.stopAnimating() not works.

When i debug this stopAnimating, i found hide(_:) method in NVActivityIndicatorPresenter.

fileprivate func hide(_ fadeOutAnimation: FadeOutAnimation?) {
        for window in UIApplication.shared.windows {
            for item in window.subviews
                where item.restorationIdentifier == restorationIdentifier {
                    if let fadeOutAnimation = fadeOutAnimation {
                        fadeOutAnimation(item) {
                            item.removeFromSuperview()
                        }
                    } else {
                        item.removeFromSuperview()
                    }
            }
        }
    }

i think, every item is window.subviews has no restorationIdentifier with "NVActivityIndicatorViewContainer".

I hope it will helps to understant my problem. 🙏🏼

ninjaprox commented 5 years ago

It might be a niche case to have 2 "modals" displaying at the same time. I'd suggest dismissing the alert view first, then startAnimating(_:, _:), it also gives better UX in my opinion. Since I can't reproduce this issue on my side, could you help check the following:

ninjaprox commented 5 years ago

Close this, reopen if need be.