swift button

This commit is contained in:
Pfeil, Scott Robert 2020-01-28 14:04:56 -05:00
parent c0ca81c568
commit 2ebce1b93b

View File

@ -8,12 +8,15 @@
import UIKit
open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
open class PillButton: Button, MVMCoreUIViewConstrainingProtocol, FormValidationEnableDisableProtocol {
// Used to size the button.
var size = MVMCoreUIUtility.getWidth()
var buttonModel: ButtonModel? {
get { return model as? ButtonModel }
}
// Need to re-style on set.
open override var isEnabled: Bool {
didSet {
style()
@ -25,6 +28,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
case standard = 42
}
/// The primary styling for a button. Should be used for main buttons
public func stylePrimary() {
setTitleColor(.white, for: .normal)
setTitleColor(.white, for: .disabled)
@ -36,6 +40,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
}
}
/// The secondary styling for a button. Should be used for secondary buttons
public func styleSecondary() {
setTitleColor(.black, for: .normal)
setTitleColor(.mvmCoolGray6, for: .disabled)
@ -48,6 +53,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
}
}
/// Styles the button based on the model style
private func style() {
switch buttonModel?.style {
case .secondary:
@ -97,13 +103,10 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
guard let model = model as? ButtonModel else { return }
setTitle(model.title, for: .normal)
/*self.validationRequired = model.required ?? false
self.requiredGroupsList = model.requiredGroups
if self.validationRequired,
let selfForm = self as? FormValidationEnableDisableProtocol {
FormValidator.setupValidation(molecule: selfForm, delegate: delegateObject?.formValidationProtocol)
}*/
if let required = model.required,
required == true {
FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol)
}
}
open override class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
@ -137,4 +140,17 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
open func horizontalAlignment() -> UIStackView.Alignment {
return .center
}
// MARK: - FormValidationEnableDisableProtocol
public func isValidationRequired() -> Bool {
return buttonModel?.required ?? false
}
public func requiredGroups() -> [String]? {
return buttonModel?.requiredGroups
}
public func enableField(_ enable: Bool) {
isEnabled = isValidationRequired() ? enable : true
}
}