ProgressHUD
ProgressHUD copied to clipboard
completion handler on hide
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:
- show hud for at least one second even if network request is quite fast
- show "Success!" for 1.5 seconds to give user a chance to read
- hide hud & dismiss view controller
/// 显示成功提示
/// - 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()
}