ProgressHUD icon indicating copy to clipboard operation
ProgressHUD copied to clipboard

completion handler on hide

Open gurgeous opened this issue 5 years ago • 1 comments

Great work, thanks for making it available! This thing is sweet.

One minor feature request. It would be nice to get a callback after the if hide timer, since I typically have to take some action on my end. For example, I want to show "Success!" for 1.5 seconds and then dismiss my modal vc. The builtin hiding delay is thoughtful but I can't take advantage of it without a completion handler.

Typical flow:

  1. show hud for at least one second even if network request is quite fast
  2. show "Success!" for 1.5 seconds to give user a chance to read
  3. hide hud & dismiss view controller

gurgeous avatar Aug 26 '20 18:08 gurgeous

    /// 显示成功提示
    /// - Parameters:
    ///   - status: 文本
    ///   - delay: 延时隐藏
    ///   - completion: 完成回调
    static func showSuccess(_ status: String?, delay: TimeInterval? = nil, completion: (() -> Void)? = nil) {
        let delay = delay ?? duration(status ?? "")
        ProgressHUD.success(status, delay: delay)
        DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
            completion?()
        }
    }
    
    /// 显示失败提示
    /// - Parameters:
    ///   - status: 文本
    ///   - delay: 延时隐藏
    static func showError(_ status: String?, delay: TimeInterval? = nil) {
        ProgressHUD.error(status, delay: delay ?? duration(status ?? ""))
    }
    
    /// 隐藏提示
    /// - Parameters:
    ///   - delay: 延时隐藏
    ///   - completion: 隐藏回调
    static func dismiss(delay: TimeInterval? = nil, completion: (() -> Void)? = nil) {
        if let delay = delay {
            DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
                ProgressHUD.dismiss()
                completion?()
            }
            return
        }
        ProgressHUD.dismiss()
    }

hubin97 avatar Sep 26 '24 04:09 hubin97