Merge branch 'feature/more_inversion' into 'develop'

More inversion

See merge request BPHV_MIPS/mvm_core_ui!439
This commit is contained in:
Pfeil, Scott Robert 2020-05-27 10:02:08 -04:00
commit 3ec07412c2
22 changed files with 474 additions and 163 deletions

View File

@ -9,14 +9,13 @@
open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol {
//------------------------------------------------------ //------------------------------------------------------
// MARK: - Constants // MARK: - Constants
//------------------------------------------------------ //------------------------------------------------------
private let CARET_VIEW_HEIGHT: Float = 10.5 private let CARET_VIEW_HEIGHT: Float = 10.5
private let CARET_VIEW_WIDTH: Float = 6.5 private let CARET_VIEW_WIDTH: Float = 6.5
//------------------------------------------------------ //------------------------------------------------------
// MARK: - Properties // MARK: - Properties
//------------------------------------------------------ //------------------------------------------------------
@ -82,7 +81,7 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol {
setTitleColor(enabledColor, for: .normal) setTitleColor(enabledColor, for: .normal)
setTitleColor(disabledColor, for: .disabled) setTitleColor(disabledColor, for: .disabled)
if let rightCaretView = rightView as? CaretView { if let rightCaretView = rightView as? CaretView {
rightCaretView.enabledColor = enabledColor rightCaretView.enabledColor = enabledColor
rightCaretView.disabledColor = disabledColor rightCaretView.disabledColor = disabledColor
@ -123,7 +122,7 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol {
bottomAnchor.constraint(greaterThanOrEqualTo: caretView.bottomAnchor).isActive = true bottomAnchor.constraint(greaterThanOrEqualTo: caretView.bottomAnchor).isActive = true
contentHorizontalAlignment = .left contentHorizontalAlignment = .left
//set correct color after layout // Set correct color after layout
changeCaretColor() changeCaretColor()
} }
@ -135,6 +134,7 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol {
//------------------------------------------------------ //------------------------------------------------------
// MARK: - Atomization // MARK: - Atomization
//------------------------------------------------------ //------------------------------------------------------
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
guard let model = model as? CaretLinkModel else { return } guard let model = model as? CaretLinkModel else { return }
@ -143,10 +143,8 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol {
backgroundColor = color.uiColor backgroundColor = color.uiColor
} }
enabledColor = model.enabledColor.uiColor enabledColor = (model.inverted ? model.enabledColor_inverted : model.enabledColor).uiColor
if let color = model.disabledColor { disabledColor = (model.inverted ? model.disabledColor_inverted : model.disabledColor).uiColor
disabledColor = color.uiColor
}
isEnabled = model.enabled isEnabled = model.enabled
set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) set(with: model.action, delegateObject: delegateObject, additionalData: additionalData)

View File

@ -9,46 +9,86 @@
import Foundation import Foundation
import MVMCore import MVMCore
public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol { public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "caretLink" public static var identifier: String = "caretLink"
public var backgroundColor: Color? public var backgroundColor: Color?
public var title: String public var title: String
public var action: ActionModelProtocol public var action: ActionModelProtocol
public var enabledColor: Color = Color(uiColor: .black) public var enabledColor: Color = Color(uiColor: .mvmBlack)
public var disabledColor: Color? = Color(uiColor: .mvmCoolGray6) public var disabledColor: Color = Color(uiColor: .mvmCoolGray6)
public var enabledColor_inverted: Color = Color(uiColor: .mvmWhite)
public var disabledColor_inverted: Color = Color(uiColor: .mvmCoolGray10)
public var enabled = true public var enabled = true
public var inverted = false
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
public init(title: String, action: ActionModelProtocol) { public init(title: String, action: ActionModelProtocol) {
self.title = title self.title = title
self.action = action self.action = action
} }
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case backgroundColor case backgroundColor
case title case title
case action case action
case enabledColor_inverted
case disabledColor_inverted
case enabledColor case enabledColor
case disabledColor case disabledColor
case enabled case enabled
case inverted
case moleculeName case moleculeName
} }
//--------------------------------------------------
// MARK: - Codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
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)
if let enabledColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor_inverted) {
self.enabledColor_inverted = enabledColor_inverted
}
if let disabledColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor_inverted) {
self.disabledColor_inverted = disabledColor_inverted
}
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor) { if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor) {
enabledColor = color enabledColor = color
} }
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) { if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) {
disabledColor = color disabledColor = color
} }
if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
self.enabled = enabled self.enabled = enabled
} }
if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) {
self.inverted = inverted
}
action = try typeContainer.decodeModel(codingKey: .action) action = try typeContainer.decodeModel(codingKey: .action)
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
@ -58,5 +98,8 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol {
try container.encode(enabled, forKey: .enabledColor) try container.encode(enabled, forKey: .enabledColor)
try container.encodeIfPresent(disabledColor, forKey: .disabledColor) try container.encodeIfPresent(disabledColor, forKey: .disabledColor)
try container.encode(enabled, forKey: .enabled) try container.encode(enabled, forKey: .enabled)
try container.encode(enabledColor_inverted, forKey: .enabledColor_inverted)
try container.encode(disabledColor_inverted, forKey: .disabledColor_inverted)
try container.encode(inverted, forKey: .inverted)
} }
} }

View File

@ -25,7 +25,7 @@ open class ExternalLink: Link {
guard let model = model as? ExternalLinkModel else { return } guard let model = model as? ExternalLinkModel else { return }
exportImageView?.tintColor = model.enabledColor.uiColor exportImageView?.tintColor = titleColor(for: model.enabled ? .normal : .disabled)
} }
//-------------------------------------------------- //--------------------------------------------------

View File

