Code changes based on review comments and added default action noop.

This commit is contained in:
Lekshmi S 2020-09-29 17:39:16 +05:30
parent 8534042311
commit 7c4c9ea43a
3 changed files with 14 additions and 7 deletions

View File

@ -8,7 +8,7 @@
import UIKit
@objcMembers open class Heart: Control {
@objcMembers open class Heart: Control, MFButtonProtocol {
//--------------------------------------------------
// MARK: - Properties
@ -24,6 +24,7 @@ import UIKit
public var heartModel: HeartModel? {
return model as? HeartModel
}
var additionalData: [AnyHashable: Any]?
//--------------------------------------------------
// MARK: - Constraints
@ -86,6 +87,7 @@ import UIKit
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.set(with: model, delegateObject, additionalData)
self.delegateObject = delegateObject
self.additionalData = additionalData
guard let model = model as? HeartModel else { return }
isSelected = model.isActive
}
@ -103,6 +105,9 @@ import UIKit
func tapAction() {
isSelected = !isSelected
if let heartModel = heartModel {
Button.performButtonAction(with: heartModel.action, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: heartModel)
}
setNeedsDisplay()
}
}

View File

@ -18,7 +18,7 @@ open class HeartModel: MoleculeModelProtocol {
public var isActive: Bool = false
public var activeColor: Color = Color(uiColor: .mvmRed)
public var inActiveColor: Color = Color(uiColor: .clear)
public var action: ActionModelProtocol?
public var action: ActionModelProtocol = ActionNoopModel()
//--------------------------------------------------
// MARK: - Keys
@ -48,16 +48,18 @@ open class HeartModel: MoleculeModelProtocol {
if let inActiveColor = try typeContainer.decodeIfPresent(Color.self, forKey: .inActiveColor) {
self.inActiveColor = inActiveColor
}
action = try typeContainer.decodeModelIfPresent(codingKey: .action)
if let action: ActionModelProtocol = try typeContainer.decodeModelIfPresent(codingKey: .action) {
self.action = action
}
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(isActive, forKey: .isActive)
try container.encodeIfPresent(activeColor, forKey: .activeColor)
try container.encodeIfPresent(inActiveColor, forKey: .inActiveColor)
try container.encode(isActive, forKey: .isActive)
try container.encode(activeColor, forKey: .activeColor)
try container.encode(inActiveColor, forKey: .inActiveColor)
try container.encodeModelIfPresent(action, forKey: .action)
}
}

View File

@ -68,7 +68,7 @@
"AccToggleHint" = "double tap to toggle";
// MARK: Heart
"heart" = "Heart";
"heart" = "Favorite";
"heart_action_hint" = "Double tap to select";
"heart_selected_state" = "Selected";
"heart_not_selected_state" = "Not Selected";