From bba4cbfb66e0ad3bf7c4b41b4d0a43e309af16bd Mon Sep 17 00:00:00 2001 From: Sumanth Nadigadda Date: Sat, 5 Jun 2021 00:05:54 +0530 Subject: [PATCH] Option to set 'numberOfLines' for label from label's json. --- MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift | 4 ++++ .../Atomic/Atoms/Views/Label/LabelModel.swift | 15 +++++++++++++++ ...stLeftVariableIconWithRightCaretBodyText.swift | 3 +++ 3 files changed, 22 insertions(+) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index 026e9acf..09ed3386 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -315,6 +315,10 @@ public typealias ActionBlock = () -> () if let color = labelModel.textColor { textColor = color.uiColor } + + if let numberofLines = labelModel.numberOfLines { + numberOfLines = numberofLines + } if let attributes = labelModel.attributes, let labelText = text { let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: font.updateSize(standardFontSize), NSAttributedString.Key.foregroundColor: textColor as UIColor]) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/LabelModel.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/LabelModel.swift index fbbc9e03..8aa4c0d6 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/LabelModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/LabelModel.swift @@ -25,6 +25,7 @@ public var html: String? public var hero: Int? public var makeWholeViewClickable: Bool? + public var numberOfLines:Int? //-------------------------------------------------- // MARK: - Keys @@ -44,18 +45,30 @@ case html case hero case makeWholeViewClickable + case numberOfLines } enum AttributeTypeKey: String, CodingKey { case type } + //----------------------------------------------------- + // MARK: - Methods + //----------------------------------------------------- + + internal func setDefaults() { + if numberOfLines == nil { + numberOfLines = 1 + } + } + //-------------------------------------------------- // MARK: - Initializer //-------------------------------------------------- public init(text: String) { self.text = text + setDefaults() } //-------------------------------------------------- @@ -76,6 +89,7 @@ html = try typeContainer.decodeIfPresent(String.self, forKey: .html) hero = try typeContainer.decodeIfPresent(Int.self, forKey: .hero) makeWholeViewClickable = try typeContainer.decodeIfPresent(Bool.self, forKey: .makeWholeViewClickable) + numberOfLines = try typeContainer.decodeIfPresent(Int.self, forKey: .numberOfLines) } public func encode(to encoder: Encoder) throws { @@ -93,5 +107,6 @@ try container.encodeIfPresent(html, forKey: .html) try container.encodeIfPresent(hero, forKey: .hero) try container.encodeIfPresent(makeWholeViewClickable, forKey: .makeWholeViewClickable) + try container.encodeIfPresent(numberOfLines, forKey: .numberOfLines) } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift index b9e4a3e1..feb8694d 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift @@ -73,6 +73,9 @@ headlineBody.set(with: model.headlineBody, delegateObject, additionalData) rightLabel.set(with: model.rightLabel, delegateObject, additionalData) updateAccessibilityLabel() + if let numberOfLines = model.rightLabel.numberOfLines{ + rightLabel.numberOfLines = numberOfLines + } } open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {