updated defaults into initializers
update all initializers to look the same Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
92c8c1073f
commit
19a7ba5627
@ -20,6 +20,10 @@ public class Badge: View, Accessable {
|
|||||||
|
|
||||||
private var label = Label().with {
|
private var label = Label().with {
|
||||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
$0.adjustsFontSizeToFitWidth = false
|
||||||
|
$0.lineBreakMode = .byTruncatingTail
|
||||||
|
$0.textPosition = .left
|
||||||
|
$0.typograpicalStyle = .BoldBodySmall
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -64,8 +68,6 @@ public class Badge: View, Accessable {
|
|||||||
addSubview(label)
|
addSubview(label)
|
||||||
|
|
||||||
layer.cornerRadius = 2
|
layer.cornerRadius = 2
|
||||||
label.adjustsFontSizeToFitWidth = false
|
|
||||||
label.lineBreakMode = .byTruncatingTail
|
|
||||||
|
|
||||||
label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 4).isActive = true
|
label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 4).isActive = true
|
||||||
label.topAnchor.constraint(equalTo: topAnchor, constant: 2).isActive = true
|
label.topAnchor.constraint(equalTo: topAnchor, constant: 2).isActive = true
|
||||||
@ -75,6 +77,7 @@ public class Badge: View, Accessable {
|
|||||||
maxWidthConstraint = label.widthAnchor.constraint(lessThanOrEqualToConstant: 100)
|
maxWidthConstraint = label.widthAnchor.constraint(lessThanOrEqualToConstant: 100)
|
||||||
minWidthConstraint = label.widthAnchor.constraint(greaterThanOrEqualToConstant: 23)
|
minWidthConstraint = label.widthAnchor.constraint(greaterThanOrEqualToConstant: 23)
|
||||||
minWidthConstraint?.isActive = true
|
minWidthConstraint?.isActive = true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func reset() {
|
public override func reset() {
|
||||||
@ -162,10 +165,9 @@ public class Badge: View, Accessable {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
open override func updateView() {
|
open override func updateView() {
|
||||||
backgroundColor = backgroundColor()
|
backgroundColor = backgroundColor()
|
||||||
|
|
||||||
label.textColorConfiguration = textColorConfiguration()
|
label.textColorConfiguration = textColorConfiguration()
|
||||||
label.numberOfLines = numberOfLines
|
label.numberOfLines = numberOfLines
|
||||||
label.textPosition = .left
|
|
||||||
label.typograpicalStyle = .BoldBodySmall
|
|
||||||
label.text = text
|
label.text = text
|
||||||
label.surface = surface
|
label.surface = surface
|
||||||
label.disabled = disabled
|
label.disabled = disabled
|
||||||
|
|||||||
@ -55,49 +55,47 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private var mainStackView: UIStackView = {
|
private var mainStackView = UIStackView().with {
|
||||||
return UIStackView().with {
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.alignment = .top
|
||||||
$0.alignment = .top
|
$0.axis = .vertical
|
||||||
$0.axis = .vertical
|
}
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
private var selectorStackView: UIStackView = {
|
private var selectorStackView = UIStackView().with {
|
||||||
return UIStackView().with {
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.alignment = .top
|
||||||
$0.alignment = .top
|
$0.axis = .horizontal
|
||||||
$0.axis = .horizontal
|
}
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
private var selectorLabelStackView: UIStackView = {
|
private var selectorLabelStackView = UIStackView().with {
|
||||||
return UIStackView().with {
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.axis = .vertical
|
||||||
$0.axis = .vertical
|
}
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
private var primaryLabel = Label().with {
|
private var primaryLabel = Label().with {
|
||||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
$0.textPosition = .left
|
||||||
|
$0.typograpicalStyle = .BoldBodyLarge
|
||||||
}
|
}
|
||||||
|
|
||||||
private var secondaryLabel = Label().with {
|
private var secondaryLabel = Label().with {
|
||||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
$0.textPosition = .left
|
||||||
|
$0.typograpicalStyle = .BodyLarge
|
||||||
}
|
}
|
||||||
|
|
||||||
private var errorLabel = Label().with {
|
private var errorLabel = Label().with {
|
||||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
$0.textPosition = .left
|
||||||
|
$0.typograpicalStyle = .BodyMedium
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Public Properties
|
// MARK: - Public Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public var selectorView: UIView = {
|
public var selectorView = UIView().with {
|
||||||
return UIView().with {
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
}
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
//can't bind to @Proxy
|
//can't bind to @Proxy
|
||||||
open override var isSelected: Bool { didSet { didChange() }}
|
open override var isSelected: Bool { didSet { didChange() }}
|
||||||
@ -206,8 +204,6 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er
|
|||||||
//add the stackview to hold the 2 labels
|
//add the stackview to hold the 2 labels
|
||||||
//top label
|
//top label
|
||||||
if let labelText {
|
if let labelText {
|
||||||
primaryLabel.textPosition = .left
|
|
||||||
primaryLabel.typograpicalStyle = .BoldBodyLarge
|
|
||||||
primaryLabel.surface = surface
|
primaryLabel.surface = surface
|
||||||
primaryLabel.disabled = disabled
|
primaryLabel.disabled = disabled
|
||||||
primaryLabel.attributes = labelTextAttributes
|
primaryLabel.attributes = labelTextAttributes
|
||||||
@ -222,8 +218,6 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er
|
|||||||
|
|
||||||
//bottom label
|
//bottom label
|
||||||
if let childText {
|
if let childText {
|
||||||
secondaryLabel.textPosition = .left
|
|
||||||
secondaryLabel.typograpicalStyle = .BodyLarge
|
|
||||||
secondaryLabel.text = childText
|
secondaryLabel.text = childText
|
||||||
secondaryLabel.surface = surface
|
secondaryLabel.surface = surface
|
||||||
secondaryLabel.disabled = disabled
|
secondaryLabel.disabled = disabled
|
||||||
@ -248,8 +242,6 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er
|
|||||||
|
|
||||||
//either add/remove the error from the main stack
|
//either add/remove the error from the main stack
|
||||||
if let errorText, shouldShowError {
|
if let errorText, shouldShowError {
|
||||||
errorLabel.textPosition = .left
|
|
||||||
errorLabel.typograpicalStyle = .BodyMedium
|
|
||||||
errorLabel.text = errorText
|
errorLabel.text = errorText
|
||||||
errorLabel.surface = surface
|
errorLabel.surface = surface
|
||||||
errorLabel.disabled = disabled
|
errorLabel.disabled = disabled
|
||||||
|
|||||||
@ -46,51 +46,52 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private var mainStackView: UIStackView = {
|
private var mainStackView = UIStackView().with {
|
||||||
return UIStackView().with {
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.alignment = .top
|
||||||
$0.alignment = .top
|
$0.axis = .vertical
|
||||||
$0.axis = .vertical
|
$0.spacing = 0
|
||||||
$0.spacing = 0
|
}
|
||||||
}
|
|
||||||
}()
|
private var selectorStackView = UIStackView().with {
|
||||||
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
$0.alignment = .top
|
||||||
|
$0.axis = .horizontal
|
||||||
|
$0.spacing = 12
|
||||||
|
}
|
||||||
|
|
||||||
private var selectorStackView: UIStackView = {
|
private var selectorLeftLabelStackView = UIStackView().with {
|
||||||
return UIStackView().with {
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.axis = .vertical
|
||||||
$0.alignment = .top
|
$0.spacing = 4
|
||||||
$0.axis = .horizontal
|
$0.isHidden = false
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
|
|
||||||
private var selectorLeftLabelStackView: UIStackView = {
|
|
||||||
return UIStackView().with {
|
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
$0.axis = .vertical
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
private var textLabel = Label().with {
|
private var textLabel = Label().with {
|
||||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
$0.textPosition = .left
|
||||||
|
$0.typograpicalStyle = .BoldBodyLarge
|
||||||
}
|
}
|
||||||
|
|
||||||
private var subTextLabel = Label().with {
|
private var subTextLabel = Label().with {
|
||||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
$0.textPosition = .left
|
||||||
|
$0.typograpicalStyle = .BodyLarge
|
||||||
}
|
}
|
||||||
|
|
||||||
private var subTextRightLabel = Label().with {
|
private var subTextRightLabel = Label().with {
|
||||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
$0.textPosition = .right
|
||||||
|
$0.typograpicalStyle = .BodyLarge
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Public Properties
|
// MARK: - Public Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public var selectorView: UIView = {
|
public var selectorView = UIView().with {
|
||||||
return UIView().with {
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
}
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
open var text: String = "Default Text" { didSet { didChange() }}
|
open var text: String = "Default Text" { didSet { didChange() }}
|
||||||
|
|
||||||
open var textAttributes: [any LabelAttributeModel]? { didSet { didChange() }}
|
open var textAttributes: [any LabelAttributeModel]? { didSet { didChange() }}
|
||||||
@ -177,10 +178,6 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{
|
|||||||
selectorLeftLabelStackView.addArrangedSubview(textLabel)
|
selectorLeftLabelStackView.addArrangedSubview(textLabel)
|
||||||
selectorLeftLabelStackView.addArrangedSubview(subTextLabel)
|
selectorLeftLabelStackView.addArrangedSubview(subTextLabel)
|
||||||
|
|
||||||
selectorStackView.spacing = 12
|
|
||||||
selectorLeftLabelStackView.spacing = 4
|
|
||||||
selectorLeftLabelStackView.isHidden = false
|
|
||||||
|
|
||||||
updateSelector()
|
updateSelector()
|
||||||
|
|
||||||
selectorView.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
selectorView.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
||||||
@ -192,15 +189,12 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{
|
|||||||
mainStackView.leadingAnchor.constraint(equalTo: selectorView.leadingAnchor, constant: 16).isActive = true
|
mainStackView.leadingAnchor.constraint(equalTo: selectorView.leadingAnchor, constant: 16).isActive = true
|
||||||
mainStackView.trailingAnchor.constraint(equalTo: selectorView.trailingAnchor, constant: -16).isActive = true
|
mainStackView.trailingAnchor.constraint(equalTo: selectorView.trailingAnchor, constant: -16).isActive = true
|
||||||
mainStackView.bottomAnchor.constraint(equalTo: selectorView.bottomAnchor, constant: -16).isActive = true
|
mainStackView.bottomAnchor.constraint(equalTo: selectorView.bottomAnchor, constant: -16).isActive = true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateLabels() {
|
func updateLabels() {
|
||||||
|
|
||||||
//add the stackview to hold the 2 labels
|
//add the stackview to hold the 2 labels
|
||||||
//text label
|
//text label
|
||||||
textLabel.textPosition = .left
|
|
||||||
textLabel.typograpicalStyle = .BoldBodyLarge
|
|
||||||
textLabel.text = text
|
textLabel.text = text
|
||||||
textLabel.surface = surface
|
textLabel.surface = surface
|
||||||
textLabel.disabled = disabled
|
textLabel.disabled = disabled
|
||||||
@ -208,8 +202,6 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{
|
|||||||
|
|
||||||
//subText label
|
//subText label
|
||||||
if let subText {
|
if let subText {
|
||||||
subTextLabel.textPosition = .left
|
|
||||||
subTextLabel.typograpicalStyle = .BodyLarge
|
|
||||||
subTextLabel.text = subText
|
subTextLabel.text = subText
|
||||||
subTextLabel.surface = surface
|
subTextLabel.surface = surface
|
||||||
subTextLabel.disabled = disabled
|
subTextLabel.disabled = disabled
|
||||||
@ -225,8 +217,6 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{
|
|||||||
|
|
||||||
//subTextRight label
|
//subTextRight label
|
||||||
if let subTextRight {
|
if let subTextRight {
|
||||||
subTextRightLabel.textPosition = .right
|
|
||||||
subTextRightLabel.typograpicalStyle = .BodyLarge
|
|
||||||
subTextRightLabel.text = subTextRight
|
subTextRightLabel.text = subTextRight
|
||||||
subTextRightLabel.surface = surface
|
subTextRightLabel.surface = surface
|
||||||
subTextRightLabel.disabled = disabled
|
subTextRightLabel.disabled = disabled
|
||||||
|
|||||||
@ -49,7 +49,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
|
|||||||
public required init?(coder: NSCoder) {
|
public required init?(coder: NSCoder) {
|
||||||
super.init(coder: coder)
|
super.init(coder: coder)
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -62,29 +62,23 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
|
|||||||
guard labelText?.isEmpty == false || childText?.isEmpty == false || labelAttributedText?.string.isEmpty == false || childAttributedText?.string.isEmpty == false else { return false }
|
guard labelText?.isEmpty == false || childText?.isEmpty == false || labelAttributedText?.string.isEmpty == false || childAttributedText?.string.isEmpty == false else { return false }
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private var mainStackView: UIStackView = {
|
|
||||||
return UIStackView().with {
|
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
$0.alignment = .top
|
|
||||||
$0.axis = .vertical
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
private var selectorStackView: UIStackView = {
|
private var mainStackView = UIStackView().with {
|
||||||
return UIStackView().with {
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.alignment = .top
|
||||||
$0.alignment = .top
|
$0.axis = .vertical
|
||||||
$0.axis = .horizontal
|
}
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
private var selectorLabelStackView: UIStackView = {
|
private var selectorStackView = UIStackView().with {
|
||||||
return UIStackView().with {
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.alignment = .top
|
||||||
$0.axis = .vertical
|
$0.axis = .horizontal
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
|
private var selectorLabelStackView = UIStackView().with {
|
||||||
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
$0.axis = .vertical
|
||||||
|
}
|
||||||
|
|
||||||
private var primaryLabel = Label().with {
|
private var primaryLabel = Label().with {
|
||||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
@ -97,20 +91,18 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
|
|||||||
private var errorLabel = Label().with {
|
private var errorLabel = Label().with {
|
||||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Public Properties
|
// MARK: - Public Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public var selectorView: UIView = {
|
public var selectorView = UIView().with {
|
||||||
return UIView().with {
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
}
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
open var labelText: String? { didSet { didChange() }}
|
open var labelText: String? { didSet { didChange() }}
|
||||||
|
|
||||||
open var labelTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }}
|
open var labelTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }}
|
||||||
|
|
||||||
open var labelAttributedText: NSAttributedString? {
|
open var labelAttributedText: NSAttributedString? {
|
||||||
didSet {
|
didSet {
|
||||||
primaryLabel.useAttributedText = !(labelAttributedText?.string.isEmpty ?? true)
|
primaryLabel.useAttributedText = !(labelAttributedText?.string.isEmpty ?? true)
|
||||||
@ -118,9 +110,9 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
|
|||||||
didChange()
|
didChange()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open var childText: String? { didSet { didChange() }}
|
open var childText: String? { didSet { didChange() }}
|
||||||
|
|
||||||
open var childTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }}
|
open var childTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }}
|
||||||
|
|
||||||
open var childAttributedText: NSAttributedString? {
|
open var childAttributedText: NSAttributedString? {
|
||||||
@ -130,21 +122,21 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
|
|||||||
didChange()
|
didChange()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open var showError: Bool = false { didSet { didChange() }}
|
open var showError: Bool = false { didSet { didChange() }}
|
||||||
|
|
||||||
open var errorText: String? { didSet { didChange() }}
|
open var errorText: String? { didSet { didChange() }}
|
||||||
|
|
||||||
open var inputId: String? { didSet { didChange() }}
|
open var inputId: String? { didSet { didChange() }}
|
||||||
|
|
||||||
open var value: AnyHashable? { didSet { didChange() }}
|
open var value: AnyHashable? { didSet { didChange() }}
|
||||||
|
|
||||||
open var dataAnalyticsTrack: String? { didSet { didChange() }}
|
open var dataAnalyticsTrack: String? { didSet { didChange() }}
|
||||||
|
|
||||||
open var dataClickStream: String? { didSet { didChange() }}
|
open var dataClickStream: String? { didSet { didChange() }}
|
||||||
|
|
||||||
open var dataTrack: String? { didSet { didChange() }}
|
open var dataTrack: String? { didSet { didChange() }}
|
||||||
|
|
||||||
open var accessibilityHintEnabled: String? { didSet { didChange() }}
|
open var accessibilityHintEnabled: String? { didSet { didChange() }}
|
||||||
|
|
||||||
open var accessibilityHintDisabled: String? { didSet { didChange() }}
|
open var accessibilityHintDisabled: String? { didSet { didChange() }}
|
||||||
@ -156,7 +148,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
|
|||||||
open var accessibilityLabelEnabled: String? { didSet { didChange() }}
|
open var accessibilityLabelEnabled: String? { didSet { didChange() }}
|
||||||
|
|
||||||
open var accessibilityLabelDisabled: String? { didSet { didChange() }}
|
open var accessibilityLabelDisabled: String? { didSet { didChange() }}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Constraints
|
// MARK: - Constraints
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -168,7 +160,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Lifecycle
|
// MARK: - Lifecycle
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
|
|
||||||
@ -187,32 +179,39 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
|
|||||||
selectorStackView.addArrangedSubview(selectorLabelStackView)
|
selectorStackView.addArrangedSubview(selectorLabelStackView)
|
||||||
selectorLabelStackView.addArrangedSubview(primaryLabel)
|
selectorLabelStackView.addArrangedSubview(primaryLabel)
|
||||||
selectorLabelStackView.addArrangedSubview(secondaryLabel)
|
selectorLabelStackView.addArrangedSubview(secondaryLabel)
|
||||||
|
|
||||||
let selectorSize = getSelectorSize()
|
let selectorSize = getSelectorSize()
|
||||||
selectorHeightConstraint = selectorView.heightAnchor.constraint(equalToConstant: selectorSize.height)
|
selectorHeightConstraint = selectorView.heightAnchor.constraint(equalToConstant: selectorSize.height)
|
||||||
selectorHeightConstraint?.isActive = true
|
selectorHeightConstraint?.isActive = true
|
||||||
|
|
||||||
selectorWidthConstraint = selectorView.widthAnchor.constraint(equalToConstant: selectorSize.width)
|
selectorWidthConstraint = selectorView.widthAnchor.constraint(equalToConstant: selectorSize.width)
|
||||||
selectorWidthConstraint?.isActive = true
|
selectorWidthConstraint?.isActive = true
|
||||||
|
|
||||||
updateSelector()
|
updateSelector()
|
||||||
|
|
||||||
mainStackView.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
mainStackView.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
||||||
mainStackView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
mainStackView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
||||||
mainStackView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
|
mainStackView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
|
||||||
mainStackView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
|
mainStackView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
|
||||||
|
|
||||||
|
//defaults
|
||||||
|
primaryLabel.textPosition = .left
|
||||||
|
primaryLabel.typograpicalStyle = .BoldBodyLarge
|
||||||
|
|
||||||
|
secondaryLabel.textPosition = .left
|
||||||
|
secondaryLabel.typograpicalStyle = .BodyLarge
|
||||||
|
|
||||||
|
errorLabel.textPosition = .left
|
||||||
|
errorLabel.typograpicalStyle = .BodyMedium
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateLabels() {
|
func updateLabels() {
|
||||||
|
|
||||||
//deal with labels
|
//deal with labels
|
||||||
if shouldShowLabels {
|
if shouldShowLabels {
|
||||||
//add the stackview to hold the 2 labels
|
//add the stackview to hold the 2 labels
|
||||||
//top label
|
//top label
|
||||||
if let labelText {
|
if let labelText {
|
||||||
primaryLabel.textPosition = .left
|
|
||||||
primaryLabel.typograpicalStyle = .BoldBodyLarge
|
|
||||||
primaryLabel.text = labelText
|
primaryLabel.text = labelText
|
||||||
primaryLabel.surface = surface
|
primaryLabel.surface = surface
|
||||||
primaryLabel.disabled = disabled
|
primaryLabel.disabled = disabled
|
||||||
@ -221,15 +220,13 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
|
|||||||
|
|
||||||
} else if labelAttributedText != nil {
|
} else if labelAttributedText != nil {
|
||||||
primaryLabel.isHidden = false
|
primaryLabel.isHidden = false
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
primaryLabel.isHidden = true
|
primaryLabel.isHidden = true
|
||||||
}
|
}
|
||||||
|
|
||||||
//bottom label
|
//bottom label
|
||||||
if let childText {
|
if let childText {
|
||||||
secondaryLabel.textPosition = .left
|
|
||||||
secondaryLabel.typograpicalStyle = .BodyLarge
|
|
||||||
secondaryLabel.text = childText
|
secondaryLabel.text = childText
|
||||||
secondaryLabel.surface = surface
|
secondaryLabel.surface = surface
|
||||||
secondaryLabel.disabled = disabled
|
secondaryLabel.disabled = disabled
|
||||||
@ -238,7 +235,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
|
|||||||
|
|
||||||
} else if childAttributedText != nil {
|
} else if childAttributedText != nil {
|
||||||
secondaryLabel.isHidden = false
|
secondaryLabel.isHidden = false
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
secondaryLabel.isHidden = true
|
secondaryLabel.isHidden = true
|
||||||
}
|
}
|
||||||
@ -254,8 +251,6 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
|
|||||||
|
|
||||||
//either add/remove the error from the main stack
|
//either add/remove the error from the main stack
|
||||||
if let errorText, shouldShowError {
|
if let errorText, shouldShowError {
|
||||||
errorLabel.textPosition = .left
|
|
||||||
errorLabel.typograpicalStyle = .BodyMedium
|
|
||||||
errorLabel.text = errorText
|
errorLabel.text = errorText
|
||||||
errorLabel.surface = surface
|
errorLabel.surface = surface
|
||||||
errorLabel.disabled = disabled
|
errorLabel.disabled = disabled
|
||||||
@ -273,11 +268,11 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
|
|||||||
updateSelector()
|
updateSelector()
|
||||||
setAccessibilityLabel()
|
setAccessibilityLabel()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This will checkbox the state of the Selector and execute the actionBlock if provided.
|
/// This will checkbox the state of the Selector and execute the actionBlock if provided.
|
||||||
open func toggle() {
|
open func toggle() {
|
||||||
guard !isSelected else { return }
|
guard !isSelected else { return }
|
||||||
|
|
||||||
//removed error
|
//removed error
|
||||||
if showError && isSelected == false {
|
if showError && isSelected == false {
|
||||||
showError.toggle()
|
showError.toggle()
|
||||||
@ -285,10 +280,10 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
|
|||||||
isSelected.toggle()
|
isSelected.toggle()
|
||||||
sendActions(for: .valueChanged)
|
sendActions(for: .valueChanged)
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - State
|
// MARK: - State
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
open override func updateView() {
|
open override func updateView() {
|
||||||
updateLabels()
|
updateLabels()
|
||||||
updateSelector()
|
updateSelector()
|
||||||
@ -353,7 +348,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
|
|||||||
let bounds = selectorView.bounds
|
let bounds = selectorView.bounds
|
||||||
let length = max(bounds.size.height, bounds.size.width)
|
let length = max(bounds.size.height, bounds.size.width)
|
||||||
guard length > 0.0, shapeLayer == nil else { return }
|
guard length > 0.0, shapeLayer == nil else { return }
|
||||||
|
|
||||||
//get the colors
|
//get the colors
|
||||||
let backgroundColor = radioButtonBackgroundColorConfiguration.getColor(self)
|
let backgroundColor = radioButtonBackgroundColorConfiguration.getColor(self)
|
||||||
let borderColor = radioButtonBorderColorConfiguration.getColor(self)
|
let borderColor = radioButtonBorderColorConfiguration.getColor(self)
|
||||||
@ -367,9 +362,9 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
|
|||||||
if shapeLayer == nil {
|
if shapeLayer == nil {
|
||||||
let selectedBounds = radioButtonSelectedSize
|
let selectedBounds = radioButtonSelectedSize
|
||||||
let bezierPath = UIBezierPath(ovalIn: CGRect(x: (bounds.width - selectedBounds.width) / 2,
|
let bezierPath = UIBezierPath(ovalIn: CGRect(x: (bounds.width - selectedBounds.width) / 2,
|
||||||
y: (bounds.height - selectedBounds.height) / 2,
|
y: (bounds.height - selectedBounds.height) / 2,
|
||||||
width: radioButtonSelectedSize.width,
|
width: radioButtonSelectedSize.width,
|
||||||
height: radioButtonSelectedSize.height))
|
height: radioButtonSelectedSize.height))
|
||||||
let shapeLayer = CAShapeLayer()
|
let shapeLayer = CAShapeLayer()
|
||||||
self.shapeLayer = shapeLayer
|
self.shapeLayer = shapeLayer
|
||||||
shapeLayer.frame = bounds
|
shapeLayer.frame = bounds
|
||||||
|
|||||||
@ -43,18 +43,14 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Public Properties
|
// MARK: - Public Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public var selectorView: UIView = {
|
public var selectorView = UIView().with {
|
||||||
return UIView().with {
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
}
|
||||||
}
|
|
||||||
}()
|
public var fillView = UIImageView().with {
|
||||||
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
public var fillView: UIImageView = {
|
$0.contentMode = .scaleAspectFit
|
||||||
return UIImageView().with {
|
}
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
$0.contentMode = .scaleAspectFit
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
open var fillImage: UIImage? { didSet { didChange() }}
|
open var fillImage: UIImage? { didSet { didChange() }}
|
||||||
|
|
||||||
|
|||||||
@ -58,34 +58,28 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
|
|||||||
public required init?(coder: NSCoder) {
|
public required init?(coder: NSCoder) {
|
||||||
super.init(coder: coder)
|
super.init(coder: coder)
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private var stackView: UIStackView = {
|
private var stackView = UIStackView().with {
|
||||||
return UIStackView().with {
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.axis = .horizontal
|
||||||
$0.axis = .horizontal
|
$0.distribution = .fill
|
||||||
$0.distribution = .fill
|
}
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
private var label = Label().with {
|
private var label = Label().with {
|
||||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var toggleView: UIView = {
|
private var toggleView = UIView().with {
|
||||||
return UIView().with {
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
}
|
||||||
}
|
|
||||||
}()
|
private var knobView = UIView().with {
|
||||||
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
private var knobView: UIView = {
|
$0.backgroundColor = .white
|
||||||
return UIView().with {
|
}
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
$0.backgroundColor = .white
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Configuration Properties
|
// MARK: - Configuration Properties
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user