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]?
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
//--------------------------------------------------
@ -80,9 +71,8 @@ extension Link {
super.setupView()
backgroundColor = .clear
contentMode = .redraw
setTitleColor(.mfTextButton(), for: .normal)
setTitleColor(.mfCharcoal(), for: .highlighted)
titleColor = (.mfTextButton(), .mfSilver())
setTitleColor(.mvmBlack, for: .normal)
setTitleColor(.mvmCoolGray6, for: .disabled)
titleLabel?.numberOfLines = 1
titleLabel?.lineBreakMode = .byTruncatingTail
titleLabel?.textAlignment = .left
@ -96,6 +86,7 @@ extension Link: ModelMoleculeViewProtocol {
guard let model = model as? LinkModel else { return }
setTitle(model.title, for: .normal)
setTitleColor(model.textColor.uiColor, for: .normal)
setTitleColor(model.disabledColor.uiColor, for: .disabled)
isEnabled = model.enabled
backgroundColor = model.backgroundColor?.uiColor
set(with: model.action, delegateObject: delegateObject, additionalData: additionalData)
@ -120,18 +111,16 @@ extension Link {
actionMap = dictionary
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 {
titleColor.enabled = .mfGet(forHex: colorHex)
setTitleColor(titleColor.enabled, for: .normal)
setTitleColor(.mfGet(forHex: colorHex), for: .normal)
}
if let title = dictionary.optionalStringForKey(KeyTitle) {
setTitle(title, for: .normal)
}
if let enabled = dictionary[KeyEnabled] as? Bool {
isEnabled = enabled
}

View File

@ -14,7 +14,8 @@ public class LinkModel: MoleculeModelProtocol {
public var title: String
public var action: ActionProtocol
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) {
self.title = title
@ -27,6 +28,7 @@ public class LinkModel: MoleculeModelProtocol {
case action
case enabled
case textColor
case disabledColor
}
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) {
textColor = color
}
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) {
disabledColor = color
}
}
public func encode(to encoder: Encoder) throws {
@ -49,5 +55,6 @@ public class LinkModel: MoleculeModelProtocol {
try container.encodeModel(action, forKey: .action)
try container.encode(enabled, forKey: .enabled)
try container.encode(textColor, forKey: .textColor)
try container.encode(disabledColor, forKey: .disabledColor)
}
}