current state

This commit is contained in:
Kevin G Christiano 2020-05-13 11:19:13 -04:00
parent 699943749d
commit e676d78eb2
2 changed files with 29 additions and 18 deletions

View File

@ -13,7 +13,6 @@ open class CaretView: View {
//------------------------------------------------------ //------------------------------------------------------
private var caretPath: UIBezierPath = UIBezierPath() private var caretPath: UIBezierPath = UIBezierPath()
public var strokeColor: UIColor = .mvmBlack
public var lineWidth: CGFloat = 1 public var lineWidth: CGFloat = 1
public var direction: Direction = .right public var direction: Direction = .right
@ -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 = .mvmBlack enabledColor = .mvmBlack
} }
/// Ensure you have defined a CaretSize with Orientation before calling. /// Ensure you have defined a CaretSize with Orientation before calling.
@ -178,7 +176,7 @@ open class CaretView: View {
//------------------------------------------------------ //------------------------------------------------------
/// 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)
@ -189,12 +187,12 @@ open class CaretView: View {
guard let model = model as? CaretViewModel else { return } guard let model = model as? CaretViewModel else { return }
strokeColor = (model.inverted ? model.strokeColor_inverted : model.strokeColor).uiColor enabledColor = (model.inverted ? model.strokeColor_inverted : model.strokeColor).uiColor
isHidden = model.isHidden ?? false isHidden = model.isHidden
isOpaque = model.isOpaque ?? false isOpaque = model.isOpaque
if let lineWidthValue = model.lineWidth { if let lineWidthValue = model.lineWidth {
lineWidth = lineWidthValue lineWidth = lineWidthValue
} }
} }
} }

View File

@ -18,8 +18,8 @@ import Foundation
public var backgroundColor: Color? public var backgroundColor: Color?
public var strokeColor: Color = Color(uiColor: .mvmBlack) public var strokeColor: Color = Color(uiColor: .mvmBlack)
public var strokeColor_inverted: Color = Color(uiColor: .mvmWhite) public var strokeColor_inverted: Color = Color(uiColor: .mvmWhite)
public var isHidden: Bool? public var isHidden: Bool = false
public var isOpaque: Bool? public var isOpaque: Bool = false
public var inverted: Bool = false public var inverted: Bool = false
public var lineWidth: CGFloat? public var lineWidth: CGFloat?
@ -31,6 +31,7 @@ import Foundation
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
@ -48,13 +49,24 @@ import Foundation
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) { if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) {
self.inverted = 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)
} }
@ -62,6 +74,7 @@ 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.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)