From e64976bb080579b24ec07f7c9770455b09717406 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Fri, 4 Aug 2023 15:10:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E5=9B=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHDemo/PHDemo.xcodeproj/project.pbxproj | 31 ++++++++++++++++++- .../xcshareddata/swiftpm/Package.resolved | 23 -------------- PHDemo/PHDemo/ToastVC.swift | 6 ++++ Sources/ProHUD/Alert/AlertDefaultLayout.swift | 5 ++- .../ProHUD/Core/Models/Configuration.swift | 17 ++++++++++ Sources/ProHUD/Core/Models/ViewModel.swift | 7 +++++ Sources/ProHUD/Toast/ToastDefaultLayout.swift | 6 ++-- 7 files changed, 68 insertions(+), 27 deletions(-) delete mode 100644 PHDemo/PHDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved diff --git a/PHDemo/PHDemo.xcodeproj/project.pbxproj b/PHDemo/PHDemo.xcodeproj/project.pbxproj index d95d5aa..dc6ab2d 100644 --- a/PHDemo/PHDemo.xcodeproj/project.pbxproj +++ b/PHDemo/PHDemo.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 55; + objectVersion = 60; objects = { /* Begin PBXBuildFile section */ @@ -11,6 +11,8 @@ CD6537C128C35E1C00A5981B /* ListVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6537C028C35E1C00A5981B /* ListVC.swift */; }; CD6537C328C35E6200A5981B /* ToastVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6537C228C35E6200A5981B /* ToastVC.swift */; }; CD6537C528C35F2C00A5981B /* SheetVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD6537C428C35F2C00A5981B /* SheetVC.swift */; }; + CD6AE8A32A7CC1BA0044E53D /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = CD6AE8A22A7CC1BA0044E53D /* SnapKit */; }; + CD6AE8A62A7CC1C70044E53D /* Inspire in Frameworks */ = {isa = PBXBuildFile; productRef = CD6AE8A52A7CC1C70044E53D /* Inspire */; }; CD8EEF3B28BC5C7200E660EA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD8EEF3A28BC5C7200E660EA /* AppDelegate.swift */; }; CD8EEF3D28BC5C7200E660EA /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD8EEF3C28BC5C7200E660EA /* SceneDelegate.swift */; }; CD8EEF4228BC5C7200E660EA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD8EEF4028BC5C7200E660EA /* Main.storyboard */; }; @@ -45,7 +47,9 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + CD6AE8A62A7CC1C70044E53D /* Inspire in Frameworks */, CDB6A2A228BC5F4600DEC80D /* ProHUD in Frameworks */, + CD6AE8A32A7CC1BA0044E53D /* SnapKit in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -123,6 +127,8 @@ name = PHDemo; packageProductDependencies = ( CDB6A2A128BC5F4600DEC80D /* ProHUD */, + CD6AE8A22A7CC1BA0044E53D /* SnapKit */, + CD6AE8A52A7CC1C70044E53D /* Inspire */, ); productName = PHDemo; productReference = CD8EEF3728BC5C7200E660EA /* PHDemo.app */; @@ -152,6 +158,10 @@ Base, ); mainGroup = CD8EEF2E28BC5C7200E660EA; + packageReferences = ( + CD6AE8A12A7CC1BA0044E53D /* XCLocalSwiftPackageReference "../../SnapKit" */, + CD6AE8A42A7CC1C70044E53D /* XCLocalSwiftPackageReference "../../Inspire" */, + ); productRefGroup = CD8EEF3828BC5C7200E660EA /* Products */; projectDirPath = ""; projectRoot = ""; @@ -408,7 +418,26 @@ }; /* End XCConfigurationList section */ +/* Begin XCLocalSwiftPackageReference section */ + CD6AE8A12A7CC1BA0044E53D /* XCLocalSwiftPackageReference "../../SnapKit" */ = { + isa = XCLocalSwiftPackageReference; + relativePath = ../../SnapKit; + }; + CD6AE8A42A7CC1C70044E53D /* XCLocalSwiftPackageReference "../../Inspire" */ = { + isa = XCLocalSwiftPackageReference; + relativePath = ../../Inspire; + }; +/* End XCLocalSwiftPackageReference section */ + /* Begin XCSwiftPackageProductDependency section */ + CD6AE8A22A7CC1BA0044E53D /* SnapKit */ = { + isa = XCSwiftPackageProductDependency; + productName = SnapKit; + }; + CD6AE8A52A7CC1C70044E53D /* Inspire */ = { + isa = XCSwiftPackageProductDependency; + productName = Inspire; + }; CDB6A2A128BC5F4600DEC80D /* ProHUD */ = { isa = XCSwiftPackageProductDependency; productName = ProHUD; diff --git a/PHDemo/PHDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/PHDemo/PHDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved deleted file mode 100644 index 4a0a7cd..0000000 --- a/PHDemo/PHDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ /dev/null @@ -1,23 +0,0 @@ -{ - "pins" : [ - { - "identity" : "inspire", - "kind" : "remoteSourceControl", - "location" : "https://github.com/xaoxuu/Inspire.git", - "state" : { - "revision" : "10d5a17ee24c8a66da9a3971c62c1d161d2a4cd2", - "version" : "3.0.0" - } - }, - { - "identity" : "snapkit", - "kind" : "remoteSourceControl", - "location" : "https://github.com/SnapKit/SnapKit.git", - "state" : { - "revision" : "f222cbdf325885926566172f6f5f06af95473158", - "version" : "5.6.0" - } - } - ], - "version" : 2 -} diff --git a/PHDemo/PHDemo/ToastVC.swift b/PHDemo/PHDemo/ToastVC.swift index 99ab424..fc08bc0 100644 --- a/PHDemo/PHDemo/ToastVC.swift +++ b/PHDemo/PHDemo/ToastVC.swift @@ -46,6 +46,9 @@ class ToastVC: ListVC { mask.backgroundColor = .clear mask.effect = UIBlurEffect(style: .systemChromeMaterial) } +// config.customWebImage { imageView, imageURL in +// imageView.backgroundColor = .red +// } } list.add(title: "默认布局") { section in @@ -85,6 +88,9 @@ class ToastVC: ListVC { section.add(title: "图标 + 一段长文本") { Toast(.note.message(message)).push() } + section.add(title: "网络图标 + 一段文本") { + Toast(.message("这是网络图标").icon(.init(string: "https://xaoxuu.com/assets/xaoxuu/avatar/rect-256@2x.png"))).push() + } } list.add(title: "事件管理") { section in diff --git a/Sources/ProHUD/Alert/AlertDefaultLayout.swift b/Sources/ProHUD/Alert/AlertDefaultLayout.swift index 7424d7e..9e35489 100644 --- a/Sources/ProHUD/Alert/AlertDefaultLayout.swift +++ b/Sources/ProHUD/Alert/AlertDefaultLayout.swift @@ -141,8 +141,11 @@ extension Alert { // 移除进度 progressView?.removeFromSuperview() - if vm.icon != nil { + if vm.icon != nil || vm.iconURL != nil { imageView.image = vm.icon + if let iconURL = vm.iconURL { + config.customWebImage?(imageView, iconURL) + } if imageView.superview == nil { contentStack.insertArrangedSubview(imageView, at: 0) imageView.snp.remakeConstraints { (mk) in diff --git a/Sources/ProHUD/Core/Models/Configuration.swift b/Sources/ProHUD/Core/Models/Configuration.swift index 9a0b9fe..a071e65 100644 --- a/Sources/ProHUD/Core/Models/Configuration.swift +++ b/Sources/ProHUD/Core/Models/Configuration.swift @@ -180,6 +180,23 @@ public class Configuration: NSObject { // MARK: 自定义 + /// 网络图标 + var customWebImage: ((_ imageView: UIImageView, _ imageURL: URL) -> Void)? = { imgv, url in + DispatchQueue.global().async { + URLSession.shared.dataTask(with: .init(url: url)) { data, resp, err in + guard let data = data else { + return + } + DispatchQueue.main.async { + imgv.image = UIImage(data: data) + } + }.resume() + } + } + public func customWebImage(handler: @escaping (_ imageView: UIImageView, _ imageURL: URL) -> Void) { + customWebImage = handler + } + var customReloadData: ((_ vc: Controller) -> Bool)? /// 自定义刷新规则( ⚠️ 自定义此函数之后,整个容器将不再走默认布局规则,可实现完全自定义) diff --git a/Sources/ProHUD/Core/Models/ViewModel.swift b/Sources/ProHUD/Core/Models/ViewModel.swift index 6b2b2bb..474424f 100644 --- a/Sources/ProHUD/Core/Models/ViewModel.swift +++ b/Sources/ProHUD/Core/Models/ViewModel.swift @@ -12,6 +12,7 @@ open class ViewModel: NSObject { /// 图标 open var icon: UIImage? + var iconURL: URL? /// 图标旋转动画 open var rotation: Rotation? @@ -66,6 +67,12 @@ public extension ViewModel { return self } + func icon(_ imageURL: URL?) -> ViewModel { + self.iconURL = imageURL + return self + } + + func title(_ text: String?) -> ViewModel { self.title = text return self diff --git a/Sources/ProHUD/Toast/ToastDefaultLayout.swift b/Sources/ProHUD/Toast/ToastDefaultLayout.swift index 67ee65d..af5abf9 100644 --- a/Sources/ProHUD/Toast/ToastDefaultLayout.swift +++ b/Sources/ProHUD/Toast/ToastDefaultLayout.swift @@ -25,7 +25,7 @@ extension Toast: DefaultLayout { } return } - if vm.icon != nil { + if vm.icon != nil || vm.iconURL != nil { if imageView.superview == nil { infoStack.insertArrangedSubview(imageView, at: 0) imageView.snp.makeConstraints { make in @@ -70,7 +70,6 @@ extension Toast: DefaultLayout { bodyLabel.removeFromSuperview() } // 设置数据 - imageView.image = vm.icon titleLabel.text = vm.title bodyLabel.text = vm.message view.layoutIfNeeded() @@ -133,6 +132,9 @@ extension Toast { progressView?.removeFromSuperview() imageView.image = vm.icon + if let iconURL = vm.iconURL { + config.customWebImage?(imageView, iconURL) + } if let rotation = vm.rotation { startRotate(rotation) }