minor fixes
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
a22bbbc2b3
commit
7687c42fe2
@ -302,8 +302,8 @@
|
|||||||
EA33619D288B1E330071C351 /* Components */ = {
|
EA33619D288B1E330071C351 /* Components */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
5FC35BE128D513EB004EBEAC /* Button */,
|
|
||||||
EA4DB2FE28DCBC1900103EE3 /* Badge */,
|
EA4DB2FE28DCBC1900103EE3 /* Badge */,
|
||||||
|
5FC35BE128D513EB004EBEAC /* Button */,
|
||||||
EAF7F092289985E200B287F5 /* Checkbox */,
|
EAF7F092289985E200B287F5 /* Checkbox */,
|
||||||
EA3362412892EF700071C351 /* Label */,
|
EA3362412892EF700071C351 /* Label */,
|
||||||
EA89200B28B530F0006B9984 /* RadioBox */,
|
EA89200B28B530F0006B9984 /* RadioBox */,
|
||||||
|
|||||||
@ -25,55 +25,34 @@ open class ButtonBase<ModelType: ButtonModel>: UIButton, ModelHandlerable, ViewP
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private var mainStackView: UIStackView = {
|
private var minWidthConstraint: NSLayoutConstraint?
|
||||||
return UIStackView().with {
|
private var widthConstraint: NSLayoutConstraint?
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
private var heightConstraint: NSLayoutConstraint?
|
||||||
$0.alignment = .top
|
|
||||||
$0.axis = .vertical
|
|
||||||
$0.spacing = 0
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
private var buttonWidthConstraint: NSLayoutConstraint?
|
|
||||||
private var buttonHeightConstraint: NSLayoutConstraint?
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private let PaddingOneHalf: CGFloat = 2
|
|
||||||
private let PaddingOne: CGFloat = 4
|
|
||||||
private let PaddingTwo: CGFloat = 8
|
|
||||||
private let PaddingThree: CGFloat = 12
|
|
||||||
private let PaddingFour: CGFloat = 16
|
|
||||||
private let PaddingFive: CGFloat = 24
|
|
||||||
private let PaddingEight: CGFloat = 32
|
|
||||||
private let PaddingTen: CGFloat = 40
|
|
||||||
private let PaddingTwelve: CGFloat = 48
|
|
||||||
private let PaddingEighteen: CGFloat = 72
|
|
||||||
|
|
||||||
@Proxy(\.model.surface)
|
@Proxy(\.model.surface)
|
||||||
open var surface: Surface
|
open var surface: Surface
|
||||||
|
|
||||||
@Proxy(\.model.use)
|
|
||||||
open var use: Use
|
|
||||||
|
|
||||||
open var buttonSize: Use.Size = .large {
|
|
||||||
didSet {
|
|
||||||
model.buttonSize = buttonSize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Proxy(\.model.disabled)
|
@Proxy(\.model.disabled)
|
||||||
open var disabled: Bool {
|
open var disabled: Bool {
|
||||||
didSet {
|
didSet {
|
||||||
self.isEnabled = !disabled
|
isEnabled = !disabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Proxy(\.model.text)
|
||||||
|
open var text: String?
|
||||||
|
|
||||||
open var buttonWidth: CGFloat = 200 {
|
@Proxy(\.model.use)
|
||||||
didSet {
|
open var use: Use
|
||||||
self.updateView(viewModel: model)
|
|
||||||
}
|
@Proxy(\.model.size)
|
||||||
}
|
open var size: ButtonSize
|
||||||
|
|
||||||
|
@Proxy(\.model.width)
|
||||||
|
open var width: CGFloat?
|
||||||
|
|
||||||
open override var isEnabled: Bool {
|
open override var isEnabled: Bool {
|
||||||
get { !model.disabled }
|
get { !model.disabled }
|
||||||
@ -86,10 +65,7 @@ open class ButtonBase<ModelType: ButtonModel>: UIButton, ModelHandlerable, ViewP
|
|||||||
isUserInteractionEnabled = isEnabled
|
isUserInteractionEnabled = isEnabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Proxy(\.model.attributes)
|
|
||||||
open var attributes: [any LabelAttributeModel]?
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Configuration Properties
|
// MARK: - Configuration Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -173,13 +149,21 @@ open class ButtonBase<ModelType: ButtonModel>: UIButton, ModelHandlerable, ViewP
|
|||||||
}
|
}
|
||||||
|
|
||||||
open func setup() {
|
open func setup() {
|
||||||
self.translatesAutoresizingMaskIntoConstraints = false
|
translatesAutoresizingMaskIntoConstraints = false
|
||||||
mainStackView.addArrangedSubview(self)
|
titleLabel?.adjustsFontSizeToFitWidth = false
|
||||||
mainStackView.spacing = 12
|
titleLabel?.lineBreakMode = .byTruncatingTail
|
||||||
|
|
||||||
|
//only 1 of the 2 widths can be on at the same time
|
||||||
|
widthConstraint = widthAnchor.constraint(equalToConstant: 0)
|
||||||
|
minWidthConstraint = widthAnchor.constraint(greaterThanOrEqualToConstant: model.size.minimumWidth)
|
||||||
|
|
||||||
|
//height
|
||||||
|
heightConstraint = heightAnchor.constraint(equalToConstant: model.size.height)
|
||||||
|
heightConstraint?.isActive = true
|
||||||
}
|
}
|
||||||
|
|
||||||
open func reset() {
|
open func reset() {
|
||||||
// text = nil
|
model = ModelType()
|
||||||
accessibilityCustomActions = []
|
accessibilityCustomActions = []
|
||||||
accessibilityTraits = .staticText
|
accessibilityTraits = .staticText
|
||||||
}
|
}
|
||||||
@ -188,40 +172,41 @@ open class ButtonBase<ModelType: ButtonModel>: UIButton, ModelHandlerable, ViewP
|
|||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
open func updateView(viewModel: ModelType) {
|
open func updateView(viewModel: ModelType) {
|
||||||
if let text = viewModel.text {
|
|
||||||
self.setTitle(text, for: .normal)
|
let bgColor = buttonBackgroundColorConfiguration.getColor(viewModel)
|
||||||
} else {
|
|
||||||
self.setTitle("No ViewModel Text", for: .normal)
|
|
||||||
}
|
|
||||||
let backgroundColor = buttonBackgroundColorConfiguration.getColor(viewModel)
|
|
||||||
let borderColor = buttonBorderColorConfiguration.getColor(viewModel)
|
let borderColor = buttonBorderColorConfiguration.getColor(viewModel)
|
||||||
let borderWidth = viewModel.use == .secondary ? 1.0 : 0.0
|
|
||||||
let titleColor = buttonTitleColorConfiguration.getColor(viewModel)
|
let titleColor = buttonTitleColorConfiguration.getColor(viewModel)
|
||||||
let buttonHeight = viewModel.buttonSize.getHeight()
|
let borderWidth = viewModel.use == .secondary ? 1.0 : 0.0
|
||||||
let minWidth = buttonWidth >= viewModel.buttonSize.minimumWidth() ? buttonWidth : viewModel.buttonSize.minimumWidth()
|
let buttonHeight = viewModel.size.height
|
||||||
|
let cornerRadius = buttonHeight / 2
|
||||||
self.titleLabel?.font = viewModel.buttonSize == .large ? TypographicalStyle.BoldBodyLarge.font : TypographicalStyle.BoldBodySmall.font
|
let minWidth = viewModel.size.minimumWidth
|
||||||
self.backgroundColor = backgroundColor
|
let font = viewModel.size == .large ? TypographicalStyle.BoldBodyLarge.font : TypographicalStyle.BoldBodySmall.font
|
||||||
self.setTitleColor(titleColor, for: .normal)
|
let edgeInsets = viewModel.size.edgeInsets
|
||||||
self.layer.borderColor = borderColor.cgColor
|
|
||||||
self.layer.cornerRadius = buttonHeight / 2
|
|
||||||
self.layer.borderWidth = borderWidth
|
|
||||||
|
|
||||||
if buttonWidthConstraint == nil {
|
if let text = viewModel.text {
|
||||||
buttonWidthConstraint = self.widthAnchor.constraint(equalToConstant: minWidth)
|
setTitle(text, for: .normal)
|
||||||
} else {
|
} else {
|
||||||
buttonWidthConstraint?.constant = minWidth
|
setTitle("No ViewModel Text", for: .normal)
|
||||||
}
|
}
|
||||||
buttonWidthConstraint?.isActive = true
|
titleLabel?.font = font
|
||||||
|
backgroundColor = bgColor
|
||||||
if buttonHeightConstraint == nil {
|
setTitleColor(titleColor, for: .normal)
|
||||||
buttonHeightConstraint = self.heightAnchor.constraint(equalToConstant: buttonHeight)
|
layer.borderColor = borderColor.cgColor
|
||||||
} else {
|
layer.cornerRadius = cornerRadius
|
||||||
buttonHeightConstraint?.constant = buttonHeight
|
layer.borderWidth = borderWidth
|
||||||
}
|
contentEdgeInsets = edgeInsets
|
||||||
buttonHeightConstraint?.isActive = true
|
|
||||||
|
|
||||||
contentEdgeInsets = getContentEdgeInsets(viewModel: viewModel)
|
minWidthConstraint?.constant = minWidth
|
||||||
|
heightConstraint?.constant = buttonHeight
|
||||||
|
|
||||||
|
if let width = viewModel.width, width > minWidth {
|
||||||
|
widthConstraint?.constant = width
|
||||||
|
widthConstraint?.isActive = true
|
||||||
|
minWidthConstraint?.isActive = false
|
||||||
|
} else {
|
||||||
|
widthConstraint?.isActive = false
|
||||||
|
minWidthConstraint?.isActive = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -237,22 +222,52 @@ open class ButtonBase<ModelType: ButtonModel>: UIButton, ModelHandlerable, ViewP
|
|||||||
public func getColor(_ viewModel: ModelType) -> UIColor {
|
public func getColor(_ viewModel: ModelType) -> UIColor {
|
||||||
return viewModel.use == .primary ? primary.getColor(viewModel) : secondary.getColor(viewModel)
|
return viewModel.use == .primary ? primary.getColor(viewModel) : secondary.getColor(viewModel)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension ButtonSize {
|
||||||
|
|
||||||
|
public var height: CGFloat {
|
||||||
|
switch self {
|
||||||
|
case .large:
|
||||||
|
return 44
|
||||||
|
case .small:
|
||||||
|
return 32
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getContentEdgeInsets(viewModel: ModelType) -> UIEdgeInsets {
|
public var minimumWidth: CGFloat {
|
||||||
|
switch self {
|
||||||
|
case .large:
|
||||||
|
return 76
|
||||||
|
case .small:
|
||||||
|
return 60
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public var edgeInsets: UIEdgeInsets {
|
||||||
var verticalPadding = 0.0
|
var verticalPadding = 0.0
|
||||||
var horizontalPadding = 0.0
|
var horizontalPadding = 0.0
|
||||||
switch viewModel.buttonSize {
|
switch self {
|
||||||
case .large:
|
case .large:
|
||||||
verticalPadding = PaddingThree
|
verticalPadding = 12
|
||||||
horizontalPadding = PaddingFive
|
horizontalPadding = 24
|
||||||
break
|
break
|
||||||
case .small:
|
case .small:
|
||||||
verticalPadding = PaddingTwo
|
verticalPadding = 8
|
||||||
horizontalPadding = PaddingFour
|
horizontalPadding = 16
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return UIEdgeInsets(top: verticalPadding, left: horizontalPadding, bottom: verticalPadding, right: horizontalPadding)
|
return UIEdgeInsets(top: verticalPadding, left: horizontalPadding, bottom: verticalPadding, right: horizontalPadding)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Use {
|
||||||
|
|
||||||
|
public var color: UIColor {
|
||||||
|
return self == .primary ? VDSColor.backgroundPrimaryDark : .clear
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -8,40 +8,27 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public protocol ButtonModel: Modelable, Useable, Equatable, AnyEquatable {
|
public enum ButtonSize: String, Codable, CaseIterable {
|
||||||
|
case large
|
||||||
|
case small
|
||||||
|
}
|
||||||
|
|
||||||
|
public protocol ButtonModel: Modelable, Useable {
|
||||||
var text: String? { get set }
|
var text: String? { get set }
|
||||||
var attributes: [any LabelAttributeModel]? { get set }
|
var width: CGFloat? { get set }
|
||||||
var buttonWidth: CGFloat? { get set }
|
var size: ButtonSize { get set }
|
||||||
var buttonSize: Use.Size { get set }
|
|
||||||
var use: Use { get set }
|
var use: Use { get set }
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct DefaultButtonModel: ButtonModel {
|
public struct DefaultButtonModel: ButtonModel {
|
||||||
|
|
||||||
public static func == (lhs: DefaultButtonModel, rhs: DefaultButtonModel) -> Bool {
|
|
||||||
lhs.isEqual(rhs)
|
|
||||||
}
|
|
||||||
|
|
||||||
public func isEqual(_ equatable: DefaultButtonModel) -> Bool {
|
|
||||||
return id == equatable.id
|
|
||||||
&& attributes == equatable.attributes
|
|
||||||
&& text == equatable.text
|
|
||||||
&& surface == equatable.surface
|
|
||||||
&& use == equatable.use
|
|
||||||
&& typograpicalStyle == equatable.typograpicalStyle
|
|
||||||
&& disabled == equatable.disabled
|
|
||||||
&& buttonWidth == equatable.buttonWidth
|
|
||||||
&& buttonSize == equatable.buttonSize
|
|
||||||
}
|
|
||||||
|
|
||||||
public var id = UUID()
|
public var id = UUID()
|
||||||
public var text: String?
|
public var text: String?
|
||||||
public var attributes: [any LabelAttributeModel]?
|
|
||||||
public var typograpicalStyle: TypographicalStyle = .BoldBodyLarge
|
public var typograpicalStyle: TypographicalStyle = .BoldBodyLarge
|
||||||
public var surface: Surface = .light
|
public var surface: Surface = .light
|
||||||
public var use: Use = .primary
|
public var use: Use = .primary
|
||||||
public var disabled: Bool = false
|
public var disabled: Bool = false
|
||||||
public var buttonWidth: CGFloat?
|
public var width: CGFloat?
|
||||||
public var buttonSize: Use.Size = .large
|
public var size: ButtonSize = .large
|
||||||
public init(){}
|
public init(){}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,31 +11,6 @@ import VDSColorTokens
|
|||||||
|
|
||||||
public enum Use: String, Codable, Equatable {
|
public enum Use: String, Codable, Equatable {
|
||||||
case primary, secondary
|
case primary, secondary
|
||||||
public var color: UIColor {
|
|
||||||
return self == .primary ? VDSColor.backgroundPrimaryDark : .clear
|
|
||||||
}
|
|
||||||
public enum Size: String, Codable {
|
|
||||||
case large
|
|
||||||
case small
|
|
||||||
|
|
||||||
func getHeight() -> CGFloat {
|
|
||||||
switch self {
|
|
||||||
case .large:
|
|
||||||
return 44
|
|
||||||
case .small:
|
|
||||||
return 32
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func minimumWidth() -> CGFloat {
|
|
||||||
switch self {
|
|
||||||
case .large:
|
|
||||||
return 76
|
|
||||||
case .small:
|
|
||||||
return 60
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public protocol Useable {
|
public protocol Useable {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user