updated to use combine

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-02-14 08:46:44 -06:00
parent fdc2628b19
commit fdabe5eb86

View File

@ -13,7 +13,7 @@ import VDS
/**
This class expects its height and width to be equal.
*/
open class Tilelet: VDS.Tilelet, VDSMoleculeViewProtocol {
open class Tilelet: VDS.Tilelet, VDSMoleculeViewProtocol{
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
@ -21,32 +21,33 @@ open class Tilelet: VDS.Tilelet, VDSMoleculeViewProtocol {
public var delegateObject: MVMCoreUIDelegateObject?
public var additionalData: [AnyHashable: Any]?
public var tapAction: ActionBlock?
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
public convenience required init() {
self.init(frame: .zero)
}
open func updateView(_ size: CGFloat) {}
open override func initialSetup() {
super.initialSetup()
publisher(for: .touchUpInside)
.sink {[weak self] control in
self?.executeAction()
}.store(in: &subscribers)
}
//--------------------------------------------------
// MARK: - Actions
// MARK: - Private
//--------------------------------------------------
open override func sendAction(_ action: Selector, to target: Any?, for event: UIEvent?) {
super.sendAction(action, to: target, for: event)
tapAction?()
}
open override func sendActions(for controlEvents: UIControl.Event) {
super.sendActions(for: controlEvents)
tapAction?()
private func executeAction(){
if let action = viewModel.action {
MVMCoreUIActionHandler.performActionUnstructured(with: action, sourceModel: viewModel, additionalData: additionalData, delegateObject: delegateObject)
}
}
//--------------------------------------------------
// MARK: - Public
//--------------------------------------------------
public func viewModelDidUpdate() {
color = viewModel.color
padding = viewModel.padding
@ -59,23 +60,29 @@ open class Tilelet: VDS.Tilelet, VDSMoleculeViewProtocol {
badgeModel = viewModel.badge
descriptiveIconModel = viewModel.descriptiveIcon
directionalIconModel = viewModel.directionalIcon
if let action = viewModel.action {
tapAction = { [weak self] in
guard let self = self else { return }
MVMCoreUIActionHandler.performActionUnstructured(with: action, sourceModel: self.viewModel, additionalData: self.additionalData, delegateObject: self.delegateObject)
}
}
}
//--------------------------------------------------
// MARK: - MVMCoreViewProtocol
//--------------------------------------------------
open func updateView(_ size: CGFloat) {}
//--------------------------------------------------
// MARK: - MoleculeViewProtocol
//--------------------------------------------------
//since this is a class func, we can't reference it directly
public static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
100
}
//--------------------------------------------------
// MARK: - Touch Event
// MARK: - Overrides
//--------------------------------------------------
public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
sendActions(for: .touchUpInside)
open override func layoutSubviews() {
super.layoutSubviews()
// Accounts for any collection size changes
DispatchQueue.main.async {
self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
}
}
}