caret view inversion start

This commit is contained in:
Kevin G Christiano 2020-05-12 12:45:53 -04:00
parent 1a2d7b2abd
commit a093d4ec74
2 changed files with 37 additions and 14 deletions

View File

@ -13,14 +13,14 @@ open class CaretView: View {
//------------------------------------------------------
private var caretPath: UIBezierPath = UIBezierPath()
public var strokeColor: UIColor = .black
public var strokeColor: UIColor = .mvmBlack
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
@ -161,7 +161,7 @@ open class CaretView: View {
isOpaque = false
isHidden = false
backgroundColor = .clear
strokeColor = .black
strokeColor = .mvmBlack
}
/// Ensure you have defined a CaretSize with Orientation before calling.
@ -177,7 +177,7 @@ open class CaretView: View {
// MARK: - Atomization
//------------------------------------------------------
// Default values for view.
/// Default values for view.
public required init(model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
super.init(frame: .zero)
defaultState()
@ -186,20 +186,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
guard let model = model as? CaretViewModel else { return }
strokeColor = (model.inverted ? model.strokeColor_inverted : model.strokeColor).uiColor
isHidden = model.isHidden ?? false
isOpaque = model.isOpaque ?? false
if let lineWidthValue = caretModel.lineWidth {
if let lineWidthValue = model.lineWidth {
lineWidth = lineWidthValue
}
}
}
extension CaretView: MVMCoreUIViewConstrainingProtocol {
open func needsToBeConstrained() -> Bool {
return true
}

View File

@ -8,15 +8,25 @@
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 strokeColor: Color = Color(uiColor: .mvmBlack)
public var strokeColor_inverted: Color = Color(uiColor: .mvmWhite)
public var isHidden: Bool?
public var isOpaque: Bool?
public var inverted: Bool = false
public var lineWidth: CGFloat?
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey {
case moleculeName
case backgroundColor
@ -24,13 +34,24 @@ import Foundation
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 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)
@ -41,6 +62,7 @@ import Foundation
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(strokeColor, forKey: .strokeColor)
try container.encode(inverted, forKey: .inverted)
try container.encodeIfPresent(isHidden, forKey: .isHidden)
try container.encodeIfPresent(isOpaque, forKey: .isOpaque)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)