代码优化

This commit is contained in:
xaoxuu 2021-07-20 16:04:39 +08:00
parent 6b870e4ba8
commit 014e9abdbe
27 changed files with 134 additions and 121 deletions

View File

@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "prohud.rainbow.circle@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "prohud.rainbow.circle@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "prohud.trash@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "prohud.trash@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

@ -43,8 +43,13 @@ class BaseListVC: UIViewController {
var secs = [Section]()
lazy var tableView: UITableView = {
let tv = UITableView(frame: .zero, style: .insetGrouped)
let tv: UITableView
if #available(iOS 13.0, *) {
tv = UITableView(frame: .zero, style: .insetGrouped)
} else {
// Fallback on earlier versions
tv = UITableView(frame: .zero, style: .grouped)
}
return tv
}()

View File

@ -35,6 +35,11 @@ class TestGuardVC: BaseListVC {
vm.add(action: .cancel, title: "取消", handler: nil)
}
}
DispatchQueue.main.asyncAfter(deadline: .now()+1) {
Guard.find("del") { vc in
vc.pop()
}
}
}
// MARK:

View File

@ -1,5 +1,5 @@
PODS:
- Inspire (2.0.0)
- Inspire (2.1.0)
- ProHUD (1.0):
- Inspire
- SnapKit (= 5.0)
@ -21,10 +21,10 @@ EXTERNAL SOURCES:
:path: ".."
SPEC CHECKSUMS:
Inspire: 7556357c9c90d5e886f3be5d29fe1e0222b694e1
Inspire: 087dce1e4ff902d26d79bd3453352af09411c172
ProHUD: 7128b55036885ac4f8b4d0b0783ee6f8eb3a2ea9
SnapKit: fd22d10eb9aff484d79a8724eab922c1ddf89bcf
PODFILE CHECKSUM: 80148eec6ba2e9631b208c7b277316b6c551afc4
COCOAPODS: 1.9.2
COCOAPODS: 1.10.1

4
Example-Old/README.md Normal file
View File

@ -0,0 +1,4 @@
# 使用 AppDelegate 的项目

View File

@ -19,7 +19,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let scene = (scene as? UIWindowScene) else { return }
print(scene.statusBarManager?.statusBarFrame)
let rootVC = RootVC()
window?.rootViewController = rootVC
window?.makeKeyAndVisible()

View File

@ -0,0 +1,2 @@
# 使用 SceneDelegate 的项目

View File

