latest state

This commit is contained in:
Kevin G Christiano 2020-05-05 09:01:38 -04:00
parent 0268767554
commit 3de0c4865a
4 changed files with 22 additions and 44 deletions

View File

@ -19,23 +19,8 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW
public var title: String public var title: String
public var action: ActionModelProtocol public var action: ActionModelProtocol
public var enabled: Bool = true public var enabled: Bool = true
public var isInverted: Bool = false {
didSet { facade.isInverted = isInverted }
}
public lazy var facade: Facade = primaryFacade public lazy var facade: Facade = primaryFacade
public var style: Styler.Button?
public var style: Styler.Button = .primary {
didSet {
switch style {
case .primary:
facade = primaryFacade
case .secondary:
facade = secondaryFacade
}
}
}
public var size: Styler.Button.Size? = .standard public var size: Styler.Button.Size? = .standard
public var groupName: String = "" public var groupName: String = ""
@ -128,10 +113,6 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW
title = try typeContainer.decode(String.self, forKey: .title) title = try typeContainer.decode(String.self, forKey: .title)
action = try typeContainer.decodeModel(codingKey: .action) action = try typeContainer.decodeModel(codingKey: .action)
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
self.groupName = groupName
}
if let style = try typeContainer.decodeIfPresent(Styler.Button.self, forKey: .style) { if let style = try typeContainer.decodeIfPresent(Styler.Button.self, forKey: .style) {
self.style = style self.style = style
} }
@ -146,26 +127,21 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW
if let facade = try typeContainer.decodeIfPresent(Facade.self, forKey: .facade) { if let facade = try typeContainer.decodeIfPresent(Facade.self, forKey: .facade) {
self.facade = facade self.facade = facade
switch style {
case .primary:
primaryFacade = facade
case .secondary:
secondaryFacade = facade
}
} }
if let isInverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) { if let isInverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) {
self.isInverted = isInverted
facade.isInverted = isInverted facade.isInverted = isInverted
} }
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
self.groupName = groupName
}
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(title, forKey: .title) try container.encode(title, forKey: .title)
try container.encode(isInverted, forKey: .inverted)
try container.encode(enabled, forKey: .enabled) try container.encode(enabled, forKey: .enabled)
try container.encodeModel(action, forKey: .action) try container.encodeModel(action, forKey: .action)
try container.encodeIfPresent(facade, forKey: .facade) try container.encodeIfPresent(facade, forKey: .facade)

View File

@ -26,11 +26,6 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
didSet { style() } didSet { style() }
} }
private enum Height: CGFloat {
case tiny = 20
case standard = 42
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Computed Properties // MARK: - Computed Properties
//-------------------------------------------------- //--------------------------------------------------
@ -60,22 +55,20 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
/// The primary styling for a button. Should be used for main buttons /// The primary styling for a button. Should be used for main buttons
public func stylePrimary() { public func stylePrimary() {
buttonModel?.style = .primary
enabledTitleColor = buttonModel?.facade.enabled.text ?? .mvmWhite enabledTitleColor = buttonModel?.facade.enabled.text ?? .mvmWhite
disabledTitleColor = buttonModel?.facade.disabled.text ?? .mvmWhite disabledTitleColor = buttonModel?.facade.disabled.text ?? .mvmWhite
layer.borderWidth = buttonModel?.facade.getBorderWidth() ?? 0 layer.borderWidth = buttonModel?.facade.getBorderWidth() ?? 0
backgroundColor = isEnabled ? buttonModel?.facade.enabled.fill ?? .mvmBlack : buttonModel?.facade.enabled.fill ?? .mvmCoolGray6 backgroundColor = isEnabled ? buttonModel?.facade.enabled.fill ?? .mvmBlack : buttonModel?.facade.disabled.fill ?? .mvmCoolGray6
} }
/// The secondary styling for a button. Should be used for secondary buttons /// The secondary styling for a button. Should be used for secondary buttons
public func styleSecondary() { public func styleSecondary() {
buttonModel?.style = .secondary
enabledTitleColor = buttonModel?.facade.enabled.text ?? .mvmBlack enabledTitleColor = buttonModel?.facade.enabled.text ?? .mvmBlack
disabledTitleColor = buttonModel?.facade.disabled.text ?? .mvmCoolGray6 disabledTitleColor = buttonModel?.facade.disabled.text ?? .mvmCoolGray6
backgroundColor = .clear backgroundColor = .clear
layer.borderWidth = buttonModel?.facade.getBorderWidth() ?? 1 layer.borderWidth = buttonModel?.facade.getBorderWidth() ?? 1
borderColor = isEnabled ? buttonModel?.facade.enabled.border ?? .mvmBlack : buttonModel?.facade.enabled.border ?? .mvmCoolGray6 borderColor = isEnabled ? buttonModel?.facade.enabled.border ?? .mvmBlack : buttonModel?.facade.disabled.border ?? .mvmCoolGray6
} }
/// Styles the button based on the model style /// Styles the button based on the model style
@ -130,10 +123,14 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
switch buttonSize { switch buttonSize {
case .tiny: case .tiny:
return MFSizeObject(standardSize: Height.tiny.rawValue, standardiPadPortraitSize: 34, iPadProLandscapeSize: 38)?.getValueBased(onSize: size) ?? Height.tiny.rawValue return MFSizeObject(standardSize: Styler.Button.Height.tiny.rawValue,
standardiPadPortraitSize: 34,
iPadProLandscapeSize: 38)?.getValueBased(onSize: size) ?? Styler.Button.Height.tiny.rawValue
default: default:
return MFSizeObject(standardSize: Height.standard.rawValue, standardiPadPortraitSize: 46, iPadProLandscapeSize: 50)?.getValueBased(onSize: size) ?? Height.standard.rawValue return MFSizeObject(standardSize: Styler.Button.Height.standard.rawValue,
standardiPadPortraitSize: 46,
iPadProLandscapeSize: 50)?.getValueBased(onSize: size) ?? Styler.Button.Height.standard.rawValue
} }
} }
@ -172,8 +169,6 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
}) })
} }
style()
FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate) FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate)
} }
@ -189,10 +184,10 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
switch buttonModel?.size { switch buttonModel?.size {
case .tiny: case .tiny:
titleLabel?.font = MFFonts.mfFont75Bd(11 * (intrinsicContentSize.height / Height.tiny.rawValue)) titleLabel?.font = MFFonts.mfFont75Bd(11 * (intrinsicContentSize.height / Styler.Button.Height.tiny.rawValue))
default: default:
titleLabel?.font = MFFonts.mfFont75Bd(13 * (intrinsicContentSize.height / Height.standard.rawValue)) titleLabel?.font = MFFonts.mfFont75Bd(13 * (intrinsicContentSize.height / Styler.Button.Height.standard.rawValue))
} }
layer.cornerRadius = getInnerPadding() layer.cornerRadius = getInnerPadding()

View File

@ -140,6 +140,7 @@ import UIKit
if let secondaryModel = model.secondaryButton { if let secondaryModel = model.secondaryButton {
showSecondaryButton() showSecondaryButton()
secondaryModel.style = .secondary
secondaryButton.set(with: secondaryModel, delegateObject, additionalData) secondaryButton.set(with: secondaryModel, delegateObject, additionalData)
} else { } else {
hideSecondaryButton() hideSecondaryButton()
@ -147,6 +148,7 @@ import UIKit
if let primaryModel = model.primaryButton { if let primaryModel = model.primaryButton {
showPrimaryButton() showPrimaryButton()
primaryModel.style = .primary
primaryButton.set(with: primaryModel, delegateObject, additionalData) primaryButton.set(with: primaryModel, delegateObject, additionalData)
} else { } else {
hidePrimaryButton() hidePrimaryButton()

View File

@ -180,6 +180,11 @@ open class Styler {
case standard case standard
case tiny case tiny
} }
public enum Height: CGFloat {
case tiny = 20
case standard = 42
}
} }
//-------------------------------------------------- //--------------------------------------------------