@ -8,6 +8,7 @@
import UIKit import UIKit
open class ExternalLinkModel: LinkModel { open class ExternalLinkModel: LinkModel {
override open class var identifier: String { override open class var identifier: String {

View File

@ -37,9 +37,7 @@ import UIKit
} }
open override var intrinsicContentSize: CGSize { open override var intrinsicContentSize: CGSize {
guard let size = titleLabel?.intrinsicContentSize else { guard let size = titleLabel?.intrinsicContentSize else { return super.intrinsicContentSize }
return super.intrinsicContentSize
}
return CGSize(width: size.width, height: size.height + 2) 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]?) { public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.set(with: model, delegateObject, additionalData) super.set(with: model, delegateObject, additionalData)
guard let model = model as? LinkModel else { return } guard let model = model as? LinkModel else { return }
setTitle(model.title, for: .normal) setTitle(model.title, for: .normal)
setTitleColor(model.enabledColor.uiColor, for: .normal) setTitleColor((model.inverted ? model.enabledColor_inverted : model.enabledColor).uiColor, for: .normal)
setTitleColor(model.disabledColor.uiColor, for: .disabled) setTitleColor((model.inverted ? model.disabledColor_inverted : model.disabledColor).uiColor, for: .disabled)
isEnabled = model.enabled isEnabled = model.enabled
set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) set(with: model.action, delegateObject: delegateObject, additionalData: additionalData)
} }
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { 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) { open override func updateView(_ size: CGFloat) {
super.updateView(size) super.updateView(size)
DispatchQueue.main.async { [weak self] in DispatchQueue.main.async { [weak self] in
guard let self = self else { return } guard let self = self else { return }
var width = size 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() width = MVMCoreUIUtility.getWidth()
} }
self.titleLabel?.font = MFStyler.fontB2(forWidth: width) self.titleLabel?.font = MFStyler.fontB2(forWidth: width)
} }
} }

View File

@ -8,6 +8,7 @@
import UIKit import UIKit
open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol { open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Properties // MARK: - Properties
@ -22,7 +23,10 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol {
public var action: ActionModelProtocol public var action: ActionModelProtocol
public var enabled = true public var enabled = true
public var enabledColor = Color(uiColor: .mvmBlack) public var enabledColor = Color(uiColor: .mvmBlack)
public var enabledColor_inverted = Color(uiColor: .mvmWhite)
public var disabledColor = Color(uiColor: .mvmCoolGray6) public var disabledColor = Color(uiColor: .mvmCoolGray6)
public var disabledColor_inverted = Color(uiColor: .mvmCoolGray10)
public var inverted = false
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializer // MARK: - Initializer
@ -44,7 +48,10 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol {
case action case action
case enabled case enabled
case enabledColor case enabledColor
case enabledColor_inverted
case disabledColor case disabledColor
case disabledColor_inverted
case inverted
} }
//-------------------------------------------------- //--------------------------------------------------
@ -53,6 +60,7 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol {
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
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) 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) { if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
self.enabled = 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) { if let enabledColor = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor) {
disabledColor = color 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.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeModel(action, forKey: .action) try container.encodeModel(action, forKey: .action)
try container.encode(inverted, forKey: .inverted)
try container.encode(enabled, forKey: .enabled) try container.encode(enabled, forKey: .enabled)
try container.encode(enabledColor, forKey: .enabledColor) try container.encode(enabledColor, forKey: .enabledColor)
try container.encode(enabledColor_inverted, forKey: .enabledColor_inverted)
try container.encode(disabledColor, forKey: .disabledColor) try container.encode(disabledColor, forKey: .disabledColor)
try container.encode(disabledColor_inverted, forKey: .disabledColor_inverted)
} }
} }

View File

