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 {
|
internal var label = Label().with {
|
||||||
$0.isAccessibilityElement = false
|
$0.isAccessibilityElement = true
|
||||||
$0.lineBreakMode = .byWordWrapping
|
$0.lineBreakMode = .byWordWrapping
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var index = 0
|
internal var index = 0
|
||||||
|
internal var strikethroughLocation = 0
|
||||||
|
internal var strikethroughlength = 0
|
||||||
|
|
||||||
internal var textContentType:TextContentType = .preDelimiter
|
internal var textContentType:TextContentType = .preDelimiter
|
||||||
enum TextContentType: String, CaseIterable {
|
enum TextContentType: String, CaseIterable {
|
||||||
@ -177,7 +179,7 @@ open class PriceLockup: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var kindViewColorConfiguration: ViewColorConfiguration {
|
private var textColorConfiguration: ViewColorConfiguration {
|
||||||
switch kind {
|
switch kind {
|
||||||
|
|
||||||
case .primary:
|
case .primary:
|
||||||
@ -195,9 +197,7 @@ open class PriceLockup: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var heightConstraint: NSLayoutConstraint?
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -218,15 +218,13 @@ open class PriceLockup: View {
|
|||||||
containerView.addSubview(label)
|
containerView.addSubview(label)
|
||||||
label.pinToSuperView()
|
label.pinToSuperView()
|
||||||
label.centerXAnchor.constraint(equalTo: centerXAnchor).activate()
|
label.centerXAnchor.constraint(equalTo: centerXAnchor).activate()
|
||||||
heightConstraint = label.heightAnchor.constraint(equalToConstant: 0)
|
|
||||||
heightConstraint?.activate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateLabel() {
|
func updateLabel() {
|
||||||
var attributes: [any LabelAttributeModel] = []
|
var attributes: [any LabelAttributeModel] = []
|
||||||
let colorAttr = ColorLabelAttribute(location: 0,
|
let colorAttr = ColorLabelAttribute(location: 0,
|
||||||
length: label.text.count,
|
length: label.text.count,
|
||||||
color: kindViewColorConfiguration.getColor(self))
|
color: textColorConfiguration.getColor(self))
|
||||||
attributes.append(colorAttr)
|
attributes.append(colorAttr)
|
||||||
if index > 0 {
|
if index > 0 {
|
||||||
textContentType = .preDelimiter
|
textContentType = .preDelimiter
|
||||||
@ -252,6 +250,18 @@ open class PriceLockup: View {
|
|||||||
// Set the attributed text
|
// Set the attributed text
|
||||||
updateLabel()
|
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 {
|
if uniformSize {
|
||||||
// currency and value have the same font text style as delimeter, term, trailing text and superscript.
|
// currency and value have the same font text style as delimeter, term, trailing text and superscript.
|
||||||
textContentType = .postDelimiter
|
textContentType = .postDelimiter
|
||||||
@ -262,7 +272,6 @@ open class PriceLockup: View {
|
|||||||
}
|
}
|
||||||
label.attributes = uniformSizeAttributes
|
label.attributes = uniformSizeAttributes
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resets to default settings.
|
/// Resets to default settings.
|
||||||
@ -293,12 +302,15 @@ open class PriceLockup: View {
|
|||||||
index = index + leadingStr.count + 1
|
index = index + leadingStr.count + 1
|
||||||
}
|
}
|
||||||
if let value = price {
|
if let value = price {
|
||||||
|
strikethroughLocation = index
|
||||||
let valueStr = "\(value)"
|
let valueStr = "\(value)"
|
||||||
text = text + currency + valueStr
|
text = text + currency + valueStr
|
||||||
index = index + valueStr.count + 1
|
index = index + valueStr.count + 1
|
||||||
|
strikethroughlength = valueStr.count + 1
|
||||||
}
|
}
|
||||||
if term != .none {
|
if term != .none {
|
||||||
text = text + "/" + term.text
|
text = text + "/" + term.text
|
||||||
|
strikethroughlength = strikethroughlength + term.text.count + 1
|
||||||
}
|
}
|
||||||
if let trailingStr = trailingText {
|
if let trailingStr = trailingText {
|
||||||
text = text + " " + trailingStr
|
text = text + " " + trailingStr
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user