update link model

This commit is contained in:
Xinlei(Ryan) Pan 2020-01-22 10:16:18 -05:00
parent 25db4b1e14
commit cd231746cf
2 changed files with 13 additions and 17 deletions

View File

@ -16,15 +16,6 @@ import UIKit
private var additionalData: [AnyHashable: Any]? private var additionalData: [AnyHashable: Any]?
public var titleColor: (enabled: UIColor?, disabled: UIColor?) = (.mfTextButton(), .mfSilver())
public override var isEnabled: Bool {
didSet {
setTitleColor(isEnabled ? titleColor.enabled : titleColor.disabled, for: .normal)
setNeedsDisplay()
}
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Delegate // MARK: - Delegate
//-------------------------------------------------- //--------------------------------------------------
@ -80,9 +71,8 @@ extension Link {
super.setupView() super.setupView()
backgroundColor = .clear backgroundColor = .clear
contentMode = .redraw contentMode = .redraw
setTitleColor(.mfTextButton(), for: .normal) setTitleColor(.mvmBlack, for: .normal)
setTitleColor(.mfCharcoal(), for: .highlighted) setTitleColor(.mvmCoolGray6, for: .disabled)
titleColor = (.mfTextButton(), .mfSilver())
titleLabel?.numberOfLines = 1 titleLabel?.numberOfLines = 1
titleLabel?.lineBreakMode = .byTruncatingTail titleLabel?.lineBreakMode = .byTruncatingTail
titleLabel?.textAlignment = .left titleLabel?.textAlignment = .left
@ -96,6 +86,7 @@ extension Link: ModelMoleculeViewProtocol {
guard let model = model as? LinkModel else { return } guard let model = model as? LinkModel else { return }
setTitle(model.title, for: .normal) setTitle(model.title, for: .normal)
setTitleColor(model.textColor.uiColor, for: .normal) setTitleColor(model.textColor.uiColor, for: .normal)
setTitleColor(model.disabledColor.uiColor, for: .disabled)
isEnabled = model.enabled isEnabled = model.enabled
backgroundColor = model.backgroundColor?.uiColor backgroundColor = model.backgroundColor?.uiColor
set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) set(with: model.action, delegateObject: delegateObject, additionalData: additionalData)
@ -120,18 +111,16 @@ extension Link {
actionMap = dictionary actionMap = dictionary
if let disabledColorHex = dictionary["disabledColor"] as? String { if let disabledColorHex = dictionary["disabledColor"] as? String {
titleColor.disabled = .mfGet(forHex: disabledColorHex) setTitleColor(.mfGet(forHex: disabledColorHex), for: .disabled)
} }
if let colorHex = dictionary[KeyTextColor] as? String { if let colorHex = dictionary[KeyTextColor] as? String {
titleColor.enabled = .mfGet(forHex: colorHex) setTitleColor(.mfGet(forHex: colorHex), for: .normal)
setTitleColor(titleColor.enabled, for: .normal)
} }
if let title = dictionary.optionalStringForKey(KeyTitle) { if let title = dictionary.optionalStringForKey(KeyTitle) {
setTitle(title, for: .normal) setTitle(title, for: .normal)
} }
if let enabled = dictionary[KeyEnabled] as? Bool { if let enabled = dictionary[KeyEnabled] as? Bool {
isEnabled = enabled isEnabled = enabled
} }

View File

@ -14,7 +14,8 @@ public class LinkModel: MoleculeModelProtocol {
public var title: String public var title: String
public var action: ActionProtocol public var action: ActionProtocol
public var enabled = true public var enabled = true
public var textColor = Color(uiColor: .mfTextButton()) public var textColor = Color(uiColor: .mvmBlack)
public var disabledColor = Color(uiColor: .mvmCoolGray6)
public init(title: String, action: ActionProtocol) { public init(title: String, action: ActionProtocol) {
self.title = title self.title = title
@ -27,6 +28,7 @@ public class LinkModel: MoleculeModelProtocol {
case action case action
case enabled case enabled
case textColor case textColor
case disabledColor
} }
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
@ -40,6 +42,10 @@ public class LinkModel: MoleculeModelProtocol {
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor) { if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor) {
textColor = color textColor = color
} }
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) {
disabledColor = color
}
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
@ -49,5 +55,6 @@ public class LinkModel: MoleculeModelProtocol {
try container.encodeModel(action, forKey: .action) try container.encodeModel(action, forKey: .action)
try container.encode(enabled, forKey: .enabled) try container.encode(enabled, forKey: .enabled)
try container.encode(textColor, forKey: .textColor) try container.encode(textColor, forKey: .textColor)
try container.encode(disabledColor, forKey: .disabledColor)
} }
} }