@ -97,7 +97,7 @@ import MVMCore
public var disabledCheckColor: UIColor = .mvmCoolGray3 public var disabledCheckColor: UIColor = .mvmCoolGray3
/// Color of the check mark. /// Color of the check mark.
public var checkColor: UIColor = .black { public var checkColor: UIColor = .mvmBlack {
didSet { didSet {
setShapeLayerStrokeColor(checkColor) setShapeLayerStrokeColor(checkColor)
} }
@ -111,7 +111,7 @@ import MVMCore
} }
/// border color of the Checkbox /// border color of the Checkbox
public var borderColor: UIColor = .black { public var borderColor: UIColor = .mvmBlack {
didSet { didSet {
layer.borderColor = borderColor.cgColor layer.borderColor = borderColor.cgColor
} }
@ -126,7 +126,7 @@ import MVMCore
didSet { didSet {
if !updateSelectionOnly { if !updateSelectionOnly {
layoutIfNeeded() layoutIfNeeded()
(model as? CheckboxModel)?.isChecked = isSelected (model as? CheckboxModel)?.checked = isSelected
shapeLayer?.removeAllAnimations() shapeLayer?.removeAllAnimations()
updateCheckboxUI(isSelected: isSelected, isAnimated: isAnimated) updateCheckboxUI(isSelected: isSelected, isAnimated: isAnimated)
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) _ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
@ -375,10 +375,10 @@ import MVMCore
shapeLayer?.removeFromSuperlayer() shapeLayer?.removeFromSuperlayer()
shapeLayer = nil shapeLayer = nil
backgroundColor = .clear backgroundColor = .clear
borderColor = .black borderColor = .mvmBlack
borderWidth = 1.0 borderWidth = 1
checkColor = .black checkColor = .mvmBlack
checkWidth = 2.0 checkWidth = 2
checkAndBypassAnimations(selected: false) checkAndBypassAnimations(selected: false)
} }
@ -393,32 +393,34 @@ import MVMCore
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.set(with: model, delegateObject, additionalData) super.set(with: model, delegateObject, additionalData)
guard let model = model as? CheckboxModel else { return }
self.delegateObject = delegateObject self.delegateObject = delegateObject
guard let model = model as? CheckboxModel else { return }
FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate) FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate)
if let fieldKey = model.fieldKey { if let fieldKey = model.fieldKey {
self.fieldKey = fieldKey self.fieldKey = fieldKey
} }
borderColor = model.borderColor.uiColor borderColor = (model.inverted ? model.invertedColor : model.borderColor).uiColor
borderWidth = model.borderWidth borderWidth = model.borderWidth
checkColor = model.checkColor.uiColor checkColor = (model.inverted ? model.invertedColor : model.checkColor).uiColor
unCheckedBackgroundColor = model.unCheckedBackgroundColor.uiColor unCheckedBackgroundColor = (model.inverted ? model.invertedBackgroundColor : model.unCheckedBackgroundColor).uiColor
checkedBackgroundColor = model.checkedBackgroundColor.uiColor checkedBackgroundColor = (model.inverted ? model.invertedBackgroundColor : model.checkedBackgroundColor).uiColor
disabledCheckColor = model.disabledCheckColor.uiColor disabledCheckColor = (model.inverted ? model.invertedColor : model.disabledCheckColor).uiColor
disabledBorderColor = model.disabledBorderColor.uiColor disabledBorderColor = (model.inverted ? model.invertedColor : model.disabledBorderColor).uiColor
disabledBackgroundColor = model.disabledBackgroundColor.uiColor disabledBackgroundColor = (model.inverted ? model.invertedColor : model.disabledBackgroundColor).uiColor
isAnimated = model.isAnimated isAnimated = model.animated
isRound = model.isRound isRound = model.round
if model.isChecked { if model.checked {
checkAndBypassAnimations(selected: model.isChecked) checkAndBypassAnimations(selected: model.checked)
} }
isEnabled = model.isEnabled isEnabled = model.enabled
if let action = model.action { if let action = model.action {
actionBlock = { actionBlock = {

View File

@ -8,6 +8,7 @@
import Foundation import Foundation
@objcMembers public class CheckboxModel: MoleculeModelProtocol, FormFieldProtocol { @objcMembers public class CheckboxModel: MoleculeModelProtocol, FormFieldProtocol {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Properties // MARK: - Properties
@ -15,20 +16,23 @@ import Foundation
public static var identifier: String = "checkbox" public static var identifier: String = "checkbox"
public var backgroundColor: Color? public var backgroundColor: Color?
public var isChecked: Bool = false public var checked: Bool = false
public var isEnabled: Bool = true public var enabled: Bool = true
public var isAnimated: Bool = true public var animated: Bool = true
public var isRound: Bool = false public var inverted: Bool = false
public var round: Bool = false
public var borderWidth: CGFloat = 1 public var borderWidth: CGFloat = 1
public var borderColor: Color = Color(uiColor: .black) public var borderColor: Color = Color(uiColor: .mvmBlack)
public var checkColor: Color = Color(uiColor: .black) public var checkColor: Color = Color(uiColor: .mvmBlack)
public var unCheckedBackgroundColor: Color = Color(uiColor: .clear) public var unCheckedBackgroundColor: Color = Color(uiColor: .clear)
public var checkedBackgroundColor: Color = Color(uiColor: .clear) public var checkedBackgroundColor: Color = Color(uiColor: .clear)
public var disabledBackgroundColor: Color = Color(uiColor: .clear) public var disabledBackgroundColor: Color = Color(uiColor: .clear)
public var disabledBorderColor: Color = Color(uiColor: .mvmCoolGray3) public var disabledBorderColor: Color = Color(uiColor: .mvmCoolGray3)
public var disabledCheckColor: 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 action: ActionModelProtocol?
public var fieldKey: String? public var fieldKey: String?
public var groupName: String = FormValidator.defaultGroupName public var groupName: String = FormValidator.defaultGroupName
public var baseValue: AnyHashable? public var baseValue: AnyHashable?
@ -39,13 +43,16 @@ import Foundation
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
case isChecked = "checked" case checked
case isEnabled = "enabled" case enabled
case isAnimated = "animated" case inverted
case isRound = "round" case animated
case round
case borderWidth case borderWidth
case borderColor case borderColor
case checkColor case checkColor
case invertedColor
case invertedBackgroundColor
case unCheckedBackgroundColor case unCheckedBackgroundColor
case checkedBackgroundColor case checkedBackgroundColor
case disabledBackgroundColor case disabledBackgroundColor
@ -56,12 +63,20 @@ import Foundation
case groupName case groupName
} }
//--------------------------------------------------
// MARK: - Methods
//--------------------------------------------------
public func formFieldValue() -> AnyHashable? { public func formFieldValue() -> AnyHashable? {
return isChecked return checked
} }
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
public init(isChecked: Bool = false) { public init(isChecked: Bool = false) {
self.isChecked = isChecked self.checked = isChecked
baseValue = isChecked baseValue = isChecked
} }
@ -71,22 +86,72 @@ import Foundation
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) 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) fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) { if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
self.groupName = groupName self.groupName = groupName
} }
@ -99,16 +164,19 @@ import Foundation
try container.encodeIfPresent(fieldKey, forKey: .fieldKey) try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
try container.encodeIfPresent(borderColor, forKey: .borderColor) try container.encodeIfPresent(borderColor, forKey: .borderColor)
try container.encode(borderWidth, forKey: .borderWidth) 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(checkColor, forKey: .checkColor)
try container.encodeIfPresent(invertedColor, forKey: .invertedColor)
try container.encodeIfPresent(invertedBackgroundColor, forKey: .invertedBackgroundColor)
try container.encodeIfPresent(unCheckedBackgroundColor, forKey: .unCheckedBackgroundColor) try container.encodeIfPresent(unCheckedBackgroundColor, forKey: .unCheckedBackgroundColor)
try container.encodeIfPresent(checkedBackgroundColor, forKey: .checkedBackgroundColor) try container.encodeIfPresent(checkedBackgroundColor, forKey: .checkedBackgroundColor)
try container.encodeIfPresent(disabledBorderColor, forKey: .disabledBorderColor) try container.encodeIfPresent(disabledBorderColor, forKey: .disabledBorderColor)
try container.encodeIfPresent(disabledBackgroundColor, forKey: .disabledBackgroundColor) try container.encodeIfPresent(disabledBackgroundColor, forKey: .disabledBackgroundColor)
try container.encodeIfPresent(disabledCheckColor, forKey: .disabledCheckColor) try container.encodeIfPresent(disabledCheckColor, forKey: .disabledCheckColor)
try container.encodeIfPresent(isAnimated, forKey: .isAnimated) try container.encodeIfPresent(animated, forKey: .animated)
try container.encodeIfPresent(isRound, forKey: .isRound) try container.encodeIfPresent(round, forKey: .round)
try container.encodeIfPresent(isEnabled, forKey: .isEnabled) try container.encodeIfPresent(enabled, forKey: .enabled)
try container.encodeModelIfPresent(action, forKey: .action) try container.encodeModelIfPresent(action, forKey: .action)
try container.encodeIfPresent(groupName, forKey: .groupName) try container.encodeIfPresent(groupName, forKey: .groupName)
} }

View File

