Digital ACT-191 ONEAPP-9314 story: update label with strikethrough if its enabled, and other minor changes
This commit is contained in:
parent
1bb54d174f
commit
73db6dff2d
@ -121,11 +121,13 @@ open class PriceLockup: View {
|
||||
}
|
||||
|
||||
internal var label = Label().with {
|
||||
$0.isAccessibilityElement = false
|
||||
$0.isAccessibilityElement = true
|
||||
$0.lineBreakMode = .byWordWrapping
|
||||
}
|
||||
|
||||
internal var index = 0
|
||||
internal var strikethroughLocation = 0
|
||||
internal var strikethroughlength = 0
|
||||
|
||||
internal var textContentType:TextContentType = .preDelimiter
|
||||
enum TextContentType: String, CaseIterable {
|
||||
@ -177,7 +179,7 @@ open class PriceLockup: View {
|
||||
}
|
||||
}
|
||||
|
||||
private var kindViewColorConfiguration: ViewColorConfiguration {
|
||||
private var textColorConfiguration: ViewColorConfiguration {
|
||||
switch kind {
|
||||
|
||||
case .primary:
|
||||
@ -195,9 +197,7 @@ open class PriceLockup: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var heightConstraint: NSLayoutConstraint?
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Overrides
|
||||
//--------------------------------------------------
|
||||
@ -218,15 +218,13 @@ open class PriceLockup: View {
|
||||
containerView.addSubview(label)
|
||||
label.pinToSuperView()
|
||||
label.centerXAnchor.constraint(equalTo: centerXAnchor).activate()
|
||||
heightConstraint = label.heightAnchor.constraint(equalToConstant: 0)
|
||||
heightConstraint?.activate()
|
||||
}
|
||||
|
||||
func updateLabel() {
|
||||
var attributes: [any LabelAttributeModel] = []
|
||||
let colorAttr = ColorLabelAttribute(location: 0,
|
||||
length: label.text.count,
|
||||
color: kindViewColorConfiguration.getColor(self))
|
||||
color: textColorConfiguration.getColor(self))
|
||||
attributes.append(colorAttr)
|
||||
if index > 0 {
|
||||
textContentType = .preDelimiter
|
||||
@ -252,6 +250,18 @@ open class PriceLockup: View {
|
||||
// Set the attributed text
|
||||
updateLabel()
|
||||
|
||||
if strikethrough {
|
||||
// strike applies only when uniformSize true. Does not apply a strikethrough format to leading, trailing, and superscript text.
|
||||
textContentType = .postDelimiter
|
||||
var strikethroughAttributes: [any LabelAttributeModel]? {
|
||||
[TextStyleLabelAttribute(location: 0,
|
||||
length: label.text.count,
|
||||
textStyle: contentFontSize),
|
||||
StrikeThroughLabelAttribute(location:strikethroughLocation, length: strikethroughlength)]
|
||||
}
|
||||
label.attributes = strikethroughAttributes
|
||||
}
|
||||
|
||||
if uniformSize {
|
||||
// currency and value have the same font text style as delimeter, term, trailing text and superscript.
|
||||
textContentType = .postDelimiter
|
||||
@ -262,7 +272,6 @@ open class PriceLockup: View {
|
||||
}
|
||||
label.attributes = uniformSizeAttributes
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Resets to default settings.
|
||||
@ -293,12 +302,15 @@ open class PriceLockup: View {
|
||||
index = index + leadingStr.count + 1
|
||||
}
|
||||
if let value = price {
|
||||
strikethroughLocation = index
|
||||
let valueStr = "\(value)"
|
||||
text = text + currency + valueStr
|
||||
index = index + valueStr.count + 1
|
||||
strikethroughlength = valueStr.count + 1
|
||||
}
|
||||
if term != .none {
|
||||
text = text + "/" + term.text
|
||||
strikethroughlength = strikethroughlength + term.text.count + 1
|
||||
}
|
||||
if let trailingStr = trailingText {
|
||||
text = text + " " + trailingStr
|
||||
|
||||
Loading…
Reference in New Issue
Block a user