Changes to add button width constraints
This commit is contained in:
parent
064533950e
commit
8f234259b0
@ -35,6 +35,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
||||
//--------------------------------------------------
|
||||
|
||||
public var widthConstraint: NSLayoutConstraint?
|
||||
public var minimumWidthConstraint: NSLayoutConstraint?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
@ -75,8 +76,8 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
||||
/// The primary styling for a button. Should be used for main buttons
|
||||
public func stylePrimary() {
|
||||
|
||||
enabledTitleColor = buttonModel?.enabledColors.text ?? .mvmWhite
|
||||
disabledTitleColor = buttonModel?.disabledColors.text ?? .mvmWhite
|
||||
enabledTitleColor = buttonModel?.enabledColors.text ?? Color(uiColor: VDSColor.elementsSecondaryOnlight).uiColor
|
||||
disabledTitleColor = buttonModel?.disabledColors.text ?? Color(uiColor: VDSColor.elementsSecondaryOnlight).uiColor
|
||||
layer.borderWidth = 0
|
||||
backgroundColor = isEnabled ? buttonModel?.enabledColors.fill ?? Color(uiColor: VDSColor.elementsPrimaryOnlight).uiColor : buttonModel?.disabledColors.fill ?? Color(uiColor: VDSColor.elementsPrimaryOndark).uiColor
|
||||
}
|
||||
@ -137,13 +138,9 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
||||
}
|
||||
|
||||
private func getInnerPadding() -> CGFloat {
|
||||
getHeight() / 2.0
|
||||
buttonSize.getHeight() / 2.0
|
||||
}
|
||||
|
||||
private func getHeight() -> CGFloat {
|
||||
PillButton.getHeight(for: buttonSize, size: size)
|
||||
}
|
||||
|
||||
|
||||
private func getContentEdgeInsets() -> UIEdgeInsets {
|
||||
var verticalPadding = 0.0
|
||||
var horizontalPadding = 0.0
|
||||
@ -161,28 +158,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
||||
}
|
||||
return UIEdgeInsets(top: verticalPadding, left: horizontalPadding, bottom: verticalPadding, right: horizontalPadding)
|
||||
}
|
||||
|
||||
public static func getHeight(for buttonSize: Styler.Button.Size?, size: CGFloat) -> CGFloat {
|
||||
|
||||
switch buttonSize {
|
||||
case .tiny:
|
||||
let tinyHeight = Styler.Button.Size.tiny.getHeight()
|
||||
return MFSizeObject(standardSize: tinyHeight,
|
||||
standardiPadPortraitSize: 34,
|
||||
iPadProLandscapeSize: 38)?.getValueBased(onSize: size) ?? tinyHeight
|
||||
case .small:
|
||||
let smallHeight = Styler.Button.Size.small.getHeight()
|
||||
return MFSizeObject(standardSize: smallHeight,
|
||||
standardiPadPortraitSize: 34,
|
||||
iPadProLandscapeSize: 38)?.getValueBased(onSize: size) ?? smallHeight
|
||||
default:
|
||||
let standardHeight = Styler.Button.Size.standard.getHeight()
|
||||
return MFSizeObject(standardSize: standardHeight,
|
||||
standardiPadPortraitSize: 46,
|
||||
iPadProLandscapeSize: 50)?.getValueBased(onSize: size) ?? standardHeight
|
||||
}
|
||||
}
|
||||
|
||||
private func getMinimumWidth() -> CGFloat {
|
||||
|
||||
switch buttonSize {
|
||||
@ -229,7 +205,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
||||
}
|
||||
|
||||
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||
PillButton.getHeight(for: (model as? ButtonModel)?.size, size: MVMCoreUIUtility.getWidth())
|
||||
return (model as? ButtonModel)?.size?.getHeight()
|
||||
}
|
||||
|
||||
open override func updateView(_ size: CGFloat) {
|
||||
@ -248,9 +224,10 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
||||
layer.cornerRadius = getInnerPadding()
|
||||
contentEdgeInsets = getContentEdgeInsets()
|
||||
|
||||
if let contraint = buttonModel?.width, contraint != widthConstraint?.constant {
|
||||
if let contraint = buttonModel?.width, widthConstraint == nil {
|
||||
widthConstraint = widthAnchor.constraint(equalToConstant: contraint)
|
||||
widthConstraint?.isActive = true
|
||||
minimumWidthConstraint?.isActive = false
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,8 +240,10 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
||||
contentHorizontalAlignment = .center
|
||||
stylePrimary()
|
||||
|
||||
widthConstraint = widthAnchor.constraint(greaterThanOrEqualToConstant: getMinimumWidth())
|
||||
widthConstraint?.isActive = true
|
||||
widthConstraint?.isActive = false
|
||||
|
||||
minimumWidthConstraint = widthAnchor.constraint(greaterThanOrEqualToConstant: getMinimumWidth())
|
||||
minimumWidthConstraint?.isActive = true
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user