button fixes

This commit is contained in:
Suresh, Kamlesh 2020-01-16 17:32:00 -05:00
parent 4c656b54f1
commit 4dde423d2f
4 changed files with 20 additions and 2 deletions

View File

@ -25,6 +25,8 @@ public class ButtonModel: MoleculeProtocol {
public var action: ActionProtocol
public var style: ButtonStyle? = .primary
public var size: ButtonSize? = .standard
public var required: Bool?
public var requiredGroups: [String]?
init(with title: String, action: ActionProtocol) {
self.title = title
@ -37,6 +39,8 @@ public class ButtonModel: MoleculeProtocol {
case action
case style
case size
case required
case requiredGroups
}
required public init(from decoder: Decoder) throws {
@ -44,6 +48,8 @@ public class ButtonModel: MoleculeProtocol {
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
title = try typeContainer.decode(String.self, forKey: .title)
action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
required = try typeContainer.decodeIfPresent(Bool.self, forKey: .required)
requiredGroups = try typeContainer.decodeIfPresent([String].self, forKey: .requiredGroups)
if let style = try typeContainer.decodeIfPresent(ButtonStyle.self, forKey: .style) {
self.style = style
}
@ -59,5 +65,6 @@ public class ButtonModel: MoleculeProtocol {
try container.encodeModel(action, forKey: .action)
try container.encodeIfPresent(style, forKey: .style)
try container.encodeIfPresent(size, forKey: .size)
try container.encodeIfPresent(required, forKey: .required)
}
}

View File

@ -14,6 +14,16 @@ extension PrimaryButton: ModelMoleculeViewProtocol {
guard let model = model as? ButtonModel else { return }
setTitle(model.title, for: .normal)
backgroundColor = model.backgroundColor?.uiColor
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 style = model.style {
switch style {
case .primary:

View File

@ -46,6 +46,9 @@ static CGFloat const PrimaryButtonSmallHeight = 30.0;
// set YES to skip highlight method, for customer color button
@property (nonatomic) BOOL skipHighlighted;
@property (nonatomic) BOOL validationRequired;
@property (nullable, nonatomic, strong) NSArray *requiredGroupsList;
// The main creation functions, changed to black button for 2.0 for default
+ (nullable instancetype)primaryButton:(BOOL)enabled;
+ (nullable instancetype)primarySmallButton:(BOOL)enabled;

View File

@ -20,8 +20,6 @@
@interface PrimaryButton() <FormValidationEnableDisableProtocol>
@property (nonatomic) BOOL validationRequired;
@property (nonatomic, strong) NSArray *requiredGroupsList;
@property (nonatomic) BOOL smallButton;
@property (assign, nonatomic) BOOL tinyButton;
@property (nonatomic) CGFloat sizeForSizing;