@ -41,8 +41,17 @@ open class Arrow: View {
} }
open var color: UIColor { open var color: UIColor {
get { return arrowModel?.color.uiColor ?? .mvmBlack } get {
set { arrowModel?.color = Color(uiColor: newValue) } guard let model = arrowModel else { return .mvmBlack }
return model.inverted ? model.color_inverted.uiColor : model.color.uiColor
}
set {
if let model = arrowModel, model.inverted {
model.color_inverted = Color(uiColor: newValue)
} else {
arrowModel?.color = Color(uiColor: newValue)
}
}
} }
open var degrees: Float { open var degrees: Float {

View File

@ -22,11 +22,13 @@ open class ArrowModel: MoleculeModelProtocol {
public var backgroundColor: Color? public var backgroundColor: Color?
public var disabledColor: Color = Color(uiColor: .mvmCoolGray3) public var disabledColor: Color = Color(uiColor: .mvmCoolGray3)
public var color: Color = Color(uiColor: .mvmBlack) public var color: Color = Color(uiColor: .mvmBlack)
public var color_inverted: Color = Color(uiColor: .mvmWhite)
public var degrees: Float = 0 public var degrees: Float = 0
public var lineWidth: CGFloat = 1 public var lineWidth: CGFloat = 1
public var height: CGFloat = 12 public var height: CGFloat = 12
public var width: CGFloat = 12 public var width: CGFloat = 12
public var enabled: Bool = true public var enabled: Bool = true
public var inverted: Bool = false
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Enum // MARK: - Enum
@ -64,6 +66,7 @@ open class ArrowModel: MoleculeModelProtocol {
case height case height
case width case width
case enabled case enabled
case inverted
} }
//-------------------------------------------------- //--------------------------------------------------
@ -79,6 +82,10 @@ open class ArrowModel: MoleculeModelProtocol {
self.disabledColor = disabledColor self.disabledColor = disabledColor
} }
if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) {
self.inverted = inverted
}
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .color) { if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .color) {
self.color = color self.color = color
} }

View File

@ -13,14 +13,13 @@ open class CaretView: View {
//------------------------------------------------------ //------------------------------------------------------
private var caretPath: UIBezierPath = UIBezierPath() private var caretPath: UIBezierPath = UIBezierPath()
public var strokeColor: UIColor = .black
public var lineWidth: CGFloat = 1 public var lineWidth: CGFloat = 1
public var direction: Direction = .right public var direction: Direction = .right
public var size: CaretSize? public var size: CaretSize?
public var enabledColor: UIColor = .black public var enabledColor: UIColor = .mvmBlack
public var disabledColor: UIColor = .mfSilver() public var disabledColor: UIColor = .mvmCoolGray3
//------------------------------------------------------ //------------------------------------------------------
// MARK: - Property Observer // MARK: - Property Observer
@ -28,7 +27,7 @@ open class CaretView: View {
public var isEnabled: Bool = true { public var isEnabled: Bool = true {
didSet { didSet {
strokeColor = isEnabled ? enabledColor : disabledColor guard isEnabled != oldValue else { return }
setNeedsDisplay() setNeedsDisplay()
} }
} }
@ -49,7 +48,7 @@ open class CaretView: View {
case horizontal case horizontal
} }
// Dimensions of container; provided by InVision design. /// Dimensions of container; provided by InVision design.
func dimensions() -> CGSize { func dimensions() -> CGSize {
switch self { switch self {
@ -92,7 +91,7 @@ open class CaretView: View {
//------------------------------------------------------ //------------------------------------------------------
@objc override open func setupView() { @objc override open func setupView() {
super.setupView()
defaultState() defaultState()
} }
@ -141,7 +140,7 @@ open class CaretView: View {
caretPath.addLine(to: CGPoint(x: frame.size.width - inset, y: frame.size.height - inset)) caretPath.addLine(to: CGPoint(x: frame.size.width - inset, y: frame.size.height - inset))
} }
strokeColor.setStroke() enabledColor.setStroke()
caretPath.stroke() caretPath.stroke()
} }
@ -151,17 +150,16 @@ open class CaretView: View {
@objc public func setLineColor(_ color: UIColor) { @objc public func setLineColor(_ color: UIColor) {
strokeColor = color enabledColor = color
setNeedsDisplay() setNeedsDisplay()
} }
@objc public func defaultState() { @objc public func defaultState() {
translatesAutoresizingMaskIntoConstraints = false
isOpaque = false isOpaque = false
isHidden = false isHidden = false
backgroundColor = .clear backgroundColor = .clear
strokeColor = .black enabledColor = .mvmBlack
} }
/// Ensure you have defined a CaretSize with Orientation before calling. /// Ensure you have defined a CaretSize with Orientation before calling.
@ -177,8 +175,8 @@ open class CaretView: View {
// MARK: - Atomization // MARK: - Atomization
//------------------------------------------------------ //------------------------------------------------------
// Default values for view. /// Default values for view.
public required init(model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { public required init(model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.init(frame: .zero) super.init(frame: .zero)
defaultState() defaultState()
set(with: model, delegateObject, additionalData) set(with: model, delegateObject, additionalData)
@ -186,20 +184,21 @@ open class CaretView: View {
override public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { override public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.set(with: model, delegateObject, additionalData) super.set(with: model, delegateObject, additionalData)
guard let caretModel = model as? CaretViewModel else {
return guard let model = model as? CaretViewModel else { return }
}
strokeColor = caretModel.strokeColor.uiColor enabledColor = (model.inverted ? model.strokeColor_inverted : model.strokeColor).uiColor
isHidden = caretModel.isHidden ?? false isHidden = model.isHidden
isOpaque = caretModel.isOpaque ?? false isOpaque = model.isOpaque
if let lineWidthValue = caretModel.lineWidth { if let lineWidthValue = model.lineWidth {
lineWidth = lineWidthValue lineWidth = lineWidthValue
} }
} }
} }
extension CaretView: MVMCoreUIViewConstrainingProtocol { extension CaretView: MVMCoreUIViewConstrainingProtocol {
open func needsToBeConstrained() -> Bool { open func needsToBeConstrained() -> Bool {
return true return true
} }

View File

@ -8,32 +8,65 @@
import Foundation import Foundation
@objcMembers public class CaretViewModel: MoleculeModelProtocol {
@objcMembers public class CaretViewModel: MoleculeModelProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "caretView" public static var identifier: String = "caretView"
public var backgroundColor: Color? public var backgroundColor: Color?
public var strokeColor: Color = Color(uiColor: .black) public var strokeColor: Color = Color(uiColor: .mvmBlack)
public var isHidden: Bool? public var strokeColor_inverted: Color = Color(uiColor: .mvmWhite)
public var isOpaque: Bool? public var isHidden: Bool = false
public var isOpaque: Bool = false
public var inverted: Bool = false
public var lineWidth: CGFloat? public var lineWidth: CGFloat?
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
case backgroundColor case backgroundColor
case strokeColor case strokeColor
case strokeColor_inverted
case isHidden case isHidden
case isOpaque case isOpaque
case lineWidth case lineWidth
case inverted
} }
//--------------------------------------------------
// MARK: - Codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
if let strokeColor = try typeContainer.decodeIfPresent(Color.self, forKey: .strokeColor) { if let strokeColor = try typeContainer.decodeIfPresent(Color.self, forKey: .strokeColor) {
self.strokeColor = strokeColor self.strokeColor = strokeColor
} }
if let strokeColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .strokeColor_inverted) {
self.strokeColor_inverted = strokeColor_inverted
}
if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) {
self.inverted = inverted
}
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
isHidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .isHidden)
isOpaque = try typeContainer.decodeIfPresent(Bool.self, forKey: .isOpaque) if let isHidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .isHidden) {
self.isHidden = isHidden
}
if let isOpaque = try typeContainer.decodeIfPresent(Bool.self, forKey: .isOpaque) {
self.isOpaque = isOpaque
}
lineWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .lineWidth) lineWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .lineWidth)
} }
@ -41,6 +74,8 @@ import Foundation
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(strokeColor, forKey: .strokeColor) try container.encode(strokeColor, forKey: .strokeColor)
try container.encode(strokeColor_inverted, forKey: .strokeColor_inverted)
try container.encode(inverted, forKey: .inverted)
try container.encodeIfPresent(isHidden, forKey: .isHidden) try container.encodeIfPresent(isHidden, forKey: .isHidden)
try container.encodeIfPresent(isOpaque, forKey: .isOpaque) try container.encodeIfPresent(isOpaque, forKey: .isOpaque)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)

