diff --git a/VDS/Components/PriceLockup/PriceLockup.swift b/VDS/Components/PriceLockup/PriceLockup.swift index 6f6b21b5..0c776377 100644 --- a/VDS/Components/PriceLockup/PriceLockup.swift +++ b/VDS/Components/PriceLockup/PriceLockup.swift @@ -99,24 +99,24 @@ open class PriceLockup: View { /// Currency - If hideCurrency true, the component will render without currency. open var hideCurrency: Bool = false { didSet { setNeedsUpdate() } } - + /// Leading text for the component. open var leadingText: String? { didSet { setNeedsUpdate() } } - + /// Value rendered for the component. open var price: Float? { didSet { setNeedsUpdate() } } /// Color to the component. The default kind is primary. open var kind: Kind = Kind.defaultValue { didSet { setNeedsUpdate() } } - + /// Size of the component. It varies by size and viewport(mobile/Tablet). /// The default size is medium with viewport mobile. open var size: Size = Size.defaultValue { didSet { setNeedsUpdate() } } - + /// If true, the component with a strikethrough. It applies only when uniformSize is true. /// Does not apply a strikethrough format to leading and trailing text. open var strikethrough: Bool = false { didSet { setNeedsUpdate() } } - + /// Term text for the component. The default term is 'month'. /// Superscript placement can vary when term and delimeter are "none". open var term: Term = Term.defaultValue { didSet { setNeedsUpdate() } } @@ -130,7 +130,7 @@ open class PriceLockup: View { /// If true, currency and value have the same font text style as delimeter, term label and superscript. /// This will render the pricing and term sections as a uniform size. open var uniformSize: Bool = false { didSet { setNeedsUpdate() } } - + //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- @@ -142,7 +142,7 @@ open class PriceLockup: View { internal var delimiterIndex = 0 internal var strikethroughLocation = 0 internal var strikethroughLength = 0 - + internal var textPosition:TextPosition = .preDelimiter enum TextPosition: String, CaseIterable { case preDelimiter, postDelimiter @@ -152,7 +152,8 @@ open class PriceLockup: View { // MARK: - Configuration Properties //-------------------------------------------------- internal var containerSize: CGSize { CGSize(width: 45, height: 44) } - + + // TextStyle for the size. private var textStyle: TextStyle.StandardStyle { switch (size, textPosition) { case (.xxxsmall, .preDelimiter), (.xxxsmall, .postDelimiter): @@ -175,19 +176,19 @@ open class PriceLockup: View { case (.large, .preDelimiter): return UIDevice.isIPad ? .titleMedium : .titleLarge - + case (.large, .postDelimiter): return UIDevice.isIPad ? .titleSmall : .titleMedium - + case (.xlarge, .preDelimiter): return UIDevice.isIPad ? .titleLarge : .titleXLarge - + case (.xlarge, .postDelimiter): return UIDevice.isIPad ? .titleMedium : .titleLarge - + case (.xxlarge, .preDelimiter): return UIDevice.isIPad ? .titleXLarge : .featureSmall - + case (.xxlarge, .postDelimiter): return UIDevice.isIPad ? .titleLarge : .titleXLarge } @@ -204,11 +205,11 @@ open class PriceLockup: View { addSubview(priceLockupLabel) priceLockupLabel.pinToSuperView() } - + /// Used to make changes to the View based off a change events or from local properties. open override func updateView() { super.updateView() - + priceLockupLabel.text = fetchText() priceLockupLabel.surface = surface @@ -224,10 +225,11 @@ open class PriceLockup: View { shouldUpdateView = true setNeedsUpdate() } - + //-------------------------------------------------- // MARK: - Private Methods //-------------------------------------------------- + // Update PriceLockup text attributes func updateLabelAttributes() { var attributes: [any LabelAttributeModel] = [] attributes.append(ColorLabelAttribute(location: 0, @@ -242,6 +244,7 @@ open class PriceLockup: View { textStyle: bold ? textStyle.bold : textStyle.regular, textPosition: .left)) attributes.append(StrikeThroughLabelAttribute(location:strikethroughLocation, length: strikethroughLength)) + } else if uniformSize { // currency and value have the same font text style as delimeter, term, trailing text and superscript. @@ -249,6 +252,7 @@ open class PriceLockup: View { length: priceLockupLabel.text.count, textStyle: bold ? textStyle.bold : textStyle.regular, textPosition: .left)) + } else { // size updates relative to predelimiter, postdelimiter @@ -269,6 +273,7 @@ open class PriceLockup: View { priceLockupLabel.attributes = attributes } + // Get text for PriceLockup. open func fetchText() -> String { var text : String = "" let space = " " @@ -302,6 +307,6 @@ open class PriceLockup: View { extension Float { // remove a decimal from a float if the decimal is equal to 0 var clean: String { - return self.truncatingRemainder(dividingBy: 1) == 0 ? String(format: "%.0f", self) : String(self) + return self.truncatingRemainder(dividingBy: 1) == 0 ? String(format: "%.0f", self) : String(self) } }