current state
This commit is contained in:
parent
699943749d
commit
e676d78eb2
@ -13,7 +13,6 @@ open class CaretView: View {
|
||||
//------------------------------------------------------
|
||||
|
||||
private var caretPath: UIBezierPath = UIBezierPath()
|
||||
public var strokeColor: UIColor = .mvmBlack
|
||||
public var lineWidth: CGFloat = 1
|
||||
|
||||
public var direction: Direction = .right
|
||||
@ -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 = .mvmBlack
|
||||
enabledColor = .mvmBlack
|
||||
}
|
||||
|
||||
/// Ensure you have defined a CaretSize with Orientation before calling.
|
||||
@ -178,7 +176,7 @@ open class CaretView: 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)
|
||||
defaultState()
|
||||
set(with: model, delegateObject, additionalData)
|
||||
@ -189,12 +187,12 @@ open class CaretView: View {
|
||||
|
||||
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
|
||||
|
||||
enabledColor = (model.inverted ? model.strokeColor_inverted : model.strokeColor).uiColor
|
||||
isHidden = model.isHidden
|
||||
isOpaque = model.isOpaque
|
||||
|
||||
if let lineWidthValue = model.lineWidth {
|
||||
lineWidth = lineWidthValue
|
||||
lineWidth = lineWidthValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,8 +18,8 @@ import Foundation
|
||||
public var backgroundColor: Color?
|
||||
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 isHidden: Bool = false
|
||||
public var isOpaque: Bool = false
|
||||
public var inverted: Bool = false
|
||||
public var lineWidth: CGFloat?
|
||||
|
||||
@ -31,6 +31,7 @@ import Foundation
|
||||
case moleculeName
|
||||
case backgroundColor
|
||||
case strokeColor
|
||||
case strokeColor_inverted
|
||||
case isHidden
|
||||
case isOpaque
|
||||
case lineWidth
|
||||
@ -48,13 +49,24 @@ import Foundation
|
||||
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)
|
||||
}
|
||||
|
||||
@ -62,6 +74,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(strokeColor_inverted, forKey: .strokeColor_inverted)
|
||||
try container.encode(inverted, forKey: .inverted)
|
||||
try container.encodeIfPresent(isHidden, forKey: .isHidden)
|
||||
try container.encodeIfPresent(isOpaque, forKey: .isOpaque)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user