diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/Link/ExternalLink.swift b/MVMCoreUI/Atomic/Atoms/Buttons/Link/ExternalLink.swift index c65698c3..e051cf32 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/Link/ExternalLink.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/Link/ExternalLink.swift @@ -25,7 +25,7 @@ open class ExternalLink: Link { guard let model = model as? ExternalLinkModel else { return } - exportImageView?.tintColor = model.enabledColor.uiColor + exportImageView?.tintColor = titleColor(for: model.enabled ? .normal : .disabled) } //-------------------------------------------------- diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/Link/ExternalLinkModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/Link/ExternalLinkModel.swift index f492a546..19d6643c 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/Link/ExternalLinkModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/Link/ExternalLinkModel.swift @@ -8,6 +8,7 @@ import UIKit + open class ExternalLinkModel: LinkModel { override open class var identifier: String { diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/Link/Link.swift b/MVMCoreUI/Atomic/Atoms/Buttons/Link/Link.swift index 5f5e6e12..7413fcbb 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/Link/Link.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/Link/Link.swift @@ -37,9 +37,7 @@ import UIKit } open override var intrinsicContentSize: CGSize { - guard let size = titleLabel?.intrinsicContentSize else { - return super.intrinsicContentSize - } + guard let size = titleLabel?.intrinsicContentSize else { return super.intrinsicContentSize } return CGSize(width: size.width, height: size.height + 2) } @@ -49,17 +47,18 @@ import UIKit public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) + guard let model = model as? LinkModel else { return } setTitle(model.title, for: .normal) - setTitleColor(model.enabledColor.uiColor, for: .normal) - setTitleColor(model.disabledColor.uiColor, for: .disabled) + setTitleColor((model.inverted ? model.enabledColor_inverted : model.enabledColor).uiColor, for: .normal) + setTitleColor((model.inverted ? model.disabledColor_inverted : model.disabledColor).uiColor, for: .disabled) isEnabled = model.enabled set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) } open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { - return 31.0 + return 31 } } @@ -68,12 +67,15 @@ extension Link { open override func updateView(_ size: CGFloat) { super.updateView(size) + DispatchQueue.main.async { [weak self] in guard let self = self else { return } + var width = size - if MVMCoreGetterUtility.fequal(a: Float(CGFloat.leastNormalMagnitude), b: Float(size)) { + if MVMCoreGetterUtility.fequal(a: Float.leastNormalMagnitude, b: Float(size)) { width = MVMCoreUIUtility.getWidth() } + self.titleLabel?.font = MFStyler.fontB2(forWidth: width) } } diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/Link/LinkModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/Link/LinkModel.swift index a54f23e9..d51bddf4 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/Link/LinkModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/Link/LinkModel.swift @@ -8,6 +8,7 @@ import UIKit + open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol { //-------------------------------------------------- // MARK: - Properties @@ -22,7 +23,10 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol { public var action: ActionModelProtocol public var enabled = true public var enabledColor = Color(uiColor: .mvmBlack) + public var enabledColor_inverted = Color(uiColor: .mvmWhite) public var disabledColor = Color(uiColor: .mvmCoolGray6) + public var disabledColor_inverted = Color(uiColor: .mvmCoolGray10) + public var inverted = false //-------------------------------------------------- // MARK: - Initializer @@ -44,7 +48,10 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol { case action case enabled case enabledColor + case enabledColor_inverted case disabledColor + case disabledColor_inverted + case inverted } //-------------------------------------------------- @@ -53,6 +60,7 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol { required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) title = try typeContainer.decode(String.self, forKey: .title) action = try typeContainer.decodeModel(codingKey: .action) @@ -60,12 +68,25 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol { if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { self.enabled = enabled } - if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor) { - enabledColor = color + + if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) { + self.inverted = inverted } - if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) { - disabledColor = color + if let enabledColor = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor) { + self.enabledColor = enabledColor + } + + if let enabledColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor_inverted) { + self.enabledColor_inverted = enabledColor_inverted + } + + if let disabledColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) { + self.disabledColor = disabledColor + } + + if let disabledColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor_inverted) { + self.disabledColor_inverted = disabledColor_inverted } } @@ -75,8 +96,11 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol { try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeModel(action, forKey: .action) + try container.encode(inverted, forKey: .inverted) try container.encode(enabled, forKey: .enabled) try container.encode(enabledColor, forKey: .enabledColor) + try container.encode(enabledColor_inverted, forKey: .enabledColor_inverted) try container.encode(disabledColor, forKey: .disabledColor) + try container.encode(disabledColor_inverted, forKey: .disabledColor_inverted) } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift index cb404f5a..cffbb916 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift @@ -97,7 +97,7 @@ import MVMCore public var disabledCheckColor: UIColor = .mvmCoolGray3 /// Color of the check mark. - public var checkColor: UIColor = .black { + public var checkColor: UIColor = .mvmBlack { didSet { setShapeLayerStrokeColor(checkColor) } @@ -111,7 +111,7 @@ import MVMCore } /// border color of the Checkbox - public var borderColor: UIColor = .black { + public var borderColor: UIColor = .mvmBlack { didSet { layer.borderColor = borderColor.cgColor } @@ -126,7 +126,7 @@ import MVMCore didSet { if !updateSelectionOnly { layoutIfNeeded() - (model as? CheckboxModel)?.isChecked = isSelected + (model as? CheckboxModel)?.checked = isSelected shapeLayer?.removeAllAnimations() updateCheckboxUI(isSelected: isSelected, isAnimated: isAnimated) _ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) @@ -375,10 +375,10 @@ import MVMCore shapeLayer?.removeFromSuperlayer() shapeLayer = nil backgroundColor = .clear - borderColor = .black - borderWidth = 1.0 - checkColor = .black - checkWidth = 2.0 + borderColor = .mvmBlack + borderWidth = 1 + checkColor = .mvmBlack + checkWidth = 2 checkAndBypassAnimations(selected: false) } @@ -393,32 +393,34 @@ import MVMCore public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) - guard let model = model as? CheckboxModel else { return } self.delegateObject = delegateObject + + guard let model = model as? CheckboxModel else { return } + FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate) if let fieldKey = model.fieldKey { self.fieldKey = fieldKey } - borderColor = model.borderColor.uiColor + borderColor = (model.inverted ? model.invertedColor : model.borderColor).uiColor borderWidth = model.borderWidth - checkColor = model.checkColor.uiColor - unCheckedBackgroundColor = model.unCheckedBackgroundColor.uiColor - checkedBackgroundColor = model.checkedBackgroundColor.uiColor - disabledCheckColor = model.disabledCheckColor.uiColor - disabledBorderColor = model.disabledBorderColor.uiColor - disabledBackgroundColor = model.disabledBackgroundColor.uiColor + checkColor = (model.inverted ? model.invertedColor : model.checkColor).uiColor + unCheckedBackgroundColor = (model.inverted ? model.invertedBackgroundColor : model.unCheckedBackgroundColor).uiColor + checkedBackgroundColor = (model.inverted ? model.invertedBackgroundColor : model.checkedBackgroundColor).uiColor + disabledCheckColor = (model.inverted ? model.invertedColor : model.disabledCheckColor).uiColor + disabledBorderColor = (model.inverted ? model.invertedColor : model.disabledBorderColor).uiColor + disabledBackgroundColor = (model.inverted ? model.invertedColor : model.disabledBackgroundColor).uiColor - isAnimated = model.isAnimated - isRound = model.isRound + isAnimated = model.animated + isRound = model.round - if model.isChecked { - checkAndBypassAnimations(selected: model.isChecked) + if model.checked { + checkAndBypassAnimations(selected: model.checked) } - isEnabled = model.isEnabled + isEnabled = model.enabled if let action = model.action { actionBlock = { diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/CheckboxModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/CheckboxModel.swift index 423ed1ee..43a08aa6 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/CheckboxModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/CheckboxModel.swift @@ -8,6 +8,7 @@ import Foundation + @objcMembers public class CheckboxModel: MoleculeModelProtocol, FormFieldProtocol { //-------------------------------------------------- // MARK: - Properties @@ -15,20 +16,23 @@ import Foundation public static var identifier: String = "checkbox" public var backgroundColor: Color? - public var isChecked: Bool = false - public var isEnabled: Bool = true - public var isAnimated: Bool = true - public var isRound: Bool = false + public var checked: Bool = false + public var enabled: Bool = true + public var animated: Bool = true + public var inverted: Bool = false + public var round: Bool = false public var borderWidth: CGFloat = 1 - public var borderColor: Color = Color(uiColor: .black) - public var checkColor: Color = Color(uiColor: .black) + public var borderColor: Color = Color(uiColor: .mvmBlack) + public var checkColor: Color = Color(uiColor: .mvmBlack) public var unCheckedBackgroundColor: Color = Color(uiColor: .clear) public var checkedBackgroundColor: Color = Color(uiColor: .clear) public var disabledBackgroundColor: Color = Color(uiColor: .clear) public var disabledBorderColor: Color = Color(uiColor: .mvmCoolGray3) public var disabledCheckColor: Color = Color(uiColor: .mvmCoolGray3) + public var invertedColor: Color = Color(uiColor: .mvmWhite) + public var invertedBackgroundColor: Color = Color(uiColor: .mvmBlack) public var action: ActionModelProtocol? - + public var fieldKey: String? public var groupName: String = FormValidator.defaultGroupName public var baseValue: AnyHashable? @@ -39,13 +43,16 @@ import Foundation private enum CodingKeys: String, CodingKey { case moleculeName - case isChecked = "checked" - case isEnabled = "enabled" - case isAnimated = "animated" - case isRound = "round" + case checked + case enabled + case inverted + case animated + case round case borderWidth case borderColor case checkColor + case invertedColor + case invertedBackgroundColor case unCheckedBackgroundColor case checkedBackgroundColor case disabledBackgroundColor @@ -56,12 +63,20 @@ import Foundation case groupName } + //-------------------------------------------------- + // MARK: - Methods + //-------------------------------------------------- + public func formFieldValue() -> AnyHashable? { - return isChecked + return checked } + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + public init(isChecked: Bool = false) { - self.isChecked = isChecked + self.checked = isChecked baseValue = isChecked } @@ -71,22 +86,72 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - borderWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .borderWidth) ?? 1 - borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) ?? Color(uiColor: .black) - checkColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkColor) ?? Color(uiColor: .black) - unCheckedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .unCheckedBackgroundColor) ?? Color(uiColor: .clear) - checkedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkedBackgroundColor) ?? Color(uiColor: .clear) - disabledBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledBackgroundColor) ?? Color(uiColor: .clear) - disabledBorderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledBorderColor) ?? Color(uiColor: .mvmCoolGray3) - disabledCheckColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledCheckColor) ?? Color(uiColor: .mvmCoolGray3) - isChecked = try typeContainer.decodeIfPresent(Bool.self, forKey: .isChecked) ?? false - isAnimated = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAnimated) ?? true - isRound = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRound) ?? false - isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .isEnabled) ?? true - action = try typeContainer.decodeModelIfPresent(codingKey: .action) - baseValue = isChecked + if let borderWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .borderWidth) { + self.borderWidth = borderWidth + } + + if let borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) { + self.borderColor = borderColor + } + + if let checkColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkColor) { + self.checkColor = checkColor + } + + if let unCheckedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .unCheckedBackgroundColor) { + self.unCheckedBackgroundColor = unCheckedBackgroundColor + } + + if let checkedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkedBackgroundColor) { + self.checkedBackgroundColor = checkedBackgroundColor + } + + if let disabledBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledBackgroundColor) { + self.disabledBackgroundColor = disabledBackgroundColor + } + + if let disabledBorderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledBorderColor) { + self.disabledBorderColor = disabledBorderColor + } + + if let disabledCheckColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledCheckColor) { + self.disabledCheckColor = disabledCheckColor + } + + if let invertedColor = try typeContainer.decodeIfPresent(Color.self, forKey: .invertedColor) { + self.invertedColor = invertedColor + } + + if let invertedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .invertedBackgroundColor) { + self.invertedBackgroundColor = invertedBackgroundColor + } + + if let checked = try typeContainer.decodeIfPresent(Bool.self, forKey: .checked) { + self.checked = checked + } + + baseValue = checked + + if let animated = try typeContainer.decodeIfPresent(Bool.self, forKey: .animated) { + self.animated = animated + } + + if let round = try typeContainer.decodeIfPresent(Bool.self, forKey: .round) { + self.round = round + } + + if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) { + self.inverted = inverted + } + + if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { + self.enabled = enabled + } + + action = try typeContainer.decodeModelIfPresent(codingKey: .action) fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey) + if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) { self.groupName = groupName } @@ -99,16 +164,19 @@ import Foundation try container.encodeIfPresent(fieldKey, forKey: .fieldKey) try container.encodeIfPresent(borderColor, forKey: .borderColor) try container.encode(borderWidth, forKey: .borderWidth) - try container.encode(isChecked, forKey: .isChecked) + try container.encode(checked, forKey: .checked) + try container.encode(inverted, forKey: .inverted) try container.encodeIfPresent(checkColor, forKey: .checkColor) + try container.encodeIfPresent(invertedColor, forKey: .invertedColor) + try container.encodeIfPresent(invertedBackgroundColor, forKey: .invertedBackgroundColor) try container.encodeIfPresent(unCheckedBackgroundColor, forKey: .unCheckedBackgroundColor) try container.encodeIfPresent(checkedBackgroundColor, forKey: .checkedBackgroundColor) try container.encodeIfPresent(disabledBorderColor, forKey: .disabledBorderColor) try container.encodeIfPresent(disabledBackgroundColor, forKey: .disabledBackgroundColor) try container.encodeIfPresent(disabledCheckColor, forKey: .disabledCheckColor) - try container.encodeIfPresent(isAnimated, forKey: .isAnimated) - try container.encodeIfPresent(isRound, forKey: .isRound) - try container.encodeIfPresent(isEnabled, forKey: .isEnabled) + try container.encodeIfPresent(animated, forKey: .animated) + try container.encodeIfPresent(round, forKey: .round) + try container.encodeIfPresent(enabled, forKey: .enabled) try container.encodeModelIfPresent(action, forKey: .action) try container.encodeIfPresent(groupName, forKey: .groupName) } diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/RadioButtonLabel.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/RadioButtonLabel.swift index 91034095..d415971e 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/RadioButtonLabel.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/RadioButtonLabel.swift @@ -8,6 +8,7 @@ import UIKit + @objcMembers public class RadioButtonLabel: View { public let radioButton = RadioButton() @@ -35,9 +36,6 @@ import UIKit open override func setupView() { super.setupView() - guard subviews.count == 0 else { - return - } addSubview(radioButton) radioButton.leftAnchor.constraint(equalTo: layoutMarginsGuide.leftAnchor, constant: 0).isActive = true @@ -72,5 +70,4 @@ import UIKit radioButton.set(with: radioButtonLabelModel.radioButton, delegateObject, additionalData) label.set(with: radioButtonLabelModel.label, delegateObject, additionalData) } - } diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/RadioButtonLabelModel.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/RadioButtonLabelModel.swift index 62df9794..014030ce 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/RadioButtonLabelModel.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/RadioButtonLabelModel.swift @@ -8,7 +8,12 @@ import Foundation + @objcMembers public class RadioButtonLabelModel: MoleculeModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "radioButtonLabel" public var backgroundColor: Color? public var moleculeName: String