Skip to content

Commit

Permalink
config update
Browse files Browse the repository at this point in the history
config update
  • Loading branch information
liyb93 committed Aug 4, 2022
1 parent 4103ab1 commit 5b89981
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
Binary file not shown.
4 changes: 3 additions & 1 deletion Source/LYBProgressHUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class LYBProgressHUDStyle: NSObject {
}
}

public typealias CompletionHandler = ()->()
public class LYBProgressHUD: NSView {

private var maskView: NSView!
Expand Down Expand Up @@ -216,10 +217,11 @@ public class LYBProgressHUD: NSView {
hud.show()
}

public class func dismiss(in view: NSView, after delay: TimeInterval = 0) {
public class func dismiss(in view: NSView, after delay: TimeInterval = 0, completionHandler: CompletionHandler? = nil) {
view.subviews.filter({$0 is LYBProgressHUD}).forEach { (view) in
(view as? LYBProgressHUD)?.dismiss(after: delay)
}
completionHandler?()
}
}

Expand Down
51 changes: 51 additions & 0 deletions Source/NSView+LYBProgressHUD.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// NSView+LYBProgressHUD.swift
// LBProgressHUD
//
// Created by mac on 2022/8/4.
//

import Cocoa

public protocol NamespaceCompatible {
associatedtype CompatibleType
var lyb: CompatibleType { get }
static var lyb: CompatibleType.Type { get }
}

public struct Namespace<Base> {
let base: Base

init(_ base: Base) {
self.base = base
}
}

public extension NamespaceCompatible {
var lyb: Namespace<Self> {
return Namespace(self)
}

static var lyb: Namespace<Self>.Type {
return Namespace.self
}
}

extension NSView: NamespaceCompatible { }

public typealias StyleHandler = (LYBProgressHUDStyle)->()
public extension Namespace where Base: NSView {
@discardableResult
func showHUD(_ message: String? = nil, style: StyleHandler? = nil) -> Namespace {
let hudStyle = LYBProgressHUDStyle.init()
style?(hudStyle)
LYBProgressHUD.show(in: base, message: message, style: hudStyle)
return self
}

@discardableResult
func dismiss(_ delay: TimeInterval = 0, completionHandler: CompletionHandler? = nil) -> Namespace {
LYBProgressHUD.dismiss(in: base, after: delay, completionHandler: completionHandler)
return self
}
}

0 comments on commit 5b89981

Please sign in to comment.