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