View File

@ -68,12 +68,7 @@ open class BarsIndicatorView: CarouselIndicator {
get { return super.indicatorColor } get { return super.indicatorColor }
set (newColor) { set (newColor) {
super.indicatorColor = newColor super.indicatorColor = newColor
refreshBarColors(with: newColor)
if isEnabled {
for (i, barTuple) in barReferences.enumerated() {
barTuple.view.backgroundColor = i == currentIndex ? currentIndicatorColor : newColor
}
}
} }
} }
@ -102,6 +97,15 @@ open class BarsIndicatorView: CarouselIndicator {
// MARK: - Methods // MARK: - Methods
//-------------------------------------------------- //--------------------------------------------------
private func refreshBarColors(with color: UIColor) {
if isEnabled {
for (i, barTuple) in barReferences.enumerated() {
barTuple.view.backgroundColor = i == currentIndex ? currentIndicatorColor : color
}
}
}
func generateBars() { func generateBars() {
var bars = [(View, NSLayoutConstraint)]() var bars = [(View, NSLayoutConstraint)]()
@ -142,7 +146,7 @@ open class BarsIndicatorView: CarouselIndicator {
guard let model = model as? BarsCarouselIndicatorModel else { return } guard let model = model as? BarsCarouselIndicatorModel else { return }
currentIndicatorColor = model.currentIndicatorColor.uiColor currentIndicatorColor = model.inverted ? model.indicatorColor_inverted.uiColor : model.currentIndicatorColor.uiColor
} }
//-------------------------------------------------- //--------------------------------------------------

View File

@ -78,8 +78,17 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
} }
public var indicatorColor: UIColor { public var indicatorColor: UIColor {
get { return carouselIndicatorModel?.indicatorColor.uiColor ?? .mvmBlack } get {
set { carouselIndicatorModel?.indicatorColor = Color(uiColor: newValue) } guard let model = carouselIndicatorModel else { return .mvmBlack }
return model.inverted ? model.indicatorColor_inverted.uiColor : model.indicatorColor.uiColor
}
set {
if let model = carouselIndicatorModel, model.inverted {
model.indicatorColor_inverted = Color(uiColor: newValue)
} else {
carouselIndicatorModel?.indicatorColor = Color(uiColor: newValue)
}
}
} }
var accessibilityValueFormat: String? { var accessibilityValueFormat: String? {
@ -191,7 +200,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
guard let model = model as? CarouselIndicatorModel else { return } guard let model = model as? CarouselIndicatorModel else { return }
indicatorColor = model.indicatorColor.uiColor indicatorColor = model.inverted ? model.indicatorColor_inverted.uiColor : model.indicatorColor.uiColor
disabledIndicatorColor = model.disabledIndicatorColor.uiColor disabledIndicatorColor = model.disabledIndicatorColor.uiColor
currentIndex = model.currentIndex currentIndex = model.currentIndex
isEnabled = model.enabled isEnabled = model.enabled

View File

@ -26,11 +26,13 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
public var currentIndex: Int = 0 public var currentIndex: Int = 0
public var animated: Bool = true public var animated: Bool = true
public var hidesForSinglePage: Bool = false public var hidesForSinglePage: Bool = false
public var inverted: Bool = false
/// Set true to make the accessibility value as "Slide #currentPage of #totalPage", otherwise will be "Page #currentPage of #totalPage", default is false /// Set true to make the accessibility value as "Slide #currentPage of #totalPage", otherwise will be "Page #currentPage of #totalPage", default is false
public var accessibilityHasSlidesInsteadOfPage: Bool = false public var accessibilityHasSlidesInsteadOfPage: Bool = false
public var enabled: Bool = true public var enabled: Bool = true
public var disabledIndicatorColor: Color = Color(uiColor: .mvmCoolGray3) public var disabledIndicatorColor: Color = Color(uiColor: .mvmCoolGray3)
public var indicatorColor: Color = Color(uiColor: .mvmBlack) public var indicatorColor: Color = Color(uiColor: .mvmBlack)
public var indicatorColor_inverted: Color = Color(uiColor: .mvmWhite)
public var position: Float? public var position: Float?
/// Allows sendActions() to trigger even if index is already at min/max index. /// Allows sendActions() to trigger even if index is already at min/max index.
@ -53,6 +55,7 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
case disabledIndicatorColor case disabledIndicatorColor
case indicatorColor case indicatorColor
case position case position
case inverted
} }
//-------------------------------------------------- //--------------------------------------------------
@ -72,6 +75,10 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
self.alwaysSendAction = alwaysSendAction self.alwaysSendAction = alwaysSendAction
} }
if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) {
self.inverted = inverted
}
if let position = try typeContainer.decodeIfPresent(Float.self, forKey: .position) { if let position = try typeContainer.decodeIfPresent(Float.self, forKey: .position) {
self.position = position self.position = position
} }
@ -112,6 +119,7 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
try container.encode(hidesForSinglePage, forKey: .hidesForSinglePage) try container.encode(hidesForSinglePage, forKey: .hidesForSinglePage)
try container.encode(accessibilityHasSlidesInsteadOfPage, forKey: .accessibilityHasSlidesInsteadOfPage) try container.encode(accessibilityHasSlidesInsteadOfPage, forKey: .accessibilityHasSlidesInsteadOfPage)
try container.encode(enabled, forKey: .enabled) try container.encode(enabled, forKey: .enabled)
try container.encode(inverted, forKey: .inverted)
try container.encode(disabledIndicatorColor, forKey: .disabledIndicatorColor) try container.encode(disabledIndicatorColor, forKey: .disabledIndicatorColor)
try container.encode(indicatorColor, forKey: .indicatorColor) try container.encode(indicatorColor, forKey: .indicatorColor)
try container.encodeIfPresent(position, forKey: .position) try container.encodeIfPresent(position, forKey: .position)

