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

completion handler on hide #103

Open
gurgeous opened this issue Aug 26, 2020 · 1 comment
Open

completion handler on hide #103

gurgeous opened this issue Aug 26, 2020 · 1 comment

Comments

@gurgeous
Copy link

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
@hubin97
Copy link

hubin97 commented Sep 26, 2024

    /// 显示成功提示
    /// - 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()
    }

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

No branches or pull requests

3 participants