From f5ec26f8fb1c5c313c8754215ce1ce7a89f0e85f Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Thu, 24 Aug 2023 12:39:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHDemo/PHDemo/DemoCapsuleVC.swift | 2 +- PHDemo/PHDemo/DemoSheetVC.swift | 2 +- .../ProHUD/Core/Models/BaseViewModel.swift | 81 ++++++++++--------- Sources/ProHUD/Core/Models/Rotation.swift | 6 ++ 4 files changed, 50 insertions(+), 41 deletions(-) diff --git a/PHDemo/PHDemo/DemoCapsuleVC.swift b/PHDemo/PHDemo/DemoCapsuleVC.swift index c8ab9ff..5f76637 100644 --- a/PHDemo/PHDemo/DemoCapsuleVC.swift +++ b/PHDemo/PHDemo/DemoCapsuleVC.swift @@ -184,7 +184,7 @@ class DemoCapsuleVC: ListVC { list.add(title: "lazy push") { section in section.add(title: "以当前代码位置作为唯一标识符") { i += 1 - Capsule(.codeIdentifier().message("id=\(i)")) + Capsule(.identifier().message("id=\(i)")) } section.add(title: "指定id=a, haha") { Capsule(.identifier("a").message("id=a, haha")) diff --git a/PHDemo/PHDemo/DemoSheetVC.swift b/PHDemo/PHDemo/DemoSheetVC.swift index d9a1d65..10778ab 100644 --- a/PHDemo/PHDemo/DemoSheetVC.swift +++ b/PHDemo/PHDemo/DemoSheetVC.swift @@ -76,7 +76,7 @@ class DemoSheetVC: ListVC { sheet.onTappedBackground { sheet in Toast( .error - .lazyIdentifier() + .identifier() .title("点击了背景") .message("点击背景将不会dismiss,必须在下方做出选择才能关掉") .duration(2) diff --git a/Sources/ProHUD/Core/Models/BaseViewModel.swift b/Sources/ProHUD/Core/Models/BaseViewModel.swift index a4fd4d8..37fb9ae 100644 --- a/Sources/ProHUD/Core/Models/BaseViewModel.swift +++ b/Sources/ProHUD/Core/Models/BaseViewModel.swift @@ -101,16 +101,27 @@ open class BaseViewModel: NSObject, HUDViewModelType { // MARK: - convenience func public extension BaseViewModel { - @discardableResult func identifier(_ identifier: String?) -> Self { - self.identifier = identifier + // MARK: identifier + + /// 设置唯一标识符(不传参数则以代码位置作为唯一标识符) + /// - Parameters: + /// - identifier: 指定的唯一标识符 + /// - Returns: 唯一标识符 + @discardableResult func identifier(_ identifier: String? = nil, file: String = #file, line: Int = #line) -> Self { + self.identifier = identifier ?? (file + "#\(line)") return self } - @discardableResult func lazyIdentifier(file: String = #file, line: Int = #line) -> Self { - self.identifier = (file + "#\(line)") - return self + /// 设置唯一标识符(不传参数则以代码位置作为唯一标识符) + /// - Parameters: + /// - identifier: 指定的唯一标识符 + /// - Returns: 唯一标识符 + @discardableResult static func identifier(_ identifier: String? = nil, file: String = #file, line: Int = #line) -> Self { + .init().identifier(identifier, file: file, line: line) } + // MARK: icon + @discardableResult func icon(_ image: UIImage?) -> Self { self.icon = image return self @@ -129,16 +140,40 @@ public extension BaseViewModel { } } + static func icon(_ imageURLStr: String) -> Self { + .init().icon(imageURLStr) + } + static func icon(_ imageURL: URL) -> Self { + .init().icon(imageURL) + } + static func icon(_ image: UIImage?) -> Self { + .init().icon(image) + } + + // MARK: text + @discardableResult func title(_ text: String?) -> Self { self.title = text return self } + static func title(_ text: String?) -> Self { + .init() + .title(text) + } + @discardableResult func message(_ text: String?) -> Self { self.message = text return self } + static func message(_ text: String?) -> Self { + .init() + .message(text) + } + + // MARK: others + @discardableResult func duration(_ seconds: TimeInterval?) -> Self { self.duration = seconds return self @@ -159,48 +194,16 @@ public extension BaseViewModel { // MARK: - example scenes public extension BaseViewModel { - /// 设置指定的唯一标识符 - /// - Parameter text: 唯一标识符 - static func identifier(_ text: String?) -> Self { - .init() - .identifier(text) - } - - /// 以当前代码位置作为唯一标识符 - static func codeIdentifier(file: String = #file, line: Int = #line) -> Self { - identifier((file + "#\(line)")) - } - - // MARK: plain - static func title(_ text: String?) -> Self { - .init() - .title(text) - } - static func message(_ text: String?) -> Self { - .init() - .message(text) - } - - static func icon(_ imageURLStr: String) -> Self { - .init().icon(imageURLStr) - } - static func icon(_ imageURL: URL) -> Self { - .init().icon(imageURL) - } - static func icon(_ image: UIImage?) -> Self { - .init().icon(image) - } - // MARK: loading static var loading: Self { .init() .icon(.init(inProHUD: "prohud.windmill")) - .rotation(.init(repeatCount: .infinity)) + .rotation(.default) } static func loading(_ seconds: TimeInterval) -> Self { .init() .icon(.init(inProHUD: "prohud.windmill")) - .rotation(.init(repeatCount: .infinity)) + .rotation(.default) .duration(seconds) } // MARK: success diff --git a/Sources/ProHUD/Core/Models/Rotation.swift b/Sources/ProHUD/Core/Models/Rotation.swift index d791af4..db21c21 100644 --- a/Sources/ProHUD/Core/Models/Rotation.swift +++ b/Sources/ProHUD/Core/Models/Rotation.swift @@ -30,3 +30,9 @@ public struct Rotation { } } + +public extension Rotation { + static var `default`: Self { + .init(direction: .clockwise, speed: 2, repeatCount: .infinity) + } +}