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