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:
Matt Bruce 2022-11-10 15:10:18 -06:00
parent 92c8c1073f
commit 19a7ba5627
6 changed files with 135 additions and 166 deletions

View File

@ -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

View File

@ -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

View File

@ -46,50 +46,51 @@ 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 = { 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 $0.spacing = 12
} }
}()
private var selectorLeftLabelStackView: UIStackView = { private var selectorLeftLabelStackView = UIStackView().with {
return UIStackView().with { $0.translatesAutoresizingMaskIntoConstraints = false
$0.translatesAutoresizingMaskIntoConstraints = false $0.axis = .vertical
$0.axis = .vertical $0.spacing = 4
} $0.isHidden = false
}() }
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() }}
@ -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

View File

@ -63,28 +63,22 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
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)
@ -101,11 +95,9 @@ open class RadioButtonBase: 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 }
}
}()
open var labelText: String? { didSet { didChange() }} open var labelText: String? { didSet { didChange() }}
@ -202,6 +194,15 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
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() {
@ -211,8 +212,6 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
//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
@ -228,8 +227,6 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable,
//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
@ -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
@ -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

View File

@ -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 = { public var fillView = UIImageView().with {
return UIImageView().with { $0.translatesAutoresizingMaskIntoConstraints = false
$0.translatesAutoresizingMaskIntoConstraints = false $0.contentMode = .scaleAspectFit
$0.contentMode = .scaleAspectFit }
}
}()
open var fillImage: UIImage? { didSet { didChange() }} open var fillImage: UIImage? { didSet { didChange() }}

View File

@ -62,30 +62,24 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable {
//-------------------------------------------------- //--------------------------------------------------
// 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 = { private var knobView = UIView().with {
return UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false
$0.translatesAutoresizingMaskIntoConstraints = false $0.backgroundColor = .white
$0.backgroundColor = .white }
}
}()
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Configuration Properties // MARK: - Configuration Properties