From c45639870121f24b62a2d2290736b003b50bd148 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Mon, 12 Sep 2022 21:22:43 +0800 Subject: [PATCH] update readme --- PHDemo/PHDemo/AlertVC.swift | 24 ++++---- .../Contents.json | 0 .../Feel1@2x.png | Bin .../Feel1@3x.png | Bin PHDemo/PHDemo/TableHeaderView.swift | 2 +- PHDemo/PHDemo/ToastVC.swift | 55 ++++++++++++++---- Sources/ProHUD/Alert/AlertDefaultLayout.swift | 4 +- Sources/ProHUD/Sheet/SheetConfiguration.swift | 2 + 8 files changed, 59 insertions(+), 28 deletions(-) rename PHDemo/PHDemo/Assets.xcassets/{Feel1.imageset => twemoji.imageset}/Contents.json (100%) rename PHDemo/PHDemo/Assets.xcassets/{Feel1.imageset => twemoji.imageset}/Feel1@2x.png (100%) rename PHDemo/PHDemo/Assets.xcassets/{Feel1.imageset => twemoji.imageset}/Feel1@3x.png (100%) diff --git a/PHDemo/PHDemo/AlertVC.swift b/PHDemo/PHDemo/AlertVC.swift index 669be07..a27f5a6 100644 --- a/PHDemo/PHDemo/AlertVC.swift +++ b/PHDemo/PHDemo/AlertVC.swift @@ -46,19 +46,17 @@ class AlertVC: ListVC { Alert(.loading(3)).push() } section.add(title: "图标 + 文字") { - Alert(.loading(4).message("正在加载")) { alert in - alert.update(progress: 0) - DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) { - alert.update(progress: 0.01) - } - DispatchQueue.main.asyncAfter(deadline: .now() + 1) { - alert.update(progress: 0.33) - } - DispatchQueue.main.asyncAfter(deadline: .now() + 2) { - alert.update(progress: 0.67) - } - DispatchQueue.main.asyncAfter(deadline: .now() + 3) { - alert.update(progress: 1) + Alert(.loading.message("正在加载")) { alert in + updateProgress(in: 4) { percent in + alert.update(progress: percent) + } completion: { + alert.update { alert in + alert.vm = .success.message("加载成功") + alert.add(action: "OK") + } + DispatchQueue.main.asyncAfter(deadline: .now()+2) { + alert.pop() + } } } } diff --git a/PHDemo/PHDemo/Assets.xcassets/Feel1.imageset/Contents.json b/PHDemo/PHDemo/Assets.xcassets/twemoji.imageset/Contents.json similarity index 100% rename from PHDemo/PHDemo/Assets.xcassets/Feel1.imageset/Contents.json rename to PHDemo/PHDemo/Assets.xcassets/twemoji.imageset/Contents.json diff --git a/PHDemo/PHDemo/Assets.xcassets/Feel1.imageset/Feel1@2x.png b/PHDemo/PHDemo/Assets.xcassets/twemoji.imageset/Feel1@2x.png similarity index 100% rename from PHDemo/PHDemo/Assets.xcassets/Feel1.imageset/Feel1@2x.png rename to PHDemo/PHDemo/Assets.xcassets/twemoji.imageset/Feel1@2x.png diff --git a/PHDemo/PHDemo/Assets.xcassets/Feel1.imageset/Feel1@3x.png b/PHDemo/PHDemo/Assets.xcassets/twemoji.imageset/Feel1@3x.png similarity index 100% rename from PHDemo/PHDemo/Assets.xcassets/Feel1.imageset/Feel1@3x.png rename to PHDemo/PHDemo/Assets.xcassets/twemoji.imageset/Feel1@3x.png diff --git a/PHDemo/PHDemo/TableHeaderView.swift b/PHDemo/PHDemo/TableHeaderView.swift index 8d1e482..7713945 100644 --- a/PHDemo/PHDemo/TableHeaderView.swift +++ b/PHDemo/PHDemo/TableHeaderView.swift @@ -38,7 +38,7 @@ class TableHeaderView: UIView { addSubview(titleLabel) titleLabel.snp.makeConstraints { make in make.left.right.equalToSuperview().inset(24) - make.top.equalToSuperview().offset(20) + make.top.equalToSuperview().offset(28) } detailLabel.snp.makeConstraints { make in make.left.right.equalTo(titleLabel) diff --git a/PHDemo/PHDemo/ToastVC.swift b/PHDemo/PHDemo/ToastVC.swift index c944fff..cf48922 100644 --- a/PHDemo/PHDemo/ToastVC.swift +++ b/PHDemo/PHDemo/ToastVC.swift @@ -8,6 +8,29 @@ import UIKit import ProHUD + +func updateProgress(in duration: TimeInterval, callback: @escaping (_ percent: CGFloat) -> Void, completion: (() -> Void)?) { + let s = DispatchSemaphore(value: 1) + DispatchQueue.global().async { + let total = 50 + for i in 0 ... total { + s.wait() + DispatchQueue.main.async { + callback(CGFloat(i)/CGFloat(total)) + DispatchQueue.main.asyncAfter(deadline: .now() + (duration / TimeInterval(total))) { + s.signal() + if i == total { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { + completion?() + } + } + } + } + } + } +} + + class ToastVC: ListVC { override func viewDidLoad() { @@ -25,7 +48,6 @@ class ToastVC: ListVC { } } - let vm: ViewModel = .loading list.add(title: "默认布局") { section in section.add(title: "标题 + 正文") { Toast(.title(title).message(message)).push() @@ -34,20 +56,29 @@ class ToastVC: ListVC { Toast(.message(message)).push() } section.add(title: "图标 + 标题 + 正文") { - let s1 = "正在加载" - let s2 = "这条通知4s后消失" - let toast = Toast(.loading(4).title(s1).message(s2)) + let s1 = "笑容正在加载" + let s2 = "这通常不会太久" + let toast = Toast(.loading.title(s1).message(s2)) toast.push() toast.update(progress: 0) - DispatchQueue.main.asyncAfter(deadline: .now() + 1) { - toast.update(progress: 0.5) - } - DispatchQueue.main.asyncAfter(deadline: .now() + 2) { - toast.update(progress: 1) - } - DispatchQueue.main.asyncAfter(deadline: .now() + 2.5) { + updateProgress(in: 4) { percent in + toast.update(progress: percent) + } completion: { toast.update { toast in - toast.vm = .success(10).title("加载成功").message("这条通知10s后消失") + toast.vm = .success(5).title("加载成功").message("这条通知5s后消失") + toast.vm.icon = UIImage(named: "twemoji") + } + } + } + section.add(title: "倒计时") { + let s1 = "笑容正在消失" + let s2 = "这通常不会太久" + Toast { toast in + toast.vm = .title(s1).message(s2).icon(UIImage(named: "twemoji")) + updateProgress(in: 5) { percent in + toast.update(progress: 1 - percent) + } completion: { + toast.pop() } } } diff --git a/Sources/ProHUD/Alert/AlertDefaultLayout.swift b/Sources/ProHUD/Alert/AlertDefaultLayout.swift index deaf9b5..e61d34b 100644 --- a/Sources/ProHUD/Alert/AlertDefaultLayout.swift +++ b/Sources/ProHUD/Alert/AlertDefaultLayout.swift @@ -62,7 +62,7 @@ extension Alert: DefaultLayout { if contentView.superview != view { view.insertSubview(contentView, at: 0) } - if config.enableShadow { + if config.enableShadow && AlertWindow.alerts.count > 0 { contentView.clipsToBounds = false contentView.layer.shadowRadius = 4 contentView.layer.shadowOpacity = 0.08 @@ -244,7 +244,7 @@ extension Alert { public override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() - if config.enableShadow { + if config.enableShadow && AlertWindow.alerts.count > 1 { contentView.layer.shadowPath = UIBezierPath.init(rect: contentView.bounds).cgPath } } diff --git a/Sources/ProHUD/Sheet/SheetConfiguration.swift b/Sources/ProHUD/Sheet/SheetConfiguration.swift index c236644..22635d4 100644 --- a/Sources/ProHUD/Sheet/SheetConfiguration.swift +++ b/Sources/ProHUD/Sheet/SheetConfiguration.swift @@ -41,6 +41,8 @@ public extension Sheet { override var cardMaxWidthByDefault: CGFloat { cardMaxWidth ?? 500 } + override var cardMaxHeightByDefault: CGFloat { cardMaxHeight ?? (UIScreen.main.bounds.height - 50) } + override var titleFontByDefault: UIFont { titleFont ?? .systemFont(ofSize: 24, weight: .bold) }