Merge branch 'bugfix/VDS_Button' into 'feature/VDS_Button'
Button fixes for other containers See merge request BPHV_MIPS/mvm_core_ui!849
This commit is contained in:
commit
8d71311fc4
@ -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? = .primary {
|
||||
public var style: Styler.Button.Style? {
|
||||
didSet {
|
||||
guard let style = style else { return }
|
||||
setFacade(by: style)
|
||||
@ -85,19 +85,21 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
public init(with title: String, action: ActionModelProtocol) {
|
||||
self.title = title
|
||||
self.action = action
|
||||
setFacade(by: style ?? .primary)
|
||||
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)
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -130,16 +132,10 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
|
||||
/// Defines the default appearance for the primary style.
|
||||
func setPrimaryFacade() {
|
||||
|
||||
if enabledFillColor == nil && enabledTextColor == nil {
|
||||
enabledFillColor = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
enabledTextColor = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||
}
|
||||
|
||||
if disabledFillColor == nil && disabledTextColor == nil {
|
||||
disabledFillColor = Color(uiColor: VDSColor.interactiveDisabledOnlight)
|
||||
disabledTextColor = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||
}
|
||||
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)
|
||||
@ -149,17 +145,11 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
||||
|
||||
/// Defines the default appearance for the Secondary style.
|
||||
func setSecondaryFacade() {
|
||||
|
||||
if enabledTextColor == nil && enabledBorderColor == nil {
|
||||
enabledTextColor = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
enabledFillColor = Color(uiColor: UIColor.clear)
|
||||
enabledBorderColor = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||
}
|
||||
|
||||
if disabledTextColor == nil && disabledBorderColor == nil {
|
||||
disabledTextColor = Color(uiColor: VDSColor.interactiveDisabledOnlight)
|
||||
disabledBorderColor = Color(uiColor: VDSColor.interactiveDisabledOnlight)
|
||||
}
|
||||
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)
|
||||
|
||||
@ -23,7 +23,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
||||
|
||||
/// Need to re-style on set.
|
||||
open override var isEnabled: Bool {
|
||||
didSet { style() }
|
||||
didSet { style(with: buttonModel) }
|
||||
}
|
||||
|
||||
open var buttonSize: Styler.Button.Size = .standard {
|
||||
@ -42,10 +42,10 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
||||
//--------------------------------------------------
|
||||
|
||||
@objc public convenience init(asPrimaryButton isPrimary: Bool, makeTiny istiny: Bool) {
|
||||
self.init()
|
||||
model = ButtonModel.init(with: "", action: ActionOpenPageModel(pageType: "noop"))
|
||||
buttonSize = istiny ? .tiny : .standard
|
||||
isPrimary ? stylePrimary() : styleSecondary()
|
||||
let model = ButtonModel(with: "", action: ActionNoopModel())
|
||||
model.style = isPrimary ? .primary : .secondary
|
||||
model.size = istiny ? .tiny : .standard
|
||||
self.init(model: model, nil, nil)
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -76,32 +76,26 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
||||
|
||||
/// The primary styling for a button. Should be used for main buttons
|
||||
public func stylePrimary() {
|
||||
|
||||
buttonModel?.setPrimaryFacade()
|
||||
style()
|
||||
let buttonModel = ButtonModel(primaryButtonWith: "", action: ActionNoopModel())
|
||||
style(with: buttonModel)
|
||||
}
|
||||
|
||||
/// The secondary styling for a button. Should be used for secondary buttons
|
||||
public func styleSecondary() {
|
||||
|
||||
buttonModel?.setSecondaryFacade()
|
||||
style()
|
||||
let buttonModel = ButtonModel(secondaryButtonWith: "", action: ActionNoopModel())
|
||||
style(with: buttonModel)
|
||||
}
|
||||
|
||||
/// Styles the button based on the model style
|
||||
private func style() {
|
||||
private func style(with model: ButtonModel?) {
|
||||
|
||||
if buttonModel?.style == .primary {
|
||||
layer.borderWidth = 0
|
||||
} else if buttonModel?.style == .secondary {
|
||||
layer.borderWidth = 1
|
||||
}
|
||||
layer.borderWidth = model?.style == .secondary ? 1 : 0
|
||||
|
||||
if let titleColor = buttonModel?.enabledColors.text {
|
||||
if let titleColor = model?.enabledColors.text {
|
||||
enabledTitleColor = titleColor
|
||||
}
|
||||
|
||||
if let disabledTitleColor = buttonModel?.disabledColors.text {
|
||||
if let disabledTitleColor = model?.disabledColors.text {
|
||||
self.disabledTitleColor = disabledTitleColor
|
||||
}
|
||||
|
||||
@ -111,19 +105,19 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
||||
#endif
|
||||
|
||||
if isEnabled {
|
||||
if let fillColor = buttonModel?.enabledColors.fill {
|
||||
if let fillColor = model?.enabledColors.fill {
|
||||
backgroundColor = fillColor
|
||||
}
|
||||
|
||||
if let borderColor = buttonModel?.enabledColors.border {
|
||||
if let borderColor = model?.enabledColors.border {
|
||||
self.borderColor = borderColor
|
||||
}
|
||||
} else {
|
||||
if let fillColor = buttonModel?.disabledColors.fill {
|
||||
if let fillColor = model?.disabledColors.fill {
|
||||
backgroundColor = fillColor
|
||||
}
|
||||
|
||||
if let borderColor = buttonModel?.disabledColors.border {
|
||||
if let borderColor = model?.disabledColors.border {
|
||||
self.borderColor = borderColor
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,7 +204,6 @@
|
||||
|
||||
// Sets up to use a button action. Always uses the top view controller
|
||||
PillButton *button = [[PillButton alloc] initAsPrimaryButton:false makeTiny:true];
|
||||
[button styleSecondary];
|
||||
[button setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
|
||||
[button setContentHuggingPriority:800 forAxis:UILayoutConstraintAxisHorizontal];
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user