more changes for inverted

This commit is contained in:
Kevin G Christiano 2020-05-06 16:31:45 -04:00
parent 9e9984a8c5
commit e4911a8cce
2 changed files with 38 additions and 21 deletions

View File

@ -35,7 +35,7 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW
}
public var size: Styler.Button.Size? = .standard
public var groupName: String = ""
public var isInverted: Bool = false
public var inverted: Bool = false
public lazy var enabledColors: FacadeElements = (fill: enabled_fillColor(),
text: enabled_textColor(),
@ -97,29 +97,29 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW
//--------------------------------------------------
// MARK: - Methods
//--------------------------------------------------
public func enabled_fillColor() -> UIColor? {
return (isInverted ? enabledFillColor_inverted : enabledFillColor)?.uiColor
return (inverted ? enabledFillColor_inverted : enabledFillColor)?.uiColor
}
public func enabled_textColor() -> UIColor? {
return (isInverted ? enabledTextColor_inverted : enabledTextColor)?.uiColor
return (inverted ? enabledTextColor_inverted : enabledTextColor)?.uiColor
}
public func enabled_borderColor() -> UIColor? {
return (isInverted ? enabledBorderColor_inverted : enabledBorderColor)?.uiColor
return (inverted ? enabledBorderColor_inverted : enabledBorderColor)?.uiColor
}
public func disabled_fillColor() -> UIColor? {
return (isInverted ? disabledFillColor_inverted : disabledFillColor)?.uiColor
return (inverted ? disabledFillColor_inverted : disabledFillColor)?.uiColor
}
public func disabled_textColor() -> UIColor? {
return (isInverted ? disabledTextColor_inverted : disabledTextColor)?.uiColor
return (inverted ? disabledTextColor_inverted : disabledTextColor)?.uiColor
}
public func disabled_borderColor() -> UIColor? {
return (isInverted ? disabledBorderColor_inverted : disabledBorderColor)?.uiColor
return (inverted ? disabledBorderColor_inverted : disabledBorderColor)?.uiColor
}
/// Defines the default appearance for the primary style.
@ -134,6 +134,7 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW
disabledFillColor = Color(uiColor: .mvmCoolGray6)
disabledTextColor = Color(uiColor: .mvmWhite)
}
enabledFillColor_inverted = Color(uiColor: .mvmWhite)
enabledTextColor_inverted = Color(uiColor: .mvmBlack)
disabledFillColor_inverted = Color(uiColor: .mvmCoolGray6)
@ -152,6 +153,7 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW
disabledTextColor = Color(uiColor: .mvmCoolGray6)
disabledBorderColor = Color(uiColor: .mvmCoolGray6)
}
enabledTextColor_inverted = Color(uiColor: .mvmWhite)
enabledBorderColor_inverted = Color(uiColor: .mvmWhite)
disabledTextColor_inverted = Color(uiColor: .mvmCoolGray6)
@ -203,20 +205,37 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW
self.enabled = enabled
}
if let isInverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) {
self.isInverted = isInverted
if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) {
self.inverted = inverted
}
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
self.groupName = groupName
}
enabledFillColor = try typeContainer.decodeIfPresent(Color.self, forKey: .fillColor)
enabledTextColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor)
enabledBorderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor)
disabledFillColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledFillColor)
disabledTextColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledTextColor)
disabledBorderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledBorderColor)
if let enabledFillColor = try typeContainer.decodeIfPresent(Color.self, forKey: .fillColor) {
self.enabledFillColor = enabledFillColor
}
if let enabledTextColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor) {
self.enabledTextColor = enabledTextColor
}
if let enabledBorderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) {
self.enabledBorderColor = enabledBorderColor
}
if let disabledFillColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledFillColor) {
self.disabledFillColor = disabledFillColor
}
if let disabledTextColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledTextColor) {
self.disabledTextColor = disabledTextColor
}
if let disabledBorderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledBorderColor) {
self.disabledBorderColor = disabledBorderColor
}
}
public func encode(to encoder: Encoder) throws {
@ -224,7 +243,7 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW
try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(title, forKey: .title)
try container.encode(enabled, forKey: .enabled)
try container.encode(isInverted, forKey: .inverted)
try container.encode(inverted, forKey: .inverted)
try container.encodeModel(action, forKey: .action)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(enabledFillColor, forKey: .fillColor)

View File

@ -45,7 +45,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
guard let currentColor = layer.borderColor else { return nil }
return UIColor(cgColor: currentColor)
}
set { layer.borderColor = newValue?.cgColor}
set { layer.borderColor = newValue?.cgColor }
}
//--------------------------------------------------
@ -55,7 +55,6 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
/// The primary styling for a button. Should be used for main buttons
public func stylePrimary() {
buttonModel?.style = .primary
enabledTitleColor = buttonModel?.enabledColors.text ?? .mvmWhite
disabledTitleColor = buttonModel?.disabledColors.text ?? .mvmWhite
layer.borderWidth = 0
@ -65,7 +64,6 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
/// The secondary styling for a button. Should be used for secondary buttons
public func styleSecondary() {
buttonModel?.style = .secondary
enabledTitleColor = buttonModel?.enabledColors.text ?? .mvmBlack
disabledTitleColor = buttonModel?.disabledColors.text ?? .mvmCoolGray6
backgroundColor = .clear
@ -114,7 +112,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
}
private func getInnerPadding() -> CGFloat {
return getHeight() / 2
return getHeight() / 2.0
}
private func getHeight() -> CGFloat {