Merge branch 'feature/coding' into feature/doughnutchart_from_coding
This commit is contained in:
commit
48a8f4aba8
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -84,17 +84,19 @@ import UIKit
|
||||
}
|
||||
|
||||
open func setupConstraintsForViewWithButtons() {
|
||||
guard let viewForButtons = viewForButtons, let primaryButton = primaryButton, let secondaryButton = secondaryButton else {
|
||||
return
|
||||
}
|
||||
guard let viewForButtons = viewForButtons,
|
||||
let primaryButton = primaryButton,
|
||||
let secondaryButton = secondaryButton
|
||||
else { return }
|
||||
|
||||
viewForButtons.addSubview(primaryButton)
|
||||
viewForButtons.addSubview(secondaryButton)
|
||||
secondaryButton.widthAnchor.constraint(equalTo: primaryButton.widthAnchor, multiplier: 1).isActive = true
|
||||
secondaryButton.topAnchor.constraint(equalTo: viewForButtons.topAnchor).isActive = true
|
||||
primaryButton.topAnchor.constraint(equalTo: viewForButtons.topAnchor).isActive = true
|
||||
viewForButtons.bottomAnchor.constraint(equalTo: secondaryButton.bottomAnchor).isActive = true
|
||||
viewForButtons.bottomAnchor.constraint(equalTo: primaryButton.bottomAnchor).isActive = true
|
||||
NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[leftButton]-10-[rightButton]-0-|", options: NSLayoutConstraint.FormatOptions.alignAllCenterY, metrics: nil, views: ["leftButton": secondaryButton, "rightButton": primaryButton]))
|
||||
NSLayoutConstraint.constraintPinSubview(primaryButton, pinTop: true, pinBottom: true, pinLeft: true, pinRight: false)
|
||||
NSLayoutConstraint.constraintPinSubview(secondaryButton, pinTop: false, pinBottom: false, pinLeft: false, pinRight: true)
|
||||
let constraint = secondaryButton.leadingAnchor.constraint(equalTo: primaryButton.trailingAnchor, constant: 10)
|
||||
constraint.priority = UILayoutPriority(900)
|
||||
constraint.isActive = true
|
||||
}
|
||||
|
||||
func setupWithTwoButtons() {
|
||||
@ -107,7 +109,6 @@ import UIKit
|
||||
|
||||
pinView(toSuperView: viewForButtons)
|
||||
alignCenterHorizontal()
|
||||
|
||||
createPrimaryButton()
|
||||
createSecondaryButton()
|
||||
setupConstraintsForViewWithButtons()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user