View File

@ -18,10 +18,10 @@ open class DashLine: View {
var dashModel: DashLineModel? { var dashModel: DashLineModel? {
get { return model as? DashLineModel } get { return model as? DashLineModel }
} }
//TODO: Need this for BAU. Can remove once we fix BAU //TODO: Need this for BAU. Can remove once we fix BAU
public var dashColor: UIColor? public var dashColor: UIColor?
@objc private var dashLayer: CAShapeLayer? @objc private var dashLayer: CAShapeLayer?
//------------------------------------------------------ //------------------------------------------------------
@ -65,15 +65,15 @@ open class DashLine: View {
path.addLine(to: CGPoint(x: dashLayer.frame.size.width, y: 0)) path.addLine(to: CGPoint(x: dashLayer.frame.size.width, y: 0))
path.stroke() path.stroke()
dashLayer.strokeStart = 0.0 dashLayer.strokeStart = 0
dashLayer.lineWidth = 1 dashLayer.lineWidth = 1
dashLayer.lineJoin = .miter dashLayer.lineJoin = .miter
dashLayer.lineCap = .round dashLayer.lineCap = .round
dashLayer.lineDashPattern = [NSNumber(value: 2), NSNumber(value: 2)] dashLayer.lineDashPattern = [NSNumber(value: 2), NSNumber(value: 2)]
dashLayer.path = path.cgPath dashLayer.path = path.cgPath
dashLayer.strokeColor = dashModel?.dashColor.cgColor ?? dashColor?.cgColor dashLayer.strokeColor = dashColor?.cgColor
dashLayer.fillColor = UIColor.clear.cgColor dashLayer.fillColor = UIColor.clear.cgColor
dashLayer.backgroundColor = backgroundColor?.cgColor ?? UIColor.white.cgColor dashLayer.backgroundColor = (dashModel?.inverted ?? false) ? UIColor.mvmBlack.cgColor : backgroundColor?.cgColor ?? UIColor.mvmWhite.cgColor
self.dashLayer = dashLayer self.dashLayer = dashLayer
} }
@ -81,21 +81,21 @@ open class DashLine: View {
// MARK: - Atomization // MARK: - Atomization
//------------------------------------------------------ //------------------------------------------------------
// Default values for view.
@objc open override func reset() { @objc open override func reset() {
backgroundColor = .clear super.reset()
isHidden = false isHidden = false
} }
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.set(with: model, delegateObject, additionalData) super.set(with: model, delegateObject, additionalData)
guard let dashLineModel = dashModel else {
return guard let model = dashModel else { return }
}
if let isHiddenValue = dashLineModel.isHidden { isHidden = model.isHidden
isHidden = isHiddenValue dashColor = (model.inverted ? model.dashColor_inverted : model.dashColor).uiColor
}
if let backgroundColor = dashLineModel.backgroundColor { if let backgroundColor = model.backgroundColor {
dashLayer?.backgroundColor = backgroundColor.uiColor.cgColor dashLayer?.backgroundColor = backgroundColor.uiColor.cgColor
} }
} }

View File

@ -8,38 +8,66 @@
import Foundation import Foundation
@objcMembers public class DashLineModel: MoleculeModelProtocol { @objcMembers public class DashLineModel: MoleculeModelProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "dashLine" public static var identifier: String = "dashLine"
public var backgroundColor: Color? public var backgroundColor: Color?
public var dashColor: Color = Color(uiColor: .mvmCoolGray3)
public var dashColor_inverted: Color = Color(uiColor: .mvmWhite)
public var isHidden: Bool = false
public var inverted: Bool = false
public var dashColor: Color = Color(uiColor: .mfLighterGray()) //--------------------------------------------------
public var isHidden: Bool? // MARK: - Initializer
//--------------------------------------------------
public init(dashColor: Color) { public init(dashColor: Color) {
self.dashColor = dashColor self.dashColor = dashColor
} }
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
case backgroundColor case backgroundColor
case dashColor_inverted
case dashColor case dashColor
case isHidden case isHidden
} }
//--------------------------------------------------
// MARK: - codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
if let dashColor = try typeContainer.decodeIfPresent(Color.self, forKey: .dashColor) { if let dashColor = try typeContainer.decodeIfPresent(Color.self, forKey: .dashColor) {
self.dashColor = dashColor self.dashColor = dashColor
} }
if let dashColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .dashColor_inverted) {
self.dashColor_inverted = dashColor_inverted
}
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
isHidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .isHidden)
if let isHidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .isHidden) {
self.isHidden = isHidden
}
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(dashColor, forKey: .dashColor) try container.encode(dashColor, forKey: .dashColor)
try container.encodeIfPresent(isHidden, forKey: .isHidden) try container.encode(isHidden, forKey: .isHidden)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
} }
} }

