AssistoLab / KVNProgress

KVNProgress is a fully customizable progress HUD that can be full screen or not.
MIT License
1.24k stars 202 forks source link

Swift 3 Ui Freeze with show progress on working with Alamofire #99

Open danya0365 opened 8 years ago

danya0365 commented 8 years ago

Call KVNProgress.show(0.0, status: "Logging...") in main thread

then in alamofire

request.responseJSON { (response:DataResponse<Any>) in

call

DispatchQueue.main.async { KVNProgress.showSuccess() } or KVNProgress.showSuccess()

nick-iCars commented 7 years ago

This may not be limited to alamofire. I am having UI unresponsiveness, when the complete block of KVNProgress.dismiss(completion: {}) is fired. If I dismiss it with KVNProgress.dismiss() there does not seem to be an issue. I am hitting the network when this happens so maybe it is related to that. But I am not using Alamofire anywhere in the app.

bb-git commented 7 years ago

I'm also experiencing seemingly random app freezes since migrating to Swift 3, but some of my users are experiencing this pretty often. I'm using KVNProgress heavily, so I will try to reproduce as you described.

bb-git commented 7 years ago

So I removed KVNProgress from my project. No more complaints since then, so it is definitly an issue of this library. I use KVNProgress mostly to show success or error. Hope there will be a fix soon, as this is by far the best library!

nick-iCars commented 7 years ago

I'm narrowing down the cause of this bug and I think it actually is a result of calling dismiss() multiple times, or more specifically calling dismiss() when there is no kvnprogressview visible.

VivienCormierRM commented 7 years ago

👍

VivienCormierRM commented 7 years ago

I was able to fixed this issue (in my case) by adding a .dismiss() before a .showError().

KVNProgress.show(0.5)
KVNProgress.dismiss() <= Add dismiss between show and showError
KVNProgress.showError()
danya0365 commented 7 years ago

Today i already fixed by check isVisible before show other KVNProgress

example

   KVNProgress.show()

after that before recall just check previous.

    if KVNProgress.isVisible() {
        KVNProgress.dismiss(completion: {
            KVNProgress.show()
        })
    } else {

        KVNProgress.show()
    }
danya0365 commented 7 years ago

I created KVNManager to wrapped KNV library to manage it before show or dismiss.

    class KVNProgressManager: NSObject {

        static func applyConfig() {

            let configuration = KVNProgressConfiguration()
            configuration.minimumDisplayTime = 3.0
            configuration.minimumSuccessDisplayTime = 3.0
            configuration.minimumErrorDisplayTime = 3.0
            KVNProgress.setConfiguration(configuration)
        }

        static func show() {

            if KVNProgress.isVisible() {
                KVNProgress.dismiss(completion: {
                    KVNProgress.show()
                })
            } else {
                KVNProgress.show()
            }
        }

        static func dismiss() {

            if KVNProgress.isVisible() {
                KVNProgress.dismiss()
            }
        }

        static func dismiss(withCallback callback: @escaping () -> ()) {

            if KVNProgress.isVisible() {
                KVNProgress.dismiss(completion: { 
                    callback()
                })
            } else {
                callback()
            }
        }

        static func showError(withStatus status: String) {

            if KVNProgress.isVisible() {
                KVNProgress.dismiss(completion: { 
                    KVNProgress.showError(withStatus: status)
                })
            } else {
                KVNProgress.showError(withStatus: status)
            }
        }

        static func showSuccess(withStatus status: String) {

            if KVNProgress.isVisible() {
                KVNProgress.dismiss(completion: {
                    KVNProgress.showSuccess(withStatus: status)
                })
            } else {
                KVNProgress.showSuccess(withStatus: status)
            }
        }
    }
pritesh-khandelwal commented 7 years ago

Issue still exist with alamofire . Can anyone help on this .