disabled and init

This commit is contained in:
Kevin G Christiano 2020-05-21 16:46:01 -04:00
parent c6a2bbaf74
commit 3f0828fa44
3 changed files with 16 additions and 18 deletions

View File

@ -143,11 +143,8 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol {
backgroundColor = color.uiColor backgroundColor = color.uiColor
} }
enabledColor = (model.inverted ? model.enabled_inverted : model.enabledColor).uiColor enabledColor = (model.inverted ? model.enabledColor_inverted : model.enabledColor).uiColor
disabledColor = (model.inverted ? model.disabledColor_inverted : model.disabledColor).uiColor
if let color = model.disabledColor {
disabledColor = color.uiColor
}
isEnabled = model.enabled isEnabled = model.enabled
set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) set(with: model.action, delegateObject: delegateObject, additionalData: additionalData)

View File

@ -20,8 +20,9 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol {
public var title: String public var title: String
public var action: ActionModelProtocol public var action: ActionModelProtocol
public var enabledColor: Color = Color(uiColor: .mvmBlack) public var enabledColor: Color = Color(uiColor: .mvmBlack)
public var disabledColor: Color? = Color(uiColor: .mvmCoolGray6) public var disabledColor: Color = Color(uiColor: .mvmCoolGray6)
public var enabled_inverted: Color = Color(uiColor: .mvmWhite) public var enabledColor_inverted: Color = Color(uiColor: .mvmWhite)
public var disabledColor_inverted: Color = Color(uiColor: .mvmCoolGray10)
public var enabled = true public var enabled = true
public var inverted = false public var inverted = false
@ -42,7 +43,8 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol {
case backgroundColor case backgroundColor
case title case title
case action case action
case enabled_inverted case enabledColor_inverted
case disabledColor_inverted
case enabledColor case enabledColor
case disabledColor case disabledColor
case enabled case enabled
@ -60,8 +62,12 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol {
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
title = try typeContainer.decode(String.self, forKey: .title) title = try typeContainer.decode(String.self, forKey: .title)
if let enabled_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .enabled_inverted) { if let enabledColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor_inverted) {
self.enabled_inverted = enabled_inverted self.enabledColor_inverted = enabledColor_inverted
}
if let disabledColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor_inverted) {
self.disabledColor_inverted = disabledColor_inverted
} }
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor) { if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor) {
@ -92,7 +98,8 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol {
try container.encode(enabled, forKey: .enabledColor) try container.encode(enabled, forKey: .enabledColor)
try container.encodeIfPresent(disabledColor, forKey: .disabledColor) try container.encodeIfPresent(disabledColor, forKey: .disabledColor)
try container.encode(enabled, forKey: .enabled) try container.encode(enabled, forKey: .enabled)
try container.encode(enabled_inverted, forKey: .enabled_inverted) try container.encode(enabledColor_inverted, forKey: .enabledColor_inverted)
try container.encode(disabledColor_inverted, forKey: .disabledColor_inverted)
try container.encode(inverted, forKey: .inverted) try container.encode(inverted, forKey: .inverted)
} }
} }

View File

@ -47,9 +47,7 @@ import UIKit
public convenience init(pinTo view: UIView, edge: UIRectEdge, useMargin: Bool) { public convenience init(pinTo view: UIView, edge: UIRectEdge, useMargin: Bool) {
self.init(frame: .zero) self.init(frame: .zero)
addLine(to: view, edge: edge, useMargin: useMargin)
view.addSubview(self)
NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: self, useMargins: useMargin, pinTop: edge != .bottom, pinBottom: edge != .top, pinLeft: edge != .right, pinRight: edge != .left).values))
} }
//-------------------------------------------------- //--------------------------------------------------
@ -84,10 +82,6 @@ import UIKit
//-------------------------------------------------- //--------------------------------------------------
// MARK: - MoleculeViewProtocol // MARK: - MoleculeViewProtocol
//-------------------------------------------------- //--------------------------------------------------
public convenience init(pinTo view: UIView, edge: UIRectEdge, useMargin: Bool) {
self.init(frame: .zero)
addLine(to: view, edge: edge, useMargin: useMargin)
}
open func addLine(to view: UIView, edge: UIRectEdge, useMargin: Bool) { open func addLine(to view: UIView, edge: UIRectEdge, useMargin: Bool) {
view.addSubview(self) view.addSubview(self)