Merge branch 'develop' into feature/accessibilityHandler
This commit is contained in:
commit
3900294189
@ -27,54 +27,12 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
public var action: ActionModelProtocol
|
||||
public var enabled: Bool = true
|
||||
public var width: CGFloat?
|
||||
public var style: Use? {
|
||||
didSet {
|
||||
guard let style = style else { return }
|
||||
setFacade(by: style)
|
||||
}
|
||||
}
|
||||
public var style: Use = .primary
|
||||
public var size: VDS.Button.Size = .large
|
||||
public var groupName: String = ""
|
||||
public var inverted: Bool = false
|
||||
|
||||
public lazy var enabledColors: FacadeElements = (fill: enabled_fillColor(),
|
||||
text: enabled_textColor(),
|
||||
border: enabled_borderColor())
|
||||
|
||||
public lazy var disabledColors: FacadeElements = (fill: disabled_fillColor(),
|
||||
text: disabled_textColor(),
|
||||
border: disabled_borderColor())
|
||||
|
||||
public var enabledFillColor: Color?
|
||||
public var enabledTextColor: Color?
|
||||
public var enabledBorderColor: Color?
|
||||
|
||||
public var enabledFillColor_inverted: Color?
|
||||
public var enabledTextColor_inverted: Color?
|
||||
public var enabledBorderColor_inverted: Color?
|
||||
|
||||
public var disabledFillColor: Color?
|
||||
public var disabledTextColor: Color?
|
||||
public var disabledBorderColor: Color?
|
||||
|
||||
public var disabledFillColor_inverted: Color?
|
||||
public var disabledTextColor_inverted: Color?
|
||||
public var disabledBorderColor_inverted: Color?
|
||||
|
||||
private var _backgroundColor: Color?
|
||||
public var backgroundColor: Color? {
|
||||
get {
|
||||
if let backgroundColor = _backgroundColor { return backgroundColor }
|
||||
if inverted {
|
||||
return enabled ? enabledFillColor_inverted : disabledFillColor_inverted
|
||||
}
|
||||
return enabled ? enabledFillColor : disabledFillColor
|
||||
}
|
||||
set {
|
||||
_backgroundColor = newValue
|
||||
}
|
||||
}
|
||||
|
||||
public var backgroundColor: Color?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Methods
|
||||
//--------------------------------------------------
|
||||
@ -88,88 +46,18 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
public init(with title: String, action: ActionModelProtocol) {
|
||||
self.title = title
|
||||
self.action = action
|
||||
setFacade(by: .primary)
|
||||
}
|
||||
|
||||
public init(secondaryButtonWith title: String, action: ActionModelProtocol) {
|
||||
self.title = title
|
||||
self.action = action
|
||||
style = .secondary
|
||||
setFacade(by: .secondary)
|
||||
}
|
||||
|
||||
public init(primaryButtonWith title: String, action: ActionModelProtocol) {
|
||||
self.title = title
|
||||
self.action = action
|
||||
style = .primary
|
||||
setFacade(by: .primary)
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Methods
|
||||
//--------------------------------------------------
|
||||
|
||||
public func enabled_fillColor() -> UIColor? {
|
||||
(inverted ? enabledFillColor_inverted : enabledFillColor)?.uiColor
|
||||
}
|
||||
|
||||
public func enabled_textColor() -> UIColor? {
|
||||
(inverted ? enabledTextColor_inverted : enabledTextColor)?.uiColor
|
||||
}
|
||||
|
||||
public func enabled_borderColor() -> UIColor? {
|
||||
(inverted ? enabledBorderColor_inverted : enabledBorderColor)?.uiColor
|
||||
}
|
||||
|
||||
public func disabled_fillColor() -> UIColor? {
|
||||
(inverted ? disabledFillColor_inverted : disabledFillColor)?.uiColor
|
||||
}
|
||||
|
||||
public func disabled_textColor() -> UIColor? {
|
||||
(inverted ? disabledTextColor_inverted : disabledTextColor)?.uiColor
|
||||
}
|
||||
|
||||
public func disabled_borderColor() -> UIColor? {
|
||||
(inverted ? disabledBorderColor_inverted : disabledBorderColor)?.uiColor
|
||||
}
|
||||
|
||||
/// Defines the default appearance for the primary style.
|
||||
func setPrimaryFacade() {
|
||||
enabledFillColor = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
enabledTextColor = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||
disabledFillColor = Color(uiColor: VDSColor.interactiveDisabledOnlight)
|
||||
disabledTextColor = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||
|
||||
enabledFillColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||
enabledTextColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
disabledFillColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark)
|
||||
disabledTextColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
}
|
||||
|
||||
/// Defines the default appearance for the Secondary style.
|
||||
func setSecondaryFacade() {
|
||||
enabledTextColor = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
enabledFillColor = Color(uiColor: UIColor.clear)
|
||||
enabledBorderColor = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
disabledTextColor = Color(uiColor: VDSColor.interactiveDisabledOnlight)
|
||||
disabledBorderColor = Color(uiColor: VDSColor.interactiveDisabledOnlight)
|
||||
|
||||
enabledTextColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||
enabledFillColor_inverted = Color(uiColor: UIColor.clear)
|
||||
enabledBorderColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||
disabledTextColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark)
|
||||
disabledBorderColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark)
|
||||
}
|
||||
|
||||
public func setFacade(by style: VDS.Use) {
|
||||
switch style {
|
||||
case .primary:
|
||||
setPrimaryFacade()
|
||||
case .secondary:
|
||||
setSecondaryFacade()
|
||||
@unknown default:
|
||||
setPrimaryFacade()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -179,7 +67,6 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case id
|
||||
case moleculeName
|
||||
case backgroundColor
|
||||
case accessibilityIdentifier
|
||||
case accessibilityText
|
||||
case title
|
||||
@ -189,12 +76,6 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
case style
|
||||
case size
|
||||
case groupName
|
||||
case fillColor
|
||||
case textColor
|
||||
case borderColor
|
||||
case disabledFillColor
|
||||
case disabledTextColor
|
||||
case disabledBorderColor
|
||||
case width
|
||||
}
|
||||
|
||||
@ -214,12 +95,8 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
///Style captured from the JSON
|
||||
if let style = try typeContainer.decodeIfPresent(Use.self, forKey: .style) {
|
||||
self.style = style
|
||||
setFacade(by: style)
|
||||
} else if let style = decoder.context?.value(forKey: CodingKeys.style.stringValue) as? Use { ///Reading the style param from context which is set is molecules, ex: TwoButtonView
|
||||
self.style = style
|
||||
setFacade(by: style)
|
||||
} else { ///Default style
|
||||
setFacade(by: .primary)
|
||||
}
|
||||
|
||||
if let size = try typeContainer.decodeIfPresent(VDS.Button.Size.self, forKey: .size) {
|
||||
@ -230,40 +107,57 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
self.enabled = enabled
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
width = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .width)
|
||||
|
||||
if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) {
|
||||
self.inverted = inverted
|
||||
} else {
|
||||
try setInverted(deprecatedFrom: decoder)
|
||||
}
|
||||
}
|
||||
|
||||
private enum DeprecatedCodingKeys: String, CodingKey {
|
||||
case fillColor
|
||||
case textColor
|
||||
case borderColor
|
||||
case backgroundColor
|
||||
}
|
||||
|
||||
private func setInverted(deprecatedFrom decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: DeprecatedCodingKeys.self)
|
||||
if let enabledFillColor = try typeContainer.decodeIfPresent(Color.self, forKey: .fillColor) {
|
||||
self.enabledFillColor = enabledFillColor
|
||||
if (self.style == .secondary) {
|
||||
self.inverted = enabledFillColor.uiColor.isDark()
|
||||
} else {
|
||||
self.inverted = !enabledFillColor.uiColor.isDark()
|
||||
}
|
||||
}
|
||||
|
||||
if let enabledTextColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor) {
|
||||
self.enabledTextColor = enabledTextColor
|
||||
if (self.style == .secondary) {
|
||||
self.inverted = !enabledTextColor.uiColor.isDark()
|
||||
} else {
|
||||
self.inverted = enabledTextColor.uiColor.isDark()
|
||||
}
|
||||
}
|
||||
|
||||
if let enabledBorderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) {
|
||||
self.enabledBorderColor = enabledBorderColor
|
||||
if (self.style == .secondary) {
|
||||
self.inverted = !enabledBorderColor.uiColor.isDark()
|
||||
}
|
||||
}
|
||||
|
||||
if let disabledFillColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledFillColor) {
|
||||
self.disabledFillColor = disabledFillColor
|
||||
|
||||
if let backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) {
|
||||
if (self.style == .secondary) {
|
||||
self.inverted = backgroundColor.uiColor.isDark()
|
||||
} else {
|
||||
self.inverted = !backgroundColor.uiColor.isDark()
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
width = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .width)
|
||||
}
|
||||
|
||||
open func encode(to encoder: Encoder) throws {
|
||||
@ -274,17 +168,10 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
try container.encode(enabled, forKey: .enabled)
|
||||
try container.encode(inverted, forKey: .inverted)
|
||||
try container.encodeModel(action, forKey: .action)
|
||||
try container.encodeIfPresent(_backgroundColor, forKey: .backgroundColor)
|
||||
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
|
||||
try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText)
|
||||
try container.encodeIfPresent(enabledFillColor, forKey: .fillColor)
|
||||
try container.encodeIfPresent(enabledTextColor, forKey: .textColor)
|
||||
try container.encodeIfPresent(enabledBorderColor, forKey: .borderColor)
|
||||
try container.encodeIfPresent(disabledFillColor, forKey: .disabledFillColor)
|
||||
try container.encodeIfPresent(disabledTextColor, forKey: .disabledTextColor)
|
||||
try container.encodeIfPresent(disabledBorderColor, forKey: .disabledBorderColor)
|
||||
try container.encodeIfPresent(style, forKey: .style)
|
||||
try container.encodeIfPresent(size, forKey: .size)
|
||||
try container.encode(style, forKey: .style)
|
||||
try container.encode(size, forKey: .size)
|
||||
try container.encodeIfPresent(groupName, forKey: .groupName)
|
||||
try container.encodeIfPresent(width, forKey: .width)
|
||||
}
|
||||
|
||||
@ -93,11 +93,9 @@ open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol {
|
||||
button?.style = .secondary
|
||||
switch style {
|
||||
case .error, .warning:
|
||||
button?.enabledTextColor = Color(uiColor: .mvmBlack)
|
||||
button?.enabledBorderColor = Color(uiColor: .mvmBlack)
|
||||
button?.inverted = false
|
||||
default:
|
||||
button?.enabledTextColor = Color(uiColor: .mvmWhite)
|
||||
button?.enabledBorderColor = Color(uiColor: .mvmWhite)
|
||||
button?.inverted = true
|
||||
}
|
||||
|
||||
if closeButton?.color == nil {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user