Updates to Button

This commit is contained in:
Scott Pfeil 2023-09-14 14:14:30 -04:00
parent 8e35e8036a
commit 741bf0501b

View File

@ -18,12 +18,12 @@ open class PillButton: VDS.Button, MVMCoreUIViewConstrainingProtocol, MoleculeVi
// MARK: - Properties // MARK: - Properties
//-------------------------------------------------- //--------------------------------------------------
var model: MoleculeModelProtocol? open var model: MoleculeModelProtocol?
var buttonModel: ButtonModel? { public var buttonModel: ButtonModel? {
get { model as? ButtonModel } get { model as? ButtonModel }
} }
var onClickCancellable: Cancellable? internal var onClickCancellable: Cancellable?
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializers // MARK: - Initializers
@ -58,14 +58,14 @@ open class PillButton: VDS.Button, MVMCoreUIViewConstrainingProtocol, MoleculeVi
} }
/// The primary styling for a button. Should be used for main buttons /// The primary styling for a button. Should be used for main buttons
public func stylePrimary() { open func stylePrimary() {
let buttonModel = ButtonModel(primaryButtonWith: "", action: ActionNoopModel()) model = ButtonModel(primaryButtonWith: "", action: ActionNoopModel())
use = .primary use = .primary
} }
/// The secondary styling for a button. Should be used for secondary buttons /// The secondary styling for a button. Should be used for secondary buttons
public func styleSecondary() { open func styleSecondary() {
let buttonModel = ButtonModel(secondaryButtonWith: "", action: ActionNoopModel()) model = ButtonModel(secondaryButtonWith: "", action: ActionNoopModel())
use = .secondary use = .secondary
} }
@ -81,26 +81,25 @@ open class PillButton: VDS.Button, MVMCoreUIViewConstrainingProtocol, MoleculeVi
self.accessibilityIdentifier = accessibilityIdentifier self.accessibilityIdentifier = accessibilityIdentifier
} }
setTitle(model.title, for: .normal) text = model.title
if let accessibilityText = model.accessibilityText {
accessibilityLabel = accessibilityText
}
isEnabled = model.enabled isEnabled = model.enabled
size = model.size size = model.size
// if let backgroundColor = model.backgroundColor { // if let backgroundColor = model.backgroundColor {
// self.backgroundColor = backgroundColor.uiColor // self.backgroundColor = backgroundColor.uiColor
// } // }
if let accessibilityText = model.accessibilityText {
accessibilityLabel = accessibilityText
}
FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate)
set(with: model.action, delegateObject: delegateObject, additionalData: additionalData)
model.updateUI = { [weak self] in model.updateUI = { [weak self] in
MVMCoreDispatchUtility.performBlock(onMainThread: { MVMCoreDispatchUtility.performBlock(onMainThread: {
self?.isEnabled = model.enabled self?.isEnabled = model.enabled
}) })
} }
FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate)
set(with: model.action, delegateObject: delegateObject, additionalData: additionalData)
} }
//-------------------------------------------------- //--------------------------------------------------