ProHUD/Sources/ProHUD/Alert/AlertTarget.swift

115 lines
2.7 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Alert.swift
//
//
// Created by xaoxuu on 2022/8/29.
//
import UIKit
open class AlertTarget: BaseController, HUDTargetType {
public typealias ViewModel = AlertViewModel
public lazy var config = AlertConfiguration()
public var progressView: ProgressView?
/// icontextStackactionStack)
public lazy var contentStack: StackView = {
let stack = StackView(axis: .vertical)
stack.spacing = 24
stack.alignment = .center
config.customContentStack?(stack)
return stack
}()
///
public lazy var textStack: StackView = {
let stack = StackView(axis: .vertical)
stack.spacing = 8
stack.alignment = .center
config.customTextStack?(stack)
return stack
}()
///
public lazy var imageView: UIImageView = {
let imgv = UIImageView()
imgv.contentMode = .scaleAspectFit
imgv.tintColor = view.tintColor
return imgv
}()
///
public lazy var titleLabel: UILabel = {
let lb = UILabel()
lb.textColor = config.primaryLabelColor
lb.font = .boldSystemFont(ofSize: 20)
lb.textAlignment = .left
lb.numberOfLines = 5
return lb
}()
///
public lazy var bodyLabel: UILabel = {
let lb = UILabel()
lb.textColor = config.primaryLabelColor
lb.font = .systemFont(ofSize: 17)
lb.textAlignment = .left
lb.numberOfLines = 20
return lb
}()
///
public lazy var actionStack: StackView = {
let stack = StackView()
stack.alignment = .fill
stack.distribution = .fillEqually
stack.spacing = 8
config.customActionStack?(stack)
return stack
}()
///
@objc public var vm: AlertViewModel? {
didSet {
vm?.vc = self
}
}
public override var title: String? {
didSet {
if let vm = vm {
vm.title = title
} else {
vm = .title(title)
}
}
}
required public override init() {
super.init()
}
required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public convenience init(_ vm: ViewModel) {
self.init()
self.vm = vm
}
public override func viewDidLoad() {
super.viewDidLoad()
reloadData(animated: false)
navEvents[.onViewDidLoad]?(self)
}
}
// MARK:
extension AlertTarget: LoadingAnimation {}