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

View File

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

View File

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

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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 = {

View File

@ -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)
}

View File

@ -41,8 +41,17 @@ open class Arrow: View {
}
open var color: UIColor {
get { return arrowModel?.color.uiColor ?? .mvmBlack }
set { arrowModel?.color = Color(uiColor: newValue) }
get {
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 {

View File

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

View File

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

View File

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

View File

@ -68,12 +68,7 @@ open class BarsIndicatorView: CarouselIndicator {
get { return super.indicatorColor }
set (newColor) {
super.indicatorColor = newColor
if isEnabled {
for (i, barTuple) in barReferences.enumerated() {
barTuple.view.backgroundColor = i == currentIndex ? currentIndicatorColor : newColor
}
}
refreshBarColors(with: newColor)
}
}
@ -102,6 +97,15 @@ open class BarsIndicatorView: CarouselIndicator {
// 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() {
var bars = [(View, NSLayoutConstraint)]()
@ -142,7 +146,7 @@ open class BarsIndicatorView: CarouselIndicator {
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 {
get { return carouselIndicatorModel?.indicatorColor.uiColor ?? .mvmBlack }
set { carouselIndicatorModel?.indicatorColor = Color(uiColor: newValue) }
get {
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? {
@ -191,7 +200,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
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
currentIndex = model.currentIndex
isEnabled = model.enabled

View File

@ -26,11 +26,13 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
public var currentIndex: Int = 0
public var animated: Bool = true
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
public var accessibilityHasSlidesInsteadOfPage: Bool = false
public var enabled: Bool = true
public var disabledIndicatorColor: Color = Color(uiColor: .mvmCoolGray3)
public var indicatorColor: Color = Color(uiColor: .mvmBlack)
public var indicatorColor_inverted: Color = Color(uiColor: .mvmWhite)
public var position: Float?
/// 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 indicatorColor
case position
case inverted
}
//--------------------------------------------------
@ -72,6 +75,10 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
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) {
self.position = position
}
@ -112,6 +119,7 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
try container.encode(hidesForSinglePage, forKey: .hidesForSinglePage)
try container.encode(accessibilityHasSlidesInsteadOfPage, forKey: .accessibilityHasSlidesInsteadOfPage)
try container.encode(enabled, forKey: .enabled)
try container.encode(inverted, forKey: .inverted)
try container.encode(disabledIndicatorColor, forKey: .disabledIndicatorColor)
try container.encode(indicatorColor, forKey: .indicatorColor)
try container.encodeIfPresent(position, forKey: .position)

View File

@ -18,10 +18,10 @@ open class DashLine: View {
var dashModel: DashLineModel? {
get { return model as? DashLineModel }
}
//TODO: Need this for BAU. Can remove once we fix BAU
public var dashColor: UIColor?
@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.stroke()
dashLayer.strokeStart = 0.0
dashLayer.strokeStart = 0
dashLayer.lineWidth = 1
dashLayer.lineJoin = .miter
dashLayer.lineCap = .round
dashLayer.lineDashPattern = [NSNumber(value: 2), NSNumber(value: 2)]
dashLayer.path = path.cgPath
dashLayer.strokeColor = dashModel?.dashColor.cgColor ?? dashColor?.cgColor
dashLayer.strokeColor = dashColor?.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
}
@ -81,21 +81,21 @@ open class DashLine: View {
// MARK: - Atomization
//------------------------------------------------------
// Default values for view.
@objc open override func reset() {
backgroundColor = .clear
super.reset()
isHidden = false
}
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.set(with: model, delegateObject, additionalData)
guard let dashLineModel = dashModel else {
return
}
if let isHiddenValue = dashLineModel.isHidden {
isHidden = isHiddenValue
}
if let backgroundColor = dashLineModel.backgroundColor {
guard let model = dashModel else { return }
isHidden = model.isHidden
dashColor = (model.inverted ? model.dashColor_inverted : model.dashColor).uiColor
if let backgroundColor = model.backgroundColor {
dashLayer?.backgroundColor = backgroundColor.uiColor.cgColor
}
}

View File

@ -8,38 +8,66 @@
import Foundation
@objcMembers public class DashLineModel: MoleculeModelProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "dashLine"
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) {
self.dashColor = dashColor
}
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey {
case moleculeName
case backgroundColor
case dashColor_inverted
case dashColor
case isHidden
}
//--------------------------------------------------
// MARK: - codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
if let dashColor = try typeContainer.decodeIfPresent(Color.self, forKey: .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)
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 {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(dashColor, forKey: .dashColor)
try container.encodeIfPresent(isHidden, forKey: .isHidden)
try container.encode(isHidden, forKey: .isHidden)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
}
}

View File

@ -8,14 +8,27 @@
import UIKit
@objcMembers open class Line: View {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
var lineModel: 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 widthConstraint: NSLayoutConstraint?
open func updateLineConstraints(constant: CGFloat) {
if let useVerticalLine = lineModel?.useVerticalLine, useVerticalLine {
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) {
switch style {
case .standard:
updateLineConstraints(constant: 1)
@ -47,25 +74,23 @@ import UIKit
}
}
// MARK: - Helpers
open func shouldBeVisible() -> Bool {
guard let type = lineModel?.type else { return false }
return type != .none
}
public convenience init(pinTo view: UIView, edge: UIRectEdge, useMargin: Bool) {
self.init(frame: .zero)
addLine(to: view, edge: edge, useMargin: useMargin)
}
//--------------------------------------------------
// MARK: - MoleculeViewProtocol
//--------------------------------------------------
open func addLine(to view: UIView, edge: UIRectEdge, useMargin: Bool) {
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))
}
// MARK: - MVMCoreViewProtocol
open override func setupView() {
super.setupView()
heightConstraint = heightAnchor.constraint(equalToConstant: 1)
heightConstraint?.isActive = true
widthConstraint = widthAnchor.constraint(equalToConstant: 1)
@ -73,9 +98,9 @@ import UIKit
setStyle(.standard)
}
// MARK: - MoleculeViewProtocol
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.set(with: model, delegateObject, additionalData)
if let lineModel = model as? LineModel {
setStyle(lineModel.type)
}
@ -86,7 +111,9 @@ import UIKit
}
public override static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
guard let type = (model as? LineModel)?.type else { return 1 }
switch type {
case .none:
return 0

View File

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

View File

@ -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)
}
}

View File

@ -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

View File

@ -34,6 +34,7 @@ extension UIColor {
"green33": (.mvmGreen33, "#ABE4BF"),
"green66": (.mvmGreen66, "#57C880"),
"greenShade2": (.mvmGreenShade2, "#0F5B25"),
"greenInverted": (.mvmGreenInverted, "#00AC3E"),
"orange": (.mvmOrange, "#ED7000"),
"orange66": (.mvmOrange66, "#F3A157"),
"orange33": (.mvmOrange33, "#F9D0AB"),
@ -45,6 +46,7 @@ extension UIColor {
"blue66": (.mvmBlue66, "#57B1DF"),
"blueShade1": (.mvmBlueShade1, "#136598"),
"blueShade2": (.mvmBlueShade2, "#0B4467"),
"blueInverted": (.mvmBlueInverted, "#0088CE"),
"yellow": (.mvmYellow, "#FFBC3D"),
"coolGray1": (.mvmCoolGray1, "#F6F6F6"),
"coolGray3": (.mvmCoolGray3, "#D8DADA"),
@ -147,6 +149,9 @@ extension UIColor {
/// HEX: #0F5B25
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
//--------------------------------------------------
@ -166,6 +171,9 @@ extension UIColor {
/// HEX: #0B4467
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
//--------------------------------------------------