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 action: ActionProtocol
|
||||||
public var style: ButtonStyle? = .primary
|
public var style: ButtonStyle? = .primary
|
||||||
public var size: ButtonSize? = .standard
|
public var size: ButtonSize? = .standard
|
||||||
|
public var required: Bool?
|
||||||
|
public var requiredGroups: [String]?
|
||||||
|
|
||||||
init(with title: String, action: ActionProtocol) {
|
init(with title: String, action: ActionProtocol) {
|
||||||
self.title = title
|
self.title = title
|
||||||
@ -37,6 +39,8 @@ public class ButtonModel: MoleculeProtocol {
|
|||||||
case action
|
case action
|
||||||
case style
|
case style
|
||||||
case size
|
case size
|
||||||
|
case required
|
||||||
|
case requiredGroups
|
||||||
}
|
}
|
||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
@ -44,6 +48,8 @@ public class ButtonModel: MoleculeProtocol {
|
|||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
title = try typeContainer.decode(String.self, forKey: .title)
|
title = try typeContainer.decode(String.self, forKey: .title)
|
||||||
action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
|
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) {
|
if let style = try typeContainer.decodeIfPresent(ButtonStyle.self, forKey: .style) {
|
||||||
self.style = style
|
self.style = style
|
||||||
}
|
}
|
||||||
@ -59,5 +65,6 @@ public class ButtonModel: MoleculeProtocol {
|
|||||||
try container.encodeModel(action, forKey: .action)
|
try container.encodeModel(action, forKey: .action)
|
||||||
try container.encodeIfPresent(style, forKey: .style)
|
try container.encodeIfPresent(style, forKey: .style)
|
||||||
try container.encodeIfPresent(size, forKey: .size)
|
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 }
|
guard let model = model as? ButtonModel else { return }
|
||||||
setTitle(model.title, for: .normal)
|
setTitle(model.title, for: .normal)
|
||||||
backgroundColor = model.backgroundColor?.uiColor
|
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 {
|
if let style = model.style {
|
||||||
switch style {
|
switch style {
|
||||||
case .primary:
|
case .primary:
|
||||||
|
|||||||
@ -46,6 +46,9 @@ static CGFloat const PrimaryButtonSmallHeight = 30.0;
|
|||||||
// set YES to skip highlight method, for customer color button
|
// set YES to skip highlight method, for customer color button
|
||||||
@property (nonatomic) BOOL skipHighlighted;
|
@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
|
// The main creation functions, changed to black button for 2.0 for default
|
||||||
+ (nullable instancetype)primaryButton:(BOOL)enabled;
|
+ (nullable instancetype)primaryButton:(BOOL)enabled;
|
||||||
+ (nullable instancetype)primarySmallButton:(BOOL)enabled;
|
+ (nullable instancetype)primarySmallButton:(BOOL)enabled;
|
||||||
|
|||||||
@ -20,8 +20,6 @@
|
|||||||
|
|
||||||
@interface PrimaryButton() <FormValidationEnableDisableProtocol>
|
@interface PrimaryButton() <FormValidationEnableDisableProtocol>
|
||||||
|
|
||||||
@property (nonatomic) BOOL validationRequired;
|
|
||||||
@property (nonatomic, strong) NSArray *requiredGroupsList;
|
|
||||||
@property (nonatomic) BOOL smallButton;
|
@property (nonatomic) BOOL smallButton;
|
||||||
@property (assign, nonatomic) BOOL tinyButton;
|
@property (assign, nonatomic) BOOL tinyButton;
|
||||||
@property (nonatomic) CGFloat sizeForSizing;
|
@property (nonatomic) CGFloat sizeForSizing;
|
||||||
|
|||||||
@ -84,17 +84,19 @@ import UIKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
open func setupConstraintsForViewWithButtons() {
|
open func setupConstraintsForViewWithButtons() {
|
||||||
guard let viewForButtons = viewForButtons, let primaryButton = primaryButton, let secondaryButton = secondaryButton else {
|
guard let viewForButtons = viewForButtons,
|
||||||
return
|
let primaryButton = primaryButton,
|
||||||
}
|
let secondaryButton = secondaryButton
|
||||||
|
else { return }
|
||||||
|
|
||||||
viewForButtons.addSubview(primaryButton)
|
viewForButtons.addSubview(primaryButton)
|
||||||
viewForButtons.addSubview(secondaryButton)
|
viewForButtons.addSubview(secondaryButton)
|
||||||
secondaryButton.widthAnchor.constraint(equalTo: primaryButton.widthAnchor, multiplier: 1).isActive = true
|
secondaryButton.widthAnchor.constraint(equalTo: primaryButton.widthAnchor, multiplier: 1).isActive = true
|
||||||
secondaryButton.topAnchor.constraint(equalTo: viewForButtons.topAnchor).isActive = true
|
NSLayoutConstraint.constraintPinSubview(primaryButton, pinTop: true, pinBottom: true, pinLeft: true, pinRight: false)
|
||||||
primaryButton.topAnchor.constraint(equalTo: viewForButtons.topAnchor).isActive = true
|
NSLayoutConstraint.constraintPinSubview(secondaryButton, pinTop: false, pinBottom: false, pinLeft: false, pinRight: true)
|
||||||
viewForButtons.bottomAnchor.constraint(equalTo: secondaryButton.bottomAnchor).isActive = true
|
let constraint = secondaryButton.leadingAnchor.constraint(equalTo: primaryButton.trailingAnchor, constant: 10)
|
||||||
viewForButtons.bottomAnchor.constraint(equalTo: primaryButton.bottomAnchor).isActive = true
|
constraint.priority = UILayoutPriority(900)
|
||||||
NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[leftButton]-10-[rightButton]-0-|", options: NSLayoutConstraint.FormatOptions.alignAllCenterY, metrics: nil, views: ["leftButton": secondaryButton, "rightButton": primaryButton]))
|
constraint.isActive = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupWithTwoButtons() {
|
func setupWithTwoButtons() {
|
||||||
@ -107,7 +109,6 @@ import UIKit
|
|||||||
|
|
||||||
pinView(toSuperView: viewForButtons)
|
pinView(toSuperView: viewForButtons)
|
||||||
alignCenterHorizontal()
|
alignCenterHorizontal()
|
||||||
|
|
||||||
createPrimaryButton()
|
createPrimaryButton()
|
||||||
createSecondaryButton()
|
createSecondaryButton()
|
||||||
setupConstraintsForViewWithButtons()
|
setupConstraintsForViewWithButtons()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user