Code changes based on review comments and added default action noop.
This commit is contained in:
parent
8534042311
commit
7c4c9ea43a
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
@objcMembers open class Heart: Control {
|
@objcMembers open class Heart: Control, MFButtonProtocol {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
@ -24,6 +24,7 @@ import UIKit
|
|||||||
public var heartModel: HeartModel? {
|
public var heartModel: HeartModel? {
|
||||||
return model as? HeartModel
|
return model as? HeartModel
|
||||||
}
|
}
|
||||||
|
var additionalData: [AnyHashable: Any]?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Constraints
|
// MARK: - Constraints
|
||||||
@ -86,6 +87,7 @@ import UIKit
|
|||||||
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
super.set(with: model, delegateObject, additionalData)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
self.delegateObject = delegateObject
|
self.delegateObject = delegateObject
|
||||||
|
self.additionalData = additionalData
|
||||||
guard let model = model as? HeartModel else { return }
|
guard let model = model as? HeartModel else { return }
|
||||||
isSelected = model.isActive
|
isSelected = model.isActive
|
||||||
}
|
}
|
||||||
@ -103,6 +105,9 @@ import UIKit
|
|||||||
|
|
||||||
func tapAction() {
|
func tapAction() {
|
||||||
isSelected = !isSelected
|
isSelected = !isSelected
|
||||||
|
if let heartModel = heartModel {
|
||||||
|
Button.performButtonAction(with: heartModel.action, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: heartModel)
|
||||||
|
}
|
||||||
setNeedsDisplay()
|
setNeedsDisplay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ open class HeartModel: MoleculeModelProtocol {
|
|||||||
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?
|
public var action: ActionModelProtocol = ActionNoopModel()
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Keys
|
// MARK: - Keys
|
||||||
@ -48,16 +48,18 @@ 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)
|
if let action: ActionModelProtocol = try typeContainer.decodeModelIfPresent(codingKey: .action) {
|
||||||
|
self.action = action
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
public func encode(to encoder: Encoder) throws {
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encodeIfPresent(isActive, forKey: .isActive)
|
try container.encode(isActive, forKey: .isActive)
|
||||||
try container.encodeIfPresent(activeColor, forKey: .activeColor)
|
try container.encode(activeColor, forKey: .activeColor)
|
||||||
try container.encodeIfPresent(inActiveColor, forKey: .inActiveColor)
|
try container.encode(inActiveColor, forKey: .inActiveColor)
|
||||||
try container.encodeModelIfPresent(action, forKey: .action)
|
try container.encodeModelIfPresent(action, forKey: .action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,7 +68,7 @@
|
|||||||
"AccToggleHint" = "double tap to toggle";
|
"AccToggleHint" = "double tap to toggle";
|
||||||
|
|
||||||
// MARK: Heart
|
// MARK: Heart
|
||||||
"heart" = "Heart";
|
"heart" = "Favorite";
|
||||||
"heart_action_hint" = "Double tap to select";
|
"heart_action_hint" = "Double tap to select";
|
||||||
"heart_selected_state" = "Selected";
|
"heart_selected_state" = "Selected";
|
||||||
"heart_not_selected_state" = "Not Selected";
|
"heart_not_selected_state" = "Not Selected";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user