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

View File

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