caret view inversion start
This commit is contained in:
parent
1a2d7b2abd
commit
a093d4ec74
@ -13,14 +13,14 @@ open class CaretView: View {
|
|||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
private var caretPath: UIBezierPath = UIBezierPath()
|
private var caretPath: UIBezierPath = UIBezierPath()
|
||||||
public var strokeColor: UIColor = .black
|
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
|
||||||
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
|
||||||
@ -161,7 +161,7 @@ open class CaretView: View {
|
|||||||
isOpaque = false
|
isOpaque = false
|
||||||
isHidden = false
|
isHidden = false
|
||||||
backgroundColor = .clear
|
backgroundColor = .clear
|
||||||
strokeColor = .black
|
strokeColor = .mvmBlack
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensure you have defined a CaretSize with Orientation before calling.
|
/// Ensure you have defined a CaretSize with Orientation before calling.
|
||||||
@ -177,7 +177,7 @@ 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()
|
||||||
@ -186,20 +186,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
|
|
||||||
}
|
|
||||||
strokeColor = caretModel.strokeColor.uiColor
|
|
||||||
isHidden = caretModel.isHidden ?? false
|
|
||||||
isOpaque = caretModel.isOpaque ?? false
|
|
||||||
|
|
||||||
if let lineWidthValue = caretModel.lineWidth {
|
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 = model.lineWidth {
|
||||||
lineWidth = lineWidthValue
|
lineWidth = lineWidthValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension CaretView: MVMCoreUIViewConstrainingProtocol {
|
extension CaretView: MVMCoreUIViewConstrainingProtocol {
|
||||||
|
|
||||||
open func needsToBeConstrained() -> Bool {
|
open func needsToBeConstrained() -> Bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,15 +8,25 @@
|
|||||||
|
|
||||||
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 strokeColor_inverted: Color = Color(uiColor: .mvmWhite)
|
||||||
public var isHidden: Bool?
|
public var isHidden: Bool?
|
||||||
public var isOpaque: Bool?
|
public var isOpaque: Bool?
|
||||||
|
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
|
||||||
@ -24,13 +34,24 @@ import Foundation
|
|||||||
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 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)
|
isHidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .isHidden)
|
||||||
isOpaque = try typeContainer.decodeIfPresent(Bool.self, forKey: .isOpaque)
|
isOpaque = try typeContainer.decodeIfPresent(Bool.self, forKey: .isOpaque)
|
||||||
@ -41,6 +62,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(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)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user