From e4911a8ccea4794f553fcec508857a91f84bb896 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 6 May 2020 16:31:45 -0400 Subject: [PATCH] more changes for inverted --- .../Atomic/Atoms/Buttons/ButtonModel.swift | 53 +++++++++++++------ .../Atomic/Atoms/Buttons/PillButton.swift | 6 +-- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift index 5567c540..601a8fb2 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift @@ -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) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift index 5fe7a972..745a34f4 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift @@ -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 {