Updating button default style

This commit is contained in:
Sumanth Nadigadda 2022-05-03 01:02:25 +05:30
parent c2ac51c18c
commit 7fb91d9b1e
2 changed files with 10 additions and 19 deletions

View File

@ -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)

View File

@ -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
}