View File

@ -8,14 +8,27 @@
import UIKit import UIKit
@objcMembers open class Line: View { @objcMembers open class Line: View {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
var lineModel: LineModel? { var lineModel: LineModel? {
get { return model as? LineModel } get { return model as? LineModel }
} }
var lineBackgroundColor: Color? {
return (lineModel?.inverted ?? false) ? lineModel?.backgroundColor_inverted : lineModel?.backgroundColor
}
//--------------------------------------------------
// MARK: - Constraints
//--------------------------------------------------
public var heightConstraint: NSLayoutConstraint? public var heightConstraint: NSLayoutConstraint?
public var widthConstraint: NSLayoutConstraint? public var widthConstraint: NSLayoutConstraint?
open func updateLineConstraints(constant: CGFloat) { open func updateLineConstraints(constant: CGFloat) {
if let useVerticalLine = lineModel?.useVerticalLine, useVerticalLine { if let useVerticalLine = lineModel?.useVerticalLine, useVerticalLine {
heightConstraint?.isActive = false heightConstraint?.isActive = false
@ -28,7 +41,21 @@ import UIKit
} }
} }
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
public convenience init(pinTo view: UIView, edge: UIRectEdge, useMargin: Bool) {
self.init(frame: .zero)
addLine(to: view, edge: edge, useMargin: useMargin)
}
//--------------------------------------------------
// MARK: - Methods
//--------------------------------------------------
open func setStyle(_ style: LineModel.Style) { open func setStyle(_ style: LineModel.Style) {
switch style { switch style {
case .standard: case .standard:
updateLineConstraints(constant: 1) updateLineConstraints(constant: 1)
@ -47,25 +74,23 @@ import UIKit
} }
} }
// MARK: - Helpers
open func shouldBeVisible() -> Bool { open func shouldBeVisible() -> Bool {
guard let type = lineModel?.type else { return false } guard let type = lineModel?.type else { return false }
return type != .none return type != .none
} }
public convenience init(pinTo view: UIView, edge: UIRectEdge, useMargin: Bool) { //--------------------------------------------------
self.init(frame: .zero) // MARK: - MoleculeViewProtocol
addLine(to: view, edge: edge, useMargin: useMargin) //--------------------------------------------------
}
open func addLine(to view: UIView, edge: UIRectEdge, useMargin: Bool) { open func addLine(to view: UIView, edge: UIRectEdge, useMargin: Bool) {
view.addSubview(self) view.addSubview(self)
NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: self, useMargins: useMargin, pinTop: edge != .bottom, pinBottom: edge != .top, pinLeft: edge != .right, pinRight: edge != .left).values)) NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: self, useMargins: useMargin, pinTop: edge != .bottom, pinBottom: edge != .top, pinLeft: edge != .right, pinRight: edge != .left).values))
} }
// MARK: - MVMCoreViewProtocol
open override func setupView() { open override func setupView() {
super.setupView() super.setupView()
heightConstraint = heightAnchor.constraint(equalToConstant: 1) heightConstraint = heightAnchor.constraint(equalToConstant: 1)
heightConstraint?.isActive = true heightConstraint?.isActive = true
widthConstraint = widthAnchor.constraint(equalToConstant: 1) widthConstraint = widthAnchor.constraint(equalToConstant: 1)
@ -73,9 +98,9 @@ import UIKit
setStyle(.standard) setStyle(.standard)
} }
// MARK: - MoleculeViewProtocol
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.set(with: model, delegateObject, additionalData) super.set(with: model, delegateObject, additionalData)
if let lineModel = model as? LineModel { if let lineModel = model as? LineModel {
setStyle(lineModel.type) setStyle(lineModel.type)
} }
@ -86,7 +111,9 @@ import UIKit
} }
public override static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { public override static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
guard let type = (model as? LineModel)?.type else { return 1 } guard let type = (model as? LineModel)?.type else { return 1 }
switch type { switch type {
case .none: case .none:
return 0 return 0

View File

@ -8,15 +8,19 @@
import UIKit import UIKit
@objcMembers public class LineModel: MoleculeModelProtocol { @objcMembers public class LineModel: MoleculeModelProtocol {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
/* /**
The frequency of the line in a moleculeList. The frequency of the line in a moleculeList:
all (between all cells, above top, below bottom) - all (between all cells, above top, below bottom)
allExceptTop (between all cells, below bottom) - allExceptTop (between all cells, below bottom)
allExceptBottom (between all cells, above top) - allExceptBottom (between all cells, above top)
between (between all cells) - between (between all cells)
*/ */
public enum Frequency: String, Codable { public enum Frequency: String, Codable {
case all case all
case allExceptTop case allExceptTop
@ -24,14 +28,14 @@ import UIKit
case between case between
} }
/* /**
The style of the line. The style of the line:
standard (1 height, silver) - standard (1 height, silver)
thin (1 height, black) - thin (1 height, black)
medium (2 height, black) - medium (2 height, black)
heavy (4 height, black) - heavy (4 height, black)
none (hidden) - none (hidden)
*/ */
public enum Style: String, Codable { public enum Style: String, Codable {
case standard case standard
case thin case thin
@ -40,50 +44,83 @@ import UIKit
case none case none
} }
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "line" public static var identifier: String = "line"
public var type: Style = .standard public var type: Style = .standard
public var frequency: Frequency? = .allExceptTop public var frequency: Frequency? = .allExceptTop
//TODO: use color insted of backgroundColor. Needs server changes //TODO: use color insted of backgroundColor. Needs server changes
// public var color: Color? // public var color: Color?
public var backgroundColor: Color? public var backgroundColor: Color?
public var backgroundColor_inverted: Color = Color(uiColor: .mvmWhite)
public var inverted: Bool = false
// Use this to show vertical line // Use this to show vertical line
// Default is false // Default is false
public var useVerticalLine: Bool? public var useVerticalLine: Bool?
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
public init(type: Style) { public init(type: Style) {
self.type = type self.type = type
self.useVerticalLine = false self.useVerticalLine = false
} }
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
case type case type
case backgroundColor case backgroundColor
case backgroundColor_inverted
case color case color
case frequency case frequency
case inverted
case useVerticalLine case useVerticalLine
} }
//--------------------------------------------------
// MARK: - Codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
if let type = try typeContainer.decodeIfPresent(Style.self, forKey: .type) { if let type = try typeContainer.decodeIfPresent(Style.self, forKey: .type) {
self.type = type self.type = type
} }
if let frequency = try typeContainer.decodeIfPresent(Frequency.self, forKey: .frequency) { if let frequency = try typeContainer.decodeIfPresent(Frequency.self, forKey: .frequency) {
self.frequency = frequency self.frequency = frequency
} }
if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) {
self.inverted = inverted
}
if let backgroundColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor_inverted) {
self.backgroundColor_inverted = backgroundColor_inverted
}
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
useVerticalLine = try typeContainer.decodeIfPresent(Bool.self, forKey: .useVerticalLine) useVerticalLine = try typeContainer.decodeIfPresent(Bool.self, forKey: .useVerticalLine)
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(type, forKey: .type) try container.encode(type, forKey: .type)
try container.encode(inverted, forKey: .inverted)
try container.encodeIfPresent(frequency, forKey: .frequency) try container.encodeIfPresent(frequency, forKey: .frequency)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(backgroundColor_inverted, forKey: .backgroundColor_inverted)
try container.encodeIfPresent(useVerticalLine, forKey: .useVerticalLine) try container.encodeIfPresent(useVerticalLine, forKey: .useVerticalLine)
} }
} }