@ -10,7 +10,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/SnapKit/SnapKit.git", "5.0.0" ..< "6.0.0"),
.package(url: "https://github.com/xaoxuu/Inspire.git", "2.0.0" ..< "3.0.0"),
.package(url: "https://github.com/xaoxuu/Inspire.git", "2.1.0" ..< "3.0.0"),
],
targets: [
.target(

View File

@ -23,8 +23,8 @@
CDB6A07B22EEF06500AF6CF0 /* HUDController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB6A07A22EEF06500AF6CF0 /* HUDController.swift */; };
CDB6A07D22EEF19D00AF6CF0 /* HUDConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB6A07C22EEF19D00AF6CF0 /* HUDConfig.swift */; };
CDC39CFD22FD6DDF0070E914 /* GuardModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDC39CFC22FD6DDF0070E914 /* GuardModel.swift */; };
CDC67BE92490A19100CC6FE6 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; productRef = CDC67BE82490A19100CC6FE6 /* SwiftPackageProductDependency */; };
CDC67BEC2490A1D100CC6FE6 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; productRef = CDC67BEB2490A1D100CC6FE6 /* SwiftPackageProductDependency */; };
CDC67BE92490A19100CC6FE6 /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = CDC67BE82490A19100CC6FE6 /* SnapKit */; };
CDC67BEC2490A1D100CC6FE6 /* Inspire in Frameworks */ = {isa = PBXBuildFile; productRef = CDC67BEB2490A1D100CC6FE6 /* Inspire */; };
CDF2C58924A0572C002ECDD5 /* HUDUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF2C58824A0572C002ECDD5 /* HUDUtils.swift */; };
/* End PBXBuildFile section */
@ -58,8 +58,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
CDC67BEC2490A1D100CC6FE6 /* BuildFile in Frameworks */,
CDC67BE92490A19100CC6FE6 /* BuildFile in Frameworks */,
CDC67BEC2490A1D100CC6FE6 /* Inspire in Frameworks */,
CDC67BE92490A19100CC6FE6 /* SnapKit in Frameworks */,
36CB9DEED3C3E823FE7B1C75 /* Pods_ProHUD.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -189,8 +189,8 @@
);
name = ProHUD;
packageProductDependencies = (
CDC67BE82490A19100CC6FE6 /* SwiftPackageProductDependency */,
CDC67BEB2490A1D100CC6FE6 /* SwiftPackageProductDependency */,
CDC67BE82490A19100CC6FE6 /* SnapKit */,
CDC67BEB2490A1D100CC6FE6 /* Inspire */,
);
productName = ProHUD;
productReference = CD95D21C22E72C4C007559A3 /* ProHUD.framework */;
@ -221,8 +221,8 @@
);
mainGroup = CD95D21222E72C4C007559A3;
packageReferences = (
CDC67BE72490A19100CC6FE6 /* RemoteSwiftPackageReference */,
CDC67BEA2490A1D100CC6FE6 /* RemoteSwiftPackageReference */,
CDC67BE72490A19100CC6FE6 /* XCRemoteSwiftPackageReference "SnapKit" */,
CDC67BEA2490A1D100CC6FE6 /* XCRemoteSwiftPackageReference "Inspire" */,
);
productRefGroup = CD95D21D22E72C4C007559A3 /* Products */;
projectDirPath = "";
@ -493,7 +493,7 @@
/* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */
CDC67BE72490A19100CC6FE6 /* RemoteSwiftPackageReference */ = {
CDC67BE72490A19100CC6FE6 /* XCRemoteSwiftPackageReference "SnapKit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/SnapKit/SnapKit";
requirement = {
@ -501,25 +501,25 @@
minimumVersion = 5.0.1;
};
};
CDC67BEA2490A1D100CC6FE6 /* RemoteSwiftPackageReference */ = {
CDC67BEA2490A1D100CC6FE6 /* XCRemoteSwiftPackageReference "Inspire" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/xaoxuu/Inspire";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.0.0;
minimumVersion = 2.1.0;
};
};
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
CDC67BE82490A19100CC6FE6 /* SwiftPackageProductDependency */ = {
CDC67BE82490A19100CC6FE6 /* SnapKit */ = {
isa = XCSwiftPackageProductDependency;
package = CDC67BE72490A19100CC6FE6 /* RemoteSwiftPackageReference */;
package = CDC67BE72490A19100CC6FE6 /* XCRemoteSwiftPackageReference "SnapKit" */;
productName = SnapKit;
};
CDC67BEB2490A1D100CC6FE6 /* SwiftPackageProductDependency */ = {
CDC67BEB2490A1D100CC6FE6 /* Inspire */ = {
isa = XCSwiftPackageProductDependency;
package = CDC67BEA2490A1D100CC6FE6 /* RemoteSwiftPackageReference */;
package = CDC67BEA2490A1D100CC6FE6 /* XCRemoteSwiftPackageReference "Inspire" */;
productName = Inspire;
};
/* End XCSwiftPackageProductDependency section */

View File

@ -10,7 +10,7 @@ import UIKit
import SnapKit
public extension UIWindow.Level {
static let proAlert = UIWindow.Level.alert - 1
static let alertForProHUD = UIWindow.Level.alert - 1
}
public extension ProHUD.Configuration {
@ -75,7 +75,7 @@ public extension ProHUD.Configuration {
// MARK: -
internal extension ProHUD.Configuration.Alert {
extension ProHUD.Configuration.Alert {
var reloadData: (ProHUD.Alert) -> Void {
return privReloadData

View File

@ -14,9 +14,9 @@ public typealias Alert = ProHUD.Alert
public extension ProHUD {
class Alert: HUDController {
internal static var alerts = [Alert]()
static var alerts = [Alert]()
internal static var alertWindow: UIWindow?
static var alertWindow: UIWindow?
///
public var contentView = createBlurView()
@ -96,9 +96,7 @@ public extension Alert {
window.resignKey()
window.addSubview(view)
if #available(iOS 13.0, *) {
window.windowScene = cfg.windowScene ?? UIApplication.shared.windows.first?.windowScene
} else {
// Fallback on earlier versions
window.windowScene = cfg.windowScene ?? .currentWindowScene
}
view.transform = .init(scaleX: 1.2, y: 1.2)
view.alpha = 0
@ -234,7 +232,7 @@ public extension Alert {
// MARK: -
internal extension Alert {
extension Alert {
///
/// - Parameter style:
@ -338,19 +336,13 @@ fileprivate extension Alert {
alertWindow = w
w.backgroundColor = UIColor.init(red: 0, green: 0, blue: 0, alpha: 0)
// alert
w.windowLevel = .proAlert
w.windowLevel = .alertForProHUD
return w
}
class func privRemoveItemFromArray(alert: Alert) {
if alerts.count > 1 {
for (i, a) in alerts.enumerated() {
if a == alert {
if i < alerts.count {
alerts.remove(at: i)
}
}
}
alerts.removeAll { $0 == alert }
privUpdateAlertsLayout()
} else if alerts.count == 1 {
alerts.removeAll()

View File

@ -47,15 +47,15 @@ public extension Alert {
// MARK:
///
internal var durationBlock: DispatchWorkItem?
var durationBlock: DispatchWorkItem?
/// 退
internal var hideTimerBlock: DispatchWorkItem?
var hideTimerBlock: DispatchWorkItem?
/// 退
internal var forceQuitCallback: (() -> Void)?
var forceQuitCallback: (() -> Void)?
internal func updateDuration() {
func updateDuration() {
durationBlock?.cancel()
if let t = duration ?? scene.alertDuration, t > 0 {
durationBlock = DispatchWorkItem(block: { [weak self] in

View File

@ -51,7 +51,7 @@ public extension ProHUD.Configuration {
// MARK: -
internal extension ProHUD.Configuration.Guard {
extension ProHUD.Configuration.Guard {
var reloadData: (ProHUD.Guard) -> Void {
return privReloadData

View File

@ -119,21 +119,8 @@ public extension Guard {
}
if let vc = viewController ?? cfg.rootViewController {
return f(vc)
} else {
// RootVC
let ws = UIApplication.shared.windows.filter { (w) -> Bool in
// UITextEffectsWindow Window
if "\(type(of:w))" == "UIWindow" && w.isHidden == false && w.windowLevel == .normal {
return true
} else {
return false
}
}
for w in ws {
if let vc = w.rootViewController {
} else if let vc = UIViewController.currentRootViewController {
return f(vc)
}
}
debug("自动获取根控制器失败请设置根控制器或者传入需要push到的控制器")
}
return self
@ -200,24 +187,16 @@ public extension Guard {
///
/// - Parameter identifier:
class func find(_ identifier: String?, from viewController: UIViewController? = nil) -> [Guard] {
var gg = [Guard]()
if let vc = viewController ?? cfg.rootViewController {
for child in vc.children {
if child.isKind(of: Guard.self) {
if let g = child as? Guard {
if let id = identifier {
if g.identifier == id {
gg.append(g)
}
guard let vc = viewController ?? cfg.rootViewController ?? UIViewController.currentRootViewController else { return [] }
return vc.children.compactMap { (child) -> Guard? in
guard let child = child as? Guard else { return nil }
if let id = identifier, child.identifier == id {
return child
} else {
gg.append(g)
return child
}
}
}
}
}
return gg
}
///
/// - Parameter identifier:
@ -249,7 +228,7 @@ public extension Guard {
// MARK: -
internal extension Guard {
extension Guard {
///
/// - Parameter text:

View File

@ -12,7 +12,7 @@ public extension Guard {
struct ViewModel {
internal weak var vc: Guard?
weak var vc: Guard?
}

View File

@ -8,6 +8,7 @@
import UIKit
@available(iOS 13.0, *) fileprivate var sharedWindowScene: UIWindowScene?
/// HUD
public extension ProHUD {
@ -19,22 +20,14 @@ public extension ProHUD {
///
public var rootViewController: UIViewController?
/// iOS13
@available(iOS 13.0, *)
private static var sharedWindowScene: UIWindowScene?
/// iOS13
@available(iOS 13.0, *)
public var windowScene: UIWindowScene? {
set {
Configuration.sharedWindowScene = newValue
}
get {
return Configuration.sharedWindowScene
}
set { sharedWindowScene = newValue }
get { sharedWindowScene }
}
/// iOS13
///
public lazy var dynamicColor: UIColor = {
if #available(iOS 13.0, *) {
let color = UIColor { (traitCollection: UITraitCollection) -> UIColor in

View File

@ -85,9 +85,7 @@ internal extension HUDController {
}
@objc func didTappedButton(_ sender: UIButton) {
if let ac = buttonEvents[sender] {
ac()
}
buttonEvents[sender]?()
}
}
@ -117,8 +115,8 @@ public extension LoadingAnimationView {
v.updateProgress(progress: progress)
}
}
}
}
///
public protocol LoadingRotateAnimation: LoadingAnimationView {}

View File

@ -15,16 +15,16 @@ extension String {
extension ProHUD {
static var safeAreaInsets: UIEdgeInsets {
return Inspire.shared.screen.safeAreaInsets
Inspire.shared.screen.safeAreaInsets
}
}
func == (left: ProHUD.Scene, right: ProHUD.Scene) -> Bool {
return left.identifier == right.identifier
left.identifier == right.identifier
}
func != (left: ProHUD.Scene, right: ProHUD.Scene) -> Bool {
return left.identifier != right.identifier
left.identifier != right.identifier
}

View File

@ -12,22 +12,23 @@ public class ProHUD {
public static let shared = ProHUD()
public var config: Configuration {
return cfg
public var config: Configuration { cfg }
}
public struct Scene {
private var id = "unknown"
public var identifier: String {
return id
}
// MARK: - Scene
public extension ProHUD {
struct Scene {
public let identifier: String
public var image: UIImage?
public var alertDuration: TimeInterval?
public var toastDuration: TimeInterval? = 3
public var title: String?
public var message: String?
init() {
public init(identifier: String) {
self.identifier = identifier
}
}
@ -35,10 +36,6 @@ public class ProHUD {
//
public extension ProHUD.Scene {
init(identifier: String) {
self.init()
id = identifier
}
static var `default`: ProHUD.Scene {
var scene = ProHUD.Scene.init(identifier: "prohud.default")
scene.image = ProHUD.image(named: "prohud.note")

View File

@ -53,7 +53,7 @@ public extension ProHUD.Configuration {
// MARK: -
internal extension ProHUD.Configuration.Toast {
extension ProHUD.Configuration.Toast {
var reloadData: (ProHUD.Toast) -> Void {
return privReloadData

View File

@ -13,7 +13,7 @@ public typealias Toast = ProHUD.Toast
public extension ProHUD {
class Toast: HUDController {
internal static var toasts = [Toast]()
static var toasts = [Toast]()
public var window: UIWindow?
@ -66,7 +66,7 @@ public extension ProHUD {
///
public var vm = ViewModel()
internal var maxY = CGFloat(0)
var maxY = CGFloat(0)
// MARK:
@ -120,9 +120,7 @@ public extension Toast {
let window = UIWindow(frame: .zero)
self.window = window
if #available(iOS 13.0, *) {
window.windowScene = cfg.windowScene ?? UIApplication.shared.windows.first?.windowScene
} else {
// Fallback on earlier versions
window.windowScene = cfg.windowScene ?? .currentWindowScene
}
window.windowLevel = .proToast
window.backgroundColor = .clear
@ -270,11 +268,7 @@ public extension Toast {
class func pop(_ toast: Toast) {
toast.willDisappearCallback?()
if toasts.count > 1 {
for (i, t) in toasts.enumerated() {
if t == toast {
toasts.remove(at: i)
}
}
toasts.removeAll { $0 == toast }
privUpdateToastsLayout()
} else if toasts.count == 1 {
toasts.removeAll()

View File

@ -47,12 +47,12 @@ public extension Toast {
// MARK:
///
internal var durationBlock: DispatchWorkItem?
var durationBlock: DispatchWorkItem?
///
internal var tapCallback: (() -> Void)?
var tapCallback: (() -> Void)?
internal func updateDuration() {
func updateDuration() {
durationBlock?.cancel()
if let t = duration ?? scene.toastDuration, t > 0 {
durationBlock = DispatchWorkItem(block: { [weak self] in