From a77f1a435659f83003b2d61c31adfd8185367782 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Tue, 19 Sep 2023 19:51:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6=E5=99=A8?= =?UTF-8?q?=E5=A4=B1=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHDemo/PHDemo/DemoToastVC.swift | 6 ++++++ Sources/ProHUD/Alert/AlertTarget.swift | 4 ++++ Sources/ProHUD/Capsule/CapsuleTarget.swift | 1 + Sources/ProHUD/Toast/ToastTarget.swift | 4 ++++ 4 files changed, 15 insertions(+) diff --git a/PHDemo/PHDemo/DemoToastVC.swift b/PHDemo/PHDemo/DemoToastVC.swift index 7e2cfec..9245347 100644 --- a/PHDemo/PHDemo/DemoToastVC.swift +++ b/PHDemo/PHDemo/DemoToastVC.swift @@ -118,6 +118,12 @@ class DemoToastVC: ListVC { section.add(title: "标题 + 正文") { TestToast(.title(title).message(message)) } + section.add(title: "防止重复") { + TestToast(.identifier("toast").title(title).message(message).duration(2)) + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + TestToast(.identifier("toast").title(title).message(message).duration(2)) + } + } section.add(title: "一段长文本") { // Toast(.message(message)) // 可以简写成这样: diff --git a/Sources/ProHUD/Alert/AlertTarget.swift b/Sources/ProHUD/Alert/AlertTarget.swift index ff6335e..0b11ec3 100644 --- a/Sources/ProHUD/Alert/AlertTarget.swift +++ b/Sources/ProHUD/Alert/AlertTarget.swift @@ -73,8 +73,12 @@ open class AlertTarget: BaseController, HUDTargetType { /// 视图模型 @objc public var vm: AlertViewModel? { + willSet { + vm?.cancelTimer() + } didSet { vm?.vc = self + vm?.restartTimer() } } diff --git a/Sources/ProHUD/Capsule/CapsuleTarget.swift b/Sources/ProHUD/Capsule/CapsuleTarget.swift index a1463ca..62781d5 100644 --- a/Sources/ProHUD/Capsule/CapsuleTarget.swift +++ b/Sources/ProHUD/Capsule/CapsuleTarget.swift @@ -48,6 +48,7 @@ open class CapsuleTarget: BaseController, HUDTargetType { } didSet { vm?.vc = self + vm?.restartTimer() } } diff --git a/Sources/ProHUD/Toast/ToastTarget.swift b/Sources/ProHUD/Toast/ToastTarget.swift index 8417e35..f7d96f6 100644 --- a/Sources/ProHUD/Toast/ToastTarget.swift +++ b/Sources/ProHUD/Toast/ToastTarget.swift @@ -83,8 +83,12 @@ open class ToastTarget: BaseController, HUDTargetType { /// 视图模型 @objc public var vm: ToastViewModel? { + willSet { + vm?.cancelTimer() + } didSet { vm?.vc = self + vm?.restartTimer() } }