View File

@ -8,6 +8,7 @@
import UIKit import UIKit
@objcMembers public class RadioButtonLabel: View { @objcMembers public class RadioButtonLabel: View {
public let radioButton = RadioButton() public let radioButton = RadioButton()
@ -35,9 +36,6 @@ import UIKit
open override func setupView() { open override func setupView() {
super.setupView() super.setupView()
guard subviews.count == 0 else {
return
}
addSubview(radioButton) addSubview(radioButton)
radioButton.leftAnchor.constraint(equalTo: layoutMarginsGuide.leftAnchor, constant: 0).isActive = true radioButton.leftAnchor.constraint(equalTo: layoutMarginsGuide.leftAnchor, constant: 0).isActive = true
@ -72,5 +70,4 @@ import UIKit
radioButton.set(with: radioButtonLabelModel.radioButton, delegateObject, additionalData) radioButton.set(with: radioButtonLabelModel.radioButton, delegateObject, additionalData)
label.set(with: radioButtonLabelModel.label, delegateObject, additionalData) label.set(with: radioButtonLabelModel.label, delegateObject, additionalData)
} }
} }

View File

@ -8,7 +8,12 @@
import Foundation import Foundation
@objcMembers public class RadioButtonLabelModel: MoleculeModelProtocol { @objcMembers public class RadioButtonLabelModel: MoleculeModelProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "radioButtonLabel" public static var identifier: String = "radioButtonLabel"
public var backgroundColor: Color? public var backgroundColor: Color?
public var moleculeName: String public var moleculeName: String

View File

@ -34,6 +34,7 @@ extension UIColor {
"green33": (.mvmGreen33, "#ABE4BF"), "green33": (.mvmGreen33, "#ABE4BF"),
"green66": (.mvmGreen66, "#57C880"), "green66": (.mvmGreen66, "#57C880"),
"greenShade2": (.mvmGreenShade2, "#0F5B25"), "greenShade2": (.mvmGreenShade2, "#0F5B25"),
"greenInverted": (.mvmGreenInverted, "#00AC3E"),
"orange": (.mvmOrange, "#ED7000"), "orange": (.mvmOrange, "#ED7000"),
"orange66": (.mvmOrange66, "#F3A157"), "orange66": (.mvmOrange66, "#F3A157"),
"orange33": (.mvmOrange33, "#F9D0AB"), "orange33": (.mvmOrange33, "#F9D0AB"),
@ -45,6 +46,7 @@ extension UIColor {
"blue66": (.mvmBlue66, "#57B1DF"), "blue66": (.mvmBlue66, "#57B1DF"),
"blueShade1": (.mvmBlueShade1, "#136598"), "blueShade1": (.mvmBlueShade1, "#136598"),
"blueShade2": (.mvmBlueShade2, "#0B4467"), "blueShade2": (.mvmBlueShade2, "#0B4467"),
"blueInverted": (.mvmBlueInverted, "#0088CE"),
"yellow": (.mvmYellow, "#FFBC3D"), "yellow": (.mvmYellow, "#FFBC3D"),
"coolGray1": (.mvmCoolGray1, "#F6F6F6"), "coolGray1": (.mvmCoolGray1, "#F6F6F6"),
"coolGray3": (.mvmCoolGray3, "#D8DADA"), "coolGray3": (.mvmCoolGray3, "#D8DADA"),
@ -147,6 +149,9 @@ extension UIColor {
/// HEX: #0F5B25 /// HEX: #0F5B25
public static let mvmGreenShade2 = UIColor.color8Bits(red: 15, green: 91, blue: 37) public static let mvmGreenShade2 = UIColor.color8Bits(red: 15, green: 91, blue: 37)
/// HEX: #00AC3E
public static let mvmGreenInverted = UIColor.color8Bits(red: 0, green: 172, blue: 62)
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Blue // MARK: - Blue
//-------------------------------------------------- //--------------------------------------------------
@ -166,6 +171,9 @@ extension UIColor {
/// HEX: #0B4467 /// HEX: #0B4467
public static let mvmBlueShade2 = UIColor.color8Bits(red: 11, green: 68, blue: 103) public static let mvmBlueShade2 = UIColor.color8Bits(red: 11, green: 68, blue: 103)
/// HEX: #0088CE
public static let mvmBlueInverted = UIColor.color8Bits(red: 0, green: 136, blue: 206)
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Yellow // MARK: - Yellow
//-------------------------------------------------- //--------------------------------------------------