代码优化

This commit is contained in:
xaoxuu 2023-08-24 12:39:44 +08:00
parent c57b859555
commit f5ec26f8fb
4 changed files with 50 additions and 41 deletions

View File

@ -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"))

View File

@ -76,7 +76,7 @@ class DemoSheetVC: ListVC {
sheet.onTappedBackground { sheet in
Toast(
.error
.lazyIdentifier()
.identifier()
.title("点击了背景")
.message("点击背景将不会dismiss必须在下方做出选择才能关掉")
.duration(2)

View File

@ -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

View File

@ -30,3 +30,9 @@ public struct Rotation {
}
}
public extension Rotation {
static var `default`: Self {
.init(direction: .clockwise, speed: 2, repeatCount: .infinity)
}
}