Added action key.

This commit is contained in:
Lekshmi S 2020-09-14 17:38:20 +05:30
parent f3f71cbb38
commit 884f2ad69f
2 changed files with 7 additions and 5 deletions

View File

@ -44,7 +44,7 @@ import UIKit
func drawHeart() -> CAShapeLayer {
let heart = CAShapeLayer()
let rect = CGRect(x: 0, y: 0, width: 10, height: 10)
let rect = self.bounds
let leftArc = rect.width * 0.4
let rightArc = rect.height * 0.3
let arcRadius = sqrt(leftArc*leftArc + rightArc*rightArc)/2
@ -73,7 +73,7 @@ import UIKit
open override func setupView() {
super.setupView()
addTarget(self, action: #selector(tapAction), for: .touchUpInside)
widthConstraint = widthAnchor.constraint(equalToConstant: 10)
widthConstraint = widthAnchor.constraint(equalToConstant: 22)
widthConstraint?.isActive = true
heightConstraint = heightAnchor.constraint(equalTo: widthAnchor, multiplier: 1)
heightConstraint?.isActive = true

View File

@ -9,32 +9,32 @@
import Foundation
open class HeartModel: MoleculeModelProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "heart"
public var backgroundColor: Color?
public var isActive: Bool = false
public var activeColor: Color = Color(uiColor: .mvmRed)
public var inActiveColor: Color = Color(uiColor: .clear)
public var action: ActionModelProtocol?
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey {
case moleculeName
case backgroundColor
case isActive
case activeColor
case inActiveColor
case action
}
//--------------------------------------------------
// MARK: - Codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
@ -48,6 +48,7 @@ open class HeartModel: MoleculeModelProtocol {
if let inActiveColor = try typeContainer.decodeIfPresent(Color.self, forKey: .inActiveColor) {
self.inActiveColor = inActiveColor
}
action = try typeContainer.decodeModelIfPresent(codingKey: .action)
}
public func encode(to encoder: Encoder) throws {
@ -57,5 +58,6 @@ open class HeartModel: MoleculeModelProtocol {
try container.encodeIfPresent(isActive, forKey: .isActive)
try container.encodeIfPresent(activeColor, forKey: .activeColor)
try container.encodeIfPresent(inActiveColor, forKey: .inActiveColor)
try container.encodeModelIfPresent(action, forKey: .action)
}
}