From 73db6dff2df9f5cb94bd27c90c81398a09ea810a Mon Sep 17 00:00:00 2001 From: Vasavi Kanamarlapudi Date: Wed, 14 Aug 2024 14:53:27 +0530 Subject: [PATCH] Digital ACT-191 ONEAPP-9314 story: update label with strikethrough if its enabled, and other minor changes --- VDS/Components/PriceLockup/PriceLockup.swift | 30 ++++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/VDS/Components/PriceLockup/PriceLockup.swift b/VDS/Components/PriceLockup/PriceLockup.swift index 3bac1779..6cda4cf4 100644 --- a/VDS/Components/PriceLockup/PriceLockup.swift +++ b/VDS/Components/PriceLockup/PriceLockup.swift @@ -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