支持设置网络图标

This commit is contained in:
xaoxuu 2023-08-04 15:10:58 +08:00
parent 8992349953
commit e64976bb08
7 changed files with 68 additions and 27 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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)?
///

View File

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

View File

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