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

View File

@ -26,11 +26,6 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
didSet { style() }
}
private enum Height: CGFloat {
case tiny = 20
case standard = 42
}
//--------------------------------------------------
// MARK: - Computed Properties
//--------------------------------------------------
@ -60,22 +55,20 @@ 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?.facade.enabled.text ?? .mvmWhite
disabledTitleColor = buttonModel?.facade.disabled.text ?? .mvmWhite
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
public func styleSecondary() {
buttonModel?.style = .secondary
enabledTitleColor = buttonModel?.facade.enabled.text ?? .mvmBlack
disabledTitleColor = buttonModel?.facade.disabled.text ?? .mvmCoolGray6
backgroundColor = .clear
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
@ -130,10 +123,14 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
switch buttonSize {
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:
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)
}
@ -189,10 +184,10 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
switch buttonModel?.size {
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:
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()

View File

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

View File

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