Dash line color require for model, optional for server
This commit is contained in:
parent
f40335ce19
commit
d651fb5783
@ -15,8 +15,11 @@ open class DashLine: View {
|
|||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
@objc public var dashColor: UIColor?
|
var dashModel: DashLineModel? {
|
||||||
@objc public var dashLayer: CAShapeLayer?
|
get { return model as? DashLineModel }
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private var dashLayer: CAShapeLayer?
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Lifecycle
|
// MARK: - Lifecycle
|
||||||
@ -53,7 +56,7 @@ open class DashLine: View {
|
|||||||
dashLayer.lineCap = .round
|
dashLayer.lineCap = .round
|
||||||
dashLayer.lineDashPattern = [NSNumber(value: 2), NSNumber(value: 2)]
|
dashLayer.lineDashPattern = [NSNumber(value: 2), NSNumber(value: 2)]
|
||||||
dashLayer.path = path.cgPath
|
dashLayer.path = path.cgPath
|
||||||
dashLayer.strokeColor = dashColor?.cgColor ?? UIColor.mfLighterGray().cgColor
|
dashLayer.strokeColor = dashModel?.dashColor.uiColor.cgColor ?? UIColor.mfLighterGray().cgColor
|
||||||
dashLayer.fillColor = UIColor.clear.cgColor
|
dashLayer.fillColor = UIColor.clear.cgColor
|
||||||
dashLayer.backgroundColor = backgroundColor?.cgColor ?? UIColor.white.cgColor
|
dashLayer.backgroundColor = backgroundColor?.cgColor ?? UIColor.white.cgColor
|
||||||
self.dashLayer = dashLayer
|
self.dashLayer = dashLayer
|
||||||
@ -70,27 +73,16 @@ open class DashLine: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||||
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
guard let json = json, let model = try? Self.decodeJSONToModel(json: json, type: DashLineModel.self) else { return }
|
||||||
|
setWithModel(model, delegateObject, additionalData as? [String : AnyHashable])
|
||||||
// Configure class properties with JSON values
|
|
||||||
guard let jsonDictionary = json else { return }
|
|
||||||
|
|
||||||
if let isHiddenValue = jsonDictionary[KeyIsHidden] as? Bool {
|
|
||||||
isHidden = isHiddenValue
|
|
||||||
}
|
|
||||||
|
|
||||||
if let dashColorHex = jsonDictionary["dashColor"] as? String {
|
|
||||||
dashColor = UIColor.mfGet(forHex: dashColorHex)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//MARK: - MVMCoreMoleculeViewProtocol
|
//MARK: - MVMCoreMoleculeViewProtocol
|
||||||
public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) {
|
public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) {
|
||||||
super.setWithModel(model, delegateObject, additionalData)
|
super.setWithModel(model, delegateObject, additionalData)
|
||||||
guard let dashLineModel = model as? DashLineModel else {
|
guard let dashLineModel = dashModel else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dashColor = dashLineModel.dashColor.uiColor
|
|
||||||
if let isHiddenValue = dashLineModel.isHidden {
|
if let isHiddenValue = dashLineModel.isHidden {
|
||||||
isHidden = isHiddenValue
|
isHidden = isHiddenValue
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,10 +12,32 @@ import Foundation
|
|||||||
public static var identifier: String = "dashLine"
|
public static var identifier: String = "dashLine"
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
|
|
||||||
public var dashColor: Color
|
public var dashColor: Color = Color(uiColor: .mfLighterGray())
|
||||||
public var isHidden: Bool?
|
public var isHidden: Bool?
|
||||||
|
|
||||||
public init(dashColor: Color) {
|
public init(dashColor: Color) {
|
||||||
self.dashColor = dashColor
|
self.dashColor = dashColor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum CodingKeys: String, CodingKey {
|
||||||
|
case backgroundColor
|
||||||
|
case dashColor
|
||||||
|
case isHidden
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
|
isHidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .isHidden)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func encode(to encoder: Encoder) throws {
|
||||||
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(dashColor, forKey: .dashColor)
|
||||||
|
try container.encodeIfPresent(isHidden, forKey: .isHidden)
|
||||||
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user