From 7fb91d9b1ec99d83181ae0952e2bcaab82a55b10 Mon Sep 17 00:00:00 2001 From: Sumanth Nadigadda Date: Tue, 3 May 2022 01:02:25 +0530 Subject: [PATCH] Updating button default style --- .../Atomic/Atoms/Buttons/ButtonModel.swift | 4 +-- .../Atomic/Atoms/Buttons/PillButton.swift | 25 ++++++------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift index 0eea3036..a6453dd5 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift @@ -24,7 +24,7 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat public var action: ActionModelProtocol public var enabled: Bool = true public var width: CGFloat? - public var style: Styler.Button.Style? { + public var style: Styler.Button.Style? = .primary { didSet { guard let style = style else { return } setFacade(by: style) @@ -161,7 +161,7 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat } enabledTextColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark) - enabledFillColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOnlight) + enabledFillColor_inverted = Color(uiColor: UIColor.clear) enabledBorderColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark) disabledTextColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark) disabledBorderColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift index b70f4ccb..7960fd99 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift @@ -76,31 +76,20 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { /// The primary styling for a button. Should be used for main buttons public func stylePrimary() { - enabledTitleColor = buttonModel?.enabledColors.text ?? Color(uiColor: VDSColor.elementsPrimaryOndark).uiColor - disabledTitleColor = buttonModel?.disabledColors.text ?? Color(uiColor: VDSColor.elementsPrimaryOndark).uiColor - layer.borderWidth = 0 - backgroundColor = isEnabled ? buttonModel?.enabledColors.fill ?? Color(uiColor: VDSColor.elementsPrimaryOnlight).uiColor : buttonModel?.disabledColors.fill ?? Color(uiColor: VDSColor.interactiveDisabledOnlight).uiColor + buttonModel?.setPrimaryFacade() } /// The secondary styling for a button. Should be used for secondary buttons public func styleSecondary() { - enabledTitleColor = buttonModel?.enabledColors.text ?? Color(uiColor: VDSColor.elementsPrimaryOnlight).uiColor - disabledTitleColor = buttonModel?.disabledColors.text ?? Color(uiColor: VDSColor.interactiveDisabledOnlight).uiColor - backgroundColor = .clear - layer.borderWidth = buttonModel?.inverted ?? false ? 0 : 1 - borderColor = isEnabled ? buttonModel?.enabledColors.border ?? Color(uiColor: VDSColor.elementsPrimaryOnlight).uiColor : buttonModel?.disabledColors.border ?? Color(uiColor: VDSColor.interactiveDisabledOnlight).uiColor + buttonModel?.setSecondaryFacade() } /// Styles the button based on the model style private func style() { - switch buttonModel?.style { - case .secondary: - styleSecondary() - - default: - stylePrimary() + if buttonModel?.style == .primary { + layer.borderWidth = 0 } if let titleColor = buttonModel?.enabledColors.text { @@ -170,6 +159,8 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { super.set(with: model, delegateObject, additionalData) guard let model = model as? ButtonModel else { return } + + style() setTitle(model.title, for: .normal) if let accessibilityText = model.accessibilityText { accessibilityLabel = accessibilityText @@ -208,10 +199,10 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { layer.cornerRadius = getInnerPadding() contentEdgeInsets = getContentEdgeInsets() - if let contraint = buttonModel?.width, widthConstraint == nil { + if let contraint = buttonModel?.width, (widthConstraint == nil || widthConstraint?.constant != contraint) { widthConstraint = widthAnchor.constraint(equalToConstant: contraint) widthConstraint?.isActive = true - } else { + } else if minimumWidthConstraint == nil { minimumWidthConstraint = widthAnchor.constraint(greaterThanOrEqualToConstant: buttonSize.minimumWidth()) minimumWidthConstraint?.isActive = true }