From 8b0d208047f66d01eba28c4a04244876c52c126c Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 2 Dec 2019 15:59:44 -0500 Subject: [PATCH 01/17] Current solution to widow word. --- MVMCoreUI/Atoms/Views/Label.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 8474d74a..d677cf4b 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -685,13 +685,20 @@ extension Label { /// Converts the entire text into a link. All characters will be underlined and the intrinsic bounds will respond to tap. @objc public func makeTextButton(actionBlock: @escaping ActionBlock) { - + setTextLinkState(range: getRange, actionBlock: actionBlock) } /// Underlines the tappable region and stores the tap logic for interation. private func setTextLinkState(range: NSRange, actionBlock: @escaping ActionBlock) { + if clauses.isEmpty { + // Replace the last whitespace with \u{00A0} No-break space. + if let start = text?.lastIndex(of: " "), let end = text?.index(after: start) { + text?.replaceSubrange(start.. Date: Wed, 4 Dec 2019 15:52:18 -0500 Subject: [PATCH 02/17] This needs to be broken down and understood, but the code is here and at least functional. --- MVMCoreUI/Atoms/Views/Label.swift | 61 ++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index d677cf4b..544f7666 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -695,7 +695,7 @@ extension Label { if clauses.isEmpty { // Replace the last whitespace with \u{00A0} No-break space. if let start = text?.lastIndex(of: " "), let end = text?.index(after: start) { - text?.replaceSubrange(start.. [Any] { + + if lineBreakMode != .byWordWrapping { + lineBreakMode = .byWordWrapping + } + + var lines = [Any]() /* capacity: 10 */ + let wordSeparators = CharacterSet.whitespacesAndNewlines + var currentLine: String? = self.text + let textLength: Int = (self.text?.count ?? 0) + var rCurrentLine = NSRange(location: 0, length: textLength) + var rWhitespace = NSRange(location: 0, length: 0) + var rRemainingText = NSRange(location: 0, length: textLength) + var done: Bool = false + + while !done { + // determine the next whitespace word separator position + rWhitespace.location = rWhitespace.location + rWhitespace.length + rWhitespace.length = textLength - rWhitespace.location + rWhitespace = (self.text! as NSString).rangeOfCharacter(from: wordSeparators, options: .caseInsensitive, range: rWhitespace) + if rWhitespace.location == NSNotFound { + rWhitespace.location = textLength + done = true + } + let rTest = NSRange(location: rRemainingText.location, length: rWhitespace.location - rRemainingText.location) + let textTest: String = (self.text! as NSString).substring(with: rTest) + let fontAttributes: [String: Any]? = [NSAttributedString.Key.font.rawValue: font] + let maxWidth = (textTest as NSString).size(withAttributes: [NSAttributedString.Key(rawValue: NSAttributedString.Key.font.rawValue): font]).width + if maxWidth > self.bounds.size.width { + lines.append(currentLine?.trimmingCharacters(in: wordSeparators) ?? "") + rRemainingText.location = rCurrentLine.location + rCurrentLine.length + rRemainingText.length = textLength - rRemainingText.location + continue + } + rCurrentLine = rTest + currentLine = textTest + } + + lines.append(currentLine?.trimmingCharacters(in: wordSeparators) ?? "") + + return lines + } + + open var lastLineWidth: CGFloat { + + let lines: [Any] = self.getSeparatedLines() + + if !lines.isEmpty { + let lastLine: String = (lines.last as? String)! + let fontAttributes = [NSAttributedString.Key.font.rawValue: font] + return (lastLine as NSString).size(withAttributes: [NSAttributedString.Key(rawValue: NSAttributedString.Key.font.rawValue): font]).width + } + + return 0 + } +} + // MARK: - extension UITapGestureRecognizer { From f90fadff85f67f7485bd31f14ebfe32c408205d1 Mon Sep 17 00:00:00 2001 From: Subhankar Date: Tue, 12 Jan 2021 22:28:42 +0530 Subject: [PATCH 03/17] Changes to initialiser of LoadImageView --- .../ListLeftVariableIconWithRightCaretAllTextLinks.swift | 2 +- .../ListLeftVariableIconWithRightCaretBodyText.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinks.swift index d6175136..93d1526f 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinks.swift @@ -11,7 +11,7 @@ // MARK: - Outlets //-------------------------------------------------- - public let leftImage = LoadImageView() + public let leftImage = LoadImageView(pinnedEdges: .all) public let eyebrowHeadlineBodyLink = EyebrowHeadlineBodyLink() public let rightLabel = Label(fontStyle: .RegularBodySmall) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift index 4685cafd..b9e4a3e1 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift @@ -12,7 +12,7 @@ // MARK: - Outlets //-------------------------------------------------- - public let leftImage = LoadImageView() + public let leftImage = LoadImageView(pinnedEdges: .all) public let headlineBody = HeadlineBody() public let rightLabel = Label(fontStyle: .RegularBodySmall) public let rightLabelStackItem: StackItem From 86f397434c82eab32deb6b882f3df95fac56e80d Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 12 Jan 2021 12:36:22 -0500 Subject: [PATCH 04/17] convenience function for uistackview --- MVMCoreUI/Categories/UIStackView+Extension.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/MVMCoreUI/Categories/UIStackView+Extension.swift b/MVMCoreUI/Categories/UIStackView+Extension.swift index b88dfb51..227f057d 100644 --- a/MVMCoreUI/Categories/UIStackView+Extension.swift +++ b/MVMCoreUI/Categories/UIStackView+Extension.swift @@ -14,6 +14,18 @@ extension UIStackView: MVMCoreViewProtocol { (view as? MVMCoreViewProtocol)?.updateView(size) } } + + /// A convenience function for updating molecules. If model is nil, view is hidden. + open func updateContainedMolecules(with models: [MoleculeModelProtocol?], _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + for (index, item) in arrangedSubviews.enumerated() { + if let model = models[index] { + (item as? MoleculeViewProtocol)?.set(with: model, delegateObject, additionalData) + item.isHidden = false + } else { + item.isHidden = true + } + } + } } extension UIStackView: MoleculeViewProtocol { @@ -23,3 +35,4 @@ extension UIStackView: MoleculeViewProtocol { } } } + From 2d2cc92802313dc7d793d5d7226dc7f64c88f138 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 12 Jan 2021 12:58:32 -0500 Subject: [PATCH 05/17] minor ui bugfixes --- .../ListLeftVariableIconWithRightCaretAllTextLinks.swift | 2 +- .../ListLeftVariableIconWithRightCaretBodyText.swift | 2 +- .../ListRightVariableRightCaretAlltextAndLinks.swift | 2 +- MVMCoreUI/Categories/UIStackView+Extension.swift | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinks.swift index d6175136..93d1526f 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretAllTextLinks.swift @@ -11,7 +11,7 @@ // MARK: - Outlets //-------------------------------------------------- - public let leftImage = LoadImageView() + public let leftImage = LoadImageView(pinnedEdges: .all) public let eyebrowHeadlineBodyLink = EyebrowHeadlineBodyLink() public let rightLabel = Label(fontStyle: .RegularBodySmall) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift index 4685cafd..b9e4a3e1 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift @@ -12,7 +12,7 @@ // MARK: - Outlets //-------------------------------------------------- - public let leftImage = LoadImageView() + public let leftImage = LoadImageView(pinnedEdges: .all) public let headlineBody = HeadlineBody() public let rightLabel = Label(fontStyle: .RegularBodySmall) public let rightLabelStackItem: StackItem diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableRightCaretAlltextAndLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableRightCaretAlltextAndLinks.swift index b05098d4..1fbbe114 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableRightCaretAlltextAndLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableRightCaretAlltextAndLinks.swift @@ -21,7 +21,7 @@ //-------------------------------------------------- public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { - stack = Stack.createStack(with: [(view: eyebrowHeadlineBodyLink, model: StackItemModel(horizontalAlignment: .leading, verticalAlignment: .top)), (view: rightLabel, model: StackItemModel(horizontalAlignment:.fill))], axis: .horizontal) + stack = Stack.createStack(with: [(view: eyebrowHeadlineBodyLink, model: StackItemModel(horizontalAlignment: .leading, verticalAlignment: .leading)), (view: rightLabel, model: StackItemModel(horizontalAlignment:.fill))], axis: .horizontal) super.init(style: style, reuseIdentifier: reuseIdentifier) } diff --git a/MVMCoreUI/Categories/UIStackView+Extension.swift b/MVMCoreUI/Categories/UIStackView+Extension.swift index 227f057d..b6bc1b05 100644 --- a/MVMCoreUI/Categories/UIStackView+Extension.swift +++ b/MVMCoreUI/Categories/UIStackView+Extension.swift @@ -25,6 +25,7 @@ extension UIStackView: MVMCoreViewProtocol { item.isHidden = true } } + layoutIfNeeded() } } From 80b1f02cff51080456348f40beae7afe092342f0 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 13 Jan 2021 09:37:10 -0500 Subject: [PATCH 06/17] bug fix ListRightVariableRightCaretAlltextAndLinks --- .../ListRightVariableRightCaretAlltextAndLinks.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableRightCaretAlltextAndLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableRightCaretAlltextAndLinks.swift index 1fbbe114..9adc65f2 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableRightCaretAlltextAndLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableRightCaretAlltextAndLinks.swift @@ -21,7 +21,7 @@ //-------------------------------------------------- public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { - stack = Stack.createStack(with: [(view: eyebrowHeadlineBodyLink, model: StackItemModel(horizontalAlignment: .leading, verticalAlignment: .leading)), (view: rightLabel, model: StackItemModel(horizontalAlignment:.fill))], axis: .horizontal) + stack = Stack.createStack(with: [(view: eyebrowHeadlineBodyLink, model: StackItemModel(horizontalAlignment: .leading, verticalAlignment: .fill)), (view: rightLabel, model: StackItemModel(horizontalAlignment:.fill, verticalAlignment: .leading))], axis: .horizontal) super.init(style: style, reuseIdentifier: reuseIdentifier) } @@ -47,7 +47,7 @@ if let heroCenter = heroCenter, let stackItem = stack.stackItems.last as? StackItem { let convertedPoint = stack.convert(heroCenter, from: self) - stackItem.containerHelper.alignCenterVerticalConstraint?.constant = convertedPoint.y - stack.bounds.midY + stackItem.containerHelper.topConstraint?.constant = max(convertedPoint.y - rightLabel.bounds.midY, 0.0) } return heroCenter @@ -61,7 +61,6 @@ super.set(with: model, delegateObject, additionalData) guard let model = model as? ListRightVariableRightCaretAllTextAndLinksModel else { return } - rightLabel.set(with: model.rightLabel, delegateObject, additionalData) eyebrowHeadlineBodyLink.set(with: model.eyebrowHeadlineBodyLink, delegateObject, additionalData) updateAccessibilityLabel() From a4ac0366458cedd4ae454f0b6b7c942cbfa089ba Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 13 Jan 2021 09:51:37 -0500 Subject: [PATCH 07/17] comment --- .../ListRightVariableRightCaretAlltextAndLinks.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableRightCaretAlltextAndLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableRightCaretAlltextAndLinks.swift index 9adc65f2..3b6a5b76 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableRightCaretAlltextAndLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableRightCaretAlltextAndLinks.swift @@ -21,6 +21,7 @@ //-------------------------------------------------- public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + // Fill for left vertical alignment because bottom constraint was breaking with leading. CXTDT-145456 stack = Stack.createStack(with: [(view: eyebrowHeadlineBodyLink, model: StackItemModel(horizontalAlignment: .leading, verticalAlignment: .fill)), (view: rightLabel, model: StackItemModel(horizontalAlignment:.fill, verticalAlignment: .leading))], axis: .horizontal) super.init(style: style, reuseIdentifier: reuseIdentifier) } From c963c05f60eebc2021fa2fc97d48740c195ac0d7 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 20 Jan 2021 09:42:09 -0500 Subject: [PATCH 08/17] optional --- .../HorizontalCombinationViews/TabBarModel.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBarModel.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBarModel.swift index 9de2cd54..581b890e 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBarModel.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBarModel.swift @@ -60,7 +60,7 @@ public class TabBarModel: MoleculeModelProtocol { } public class TabBarItemModel: Codable { - var title: String + var title: String? var image: String var action: ActionModelProtocol @@ -70,7 +70,7 @@ public class TabBarItemModel: Codable { case action } - public init(with title: String, image: String, action: ActionModelProtocol) { + public init(with title: String?, image: String, action: ActionModelProtocol) { self.title = title self.image = image self.action = action @@ -78,14 +78,14 @@ public class TabBarItemModel: Codable { required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - title = try typeContainer.decode(String.self, forKey: .title) + title = try typeContainer.decodeIfPresent(String.self, forKey: .title) image = try typeContainer.decode(String.self, forKey: .image) action = try typeContainer.decodeModel(codingKey: .action) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(title, forKey: .title) + try container.encodeIfPresent(title, forKey: .title) try container.encode(image, forKey: .image) try container.encodeModel(action, forKey: .action) } From 4038adc556932d6616692f153ad3b8008e83403c Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 22 Jan 2021 17:09:01 -0500 Subject: [PATCH 09/17] actions action and minor cleanup --- .../TextFields/BaseDropdownEntryField.swift | 4 +- .../Atomic/Atoms/Selectors/Checkbox.swift | 8 +-- .../Atomic/Atoms/Views/Label/Label.swift | 4 +- MVMCoreUI/Atomic/Atoms/Views/Toggle.swift | 14 ++-- .../Templates/ModalMoleculeListTemplate.swift | 12 ++-- .../ModalMoleculeStackTemplate.swift | 13 ++-- .../Templates/ModalSectionListTemplate.swift | 9 +-- .../OtherHandlers/MVMCoreUIActionHandler.h | 14 ---- .../OtherHandlers/MVMCoreUIActionHandler.m | 66 ------------------- 9 files changed, 22 insertions(+), 122 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift index 82e46306..b89a56e3 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift @@ -92,9 +92,9 @@ import UIKit } func performDropdownAction() { - if let baseDropdownEntryFieldModel = baseDropdownEntryFieldModel, let actionModel = baseDropdownEntryFieldModel.action, let actionMap = actionModel.toJSON() { + if let baseDropdownEntryFieldModel = baseDropdownEntryFieldModel, let actionModel = baseDropdownEntryFieldModel.action { let additionalDataWithSource = additionalData.dictionaryAdding(key: KeySourceModel, value: baseDropdownEntryFieldModel) - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalDataWithSource, delegateObject: delegateObject) + MVMCoreActionHandler.shared()?.asyncHandleAction(with: actionModel, additionalData: additionalDataWithSource, delegateObject: delegateObject) } } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift index edc37628..c85b3274 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift @@ -396,11 +396,9 @@ import MVMCore } private func performCheckboxAction(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - if let actionMap = actionModel.toJSON() { - var additionalDatatoUpdate = additionalData ?? [:] - additionalDatatoUpdate[KeySourceModel] = checkboxModel - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalDatatoUpdate, delegateObject: delegateObject) - } + var additionalDatatoUpdate = additionalData ?? [:] + additionalDatatoUpdate[KeySourceModel] = checkboxModel + MVMCoreActionHandler.shared()?.asyncHandleAction(with: actionModel, additionalData: additionalDatatoUpdate, delegateObject: delegateObject) } public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index 3f485099..bb1745a3 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -381,9 +381,7 @@ public typealias ActionBlock = () -> () } case let actionAtt as LabelAttributeActionModel: addTappableLinkAttribute(range: NSRange(location: range.location, length: range.length)) { - if let data = try? actionAtt.action.encode(using: JSONEncoder()), let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any] { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) - } + MVMCoreActionHandler.shared()?.asyncHandleAction(with: actionAtt.action, additionalData: additionalData, delegateObject: delegateObject) } addActionAttributes(range: range, string: attributedString) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift b/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift index 5712695b..931b272a 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift @@ -392,21 +392,17 @@ public typealias ActionBlockConfirmation = () -> (Bool) accessibilityLabel = accessibileString } - let actionMap = model.action?.toJSON() - let alternateActionMap = model.alternateAction?.toJSON() let additionalDataWithSource = additionalData.dictionaryAdding(key: KeySourceModel, value: model) - if actionMap != nil || alternateActionMap != nil { + if model.action != nil || model.alternateAction != nil { didToggleAction = { [weak self] in guard let self = self else { return } if self.isOn { - if actionMap != nil { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalDataWithSource, delegateObject: delegateObject) + if let action = model.action { + MVMCoreActionHandler.shared()?.asyncHandleAction(with: action, additionalData: additionalDataWithSource, delegateObject: delegateObject) } } else { - if alternateActionMap != nil { - MVMCoreActionHandler.shared()?.handleAction(with: alternateActionMap, additionalData: additionalDataWithSource, delegateObject: delegateObject) - } else if actionMap != nil { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalDataWithSource, delegateObject: delegateObject) + if let action = model.alternateAction ?? model.action { + MVMCoreActionHandler.shared()?.asyncHandleAction(with: action, additionalData: additionalDataWithSource, delegateObject: delegateObject) } } } diff --git a/MVMCoreUI/Atomic/Templates/ModalMoleculeListTemplate.swift b/MVMCoreUI/Atomic/Templates/ModalMoleculeListTemplate.swift index ac22cd18..1a82333d 100644 --- a/MVMCoreUI/Atomic/Templates/ModalMoleculeListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/ModalMoleculeListTemplate.swift @@ -29,14 +29,10 @@ open class ModalMoleculeListTemplate: MoleculeListTemplate { super.handleNewData() closeButton = MVMCoreUICommonViewsUtility.addCloseButton(to: view, action: { [weak self] _ in - guard let self = self else { - return - } - guard let model = self.templateModel as? ModalListPageTemplateModel, let actionMap = model.closeAction else { - MVMCoreActionHandler.shared()?.handleAction(with: ActionBackModel().toJSON(), additionalData: nil, delegateObject: self.delegateObjectIVar) - return - } - MVMCoreActionHandler.shared()?.handleAction(with: actionMap.toJSON(), additionalData: nil, delegateObject: self.delegateObjectIVar) + guard let self = self else { return } + let closeAction = (self.templateModel as? ModalListPageTemplateModel)?.closeAction ?? + ActionBackModel() + MVMCoreActionHandler.shared()?.asyncHandleAction(with: closeAction, additionalData: nil, delegateObject: self.delegateObjectIVar) }) } diff --git a/MVMCoreUI/Atomic/Templates/ModalMoleculeStackTemplate.swift b/MVMCoreUI/Atomic/Templates/ModalMoleculeStackTemplate.swift index 78a1e157..1db1bb9c 100644 --- a/MVMCoreUI/Atomic/Templates/ModalMoleculeStackTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/ModalMoleculeStackTemplate.swift @@ -18,15 +18,10 @@ open class ModalMoleculeStackTemplate: MoleculeStackTemplate { override open func handleNewData() { super.handleNewData() _ = MVMCoreUICommonViewsUtility.addCloseButton(to: view, action: {[weak self] _ in - guard let self = self else { - return - } - - guard let model = self.templateModel as? ModalStackPageTemplateModel, let actionMap = model.closeAction else { - MVMCoreActionHandler.shared()?.handleAction(with: ActionBackModel().toJSON(), additionalData: nil, delegateObject: self.delegateObjectIVar) - return - } - MVMCoreActionHandler.shared()?.handleAction(with: actionMap.toJSON(), additionalData: nil, delegateObject: self.delegateObjectIVar) + guard let self = self else { return } + let closeAction = (self.templateModel as? ModalStackPageTemplateModel)?.closeAction ?? + ActionBackModel() + MVMCoreActionHandler.shared()?.asyncHandleAction(with: closeAction, additionalData: nil, delegateObject: self.delegateObjectIVar) }) } } diff --git a/MVMCoreUI/Atomic/Templates/ModalSectionListTemplate.swift b/MVMCoreUI/Atomic/Templates/ModalSectionListTemplate.swift index 77ee705c..424fc6c5 100644 --- a/MVMCoreUI/Atomic/Templates/ModalSectionListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/ModalSectionListTemplate.swift @@ -19,12 +19,9 @@ open class ModalSectionListTemplate: SectionListTemplate { super.handleNewData() _ = MVMCoreUICommonViewsUtility.addCloseButton(to: view, action: {[weak self] _ in guard let self = self else { return } - guard let model = self.templateModel as? ModalSectionListTemplateModel, - let actionMap = model.closeAction else { - MVMCoreActionHandler.shared()?.handleAction(with: ActionBackModel().toJSON(), additionalData: nil, delegateObject: self.delegateObjectIVar) - return - } - MVMCoreActionHandler.shared()?.handleAction(with: actionMap.toJSON(), additionalData: nil, delegateObject: self.delegateObjectIVar) + let closeAction = (self.templateModel as? ModalSectionListTemplateModel)?.closeAction ?? + ActionBackModel() + MVMCoreActionHandler.shared()?.asyncHandleAction(with: closeAction, additionalData: nil, delegateObject: self.delegateObjectIVar) }) } } diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIActionHandler.h b/MVMCoreUI/OtherHandlers/MVMCoreUIActionHandler.h index f6b89806..c1dee62a 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIActionHandler.h +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIActionHandler.h @@ -27,20 +27,6 @@ NS_ASSUME_NONNULL_BEGIN // Shows a topnotification new molecular - (void)topNotificationAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -#pragma mark - Deprecated - -// Shows a popup -- (void)popupAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Shows a top alert -- (void)topAlertAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Shows a molecular top alert -- (void)topNotificationAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Collapses the current top notification -- (void)collapseNotificationAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - @end NS_ASSUME_NONNULL_END diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIActionHandler.m b/MVMCoreUI/OtherHandlers/MVMCoreUIActionHandler.m index 79f92990..e2adbd74 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIActionHandler.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIActionHandler.m @@ -122,70 +122,4 @@ } } -#pragma mark - Deprecated - -- (BOOL)handleOtherActions:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - if ([actionType isEqualToString:KeyActionTypePopup]) { - [self popupAction:actionInformation additionalData:additionalData delegate:delegate]; - return YES; - } else if ([actionType isEqualToString:KeyActionTypeTopAlert]) { - [self topAlertAction:actionInformation additionalData:additionalData delegate:delegate]; - return YES; - } else if ([actionType isEqualToString:KeyActionTypeCollapseNotification]) { - [self collapseNotificationAction:actionInformation additionalData:additionalData delegate:delegate]; - return YES; - } else if ([actionType isEqualToString:KeyActionTypeTopNotification]) { - [self topNotificationAction:actionInformation additionalData:additionalData delegate:delegate]; - return YES; - } - return NO; -} - -- (void)popupAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - // Perform a popup. - NSString *pageTypeForPopup = [actionInformation stringForKey:KeyPageType]; - [[MVMCoreCache sharedCache] fetchJSONForPageType:pageTypeForPopup queue:nil waitUntilFinished:YES completionHandler:^(NSDictionary * _Nullable jsonDictionary) { - - MVMCoreErrorObject *error = nil; - MVMCoreAlertObject *alertObject = [MVMCoreAlertObject alertObjectWithPage:jsonDictionary isGreedy:NO additionalData:additionalData delegate:delegate error:&error]; - if ([delegate respondsToSelector:@selector(willShowPopupWithAlertObject:alertJson:)]) { - [((id )delegate) willShowPopupWithAlertObject:alertObject alertJson:jsonDictionary]; - } - - if (alertObject) { - [[MVMCoreAlertHandler sharedAlertHandler] showAlertWithAlertObject:alertObject]; - } else { - [self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegate:delegate]; - } - }]; -} - -- (void)topAlertAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - // Perform a top alert. - NSString *pageTypeForTopAlert = [actionInformation stringForKey:KeyPageType]; - [[MVMCoreCache sharedCache] fetchJSONForPageType:pageTypeForTopAlert queue:nil waitUntilFinished:YES completionHandler:^(NSDictionary * _Nullable jsonDictionary) { - - NSDictionary *responseInfo = [jsonDictionary dict:KeyResponseInfo]; - if (responseInfo) { - MVMCoreAlertObject *alertObject = [MVMCoreAlertObject alertObjectForPageType:pageTypeForTopAlert responseInfo:responseInfo additionalData:additionalData actionDelegate:delegate]; - if ([delegate respondsToSelector:@selector(willShowTopAlertWithAlertObject:alertJson:)]) { - alertObject = [((id )delegate) willShowTopAlertWithAlertObject:alertObject alertJson:jsonDictionary]; - } - [alertObject showAlert]; - } - }]; -} - -- (void)collapseNotificationAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - // Collapse the current notification. - if ([[CoreUIObject sharedInstance].globalTopAlertDelegate respondsToSelector:@selector(getTopAlertView)]) { - [[[CoreUIObject sharedInstance].globalTopAlertDelegate getTopAlertView] collapseNotification]; - } -} - -- (void)topNotificationAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - //Handle molecular topnotification - [[MVMCoreUITopAlertView sharedGlobal] showTopAlertWith:[actionInformation dict:@"topNotification"] ?: @{}]; -} - @end From d63a50427222e11006b2d2d7334f7e7f952b8358 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 25 Jan 2021 09:26:39 -0500 Subject: [PATCH 10/17] typo fix --- MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift index c85b3274..b80fe9ff 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift @@ -396,9 +396,9 @@ import MVMCore } private func performCheckboxAction(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - var additionalDatatoUpdate = additionalData ?? [:] - additionalDatatoUpdate[KeySourceModel] = checkboxModel - MVMCoreActionHandler.shared()?.asyncHandleAction(with: actionModel, additionalData: additionalDatatoUpdate, delegateObject: delegateObject) + var additionalDataToUpdate = additionalData ?? [:] + additionalDataToUpdate[KeySourceModel] = checkboxModel + MVMCoreActionHandler.shared()?.asyncHandleAction(with: actionModel, additionalData: additionalDataToUpdate, delegateObject: delegateObject) } public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { From 7b4f7885067e2c82a1dc5636d9b5e674fd20841e Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 29 Jan 2021 16:31:30 -0500 Subject: [PATCH 11/17] Bug fix and warning fix --- .../Molecules/HorizontalCombinationViews/TabBar.swift | 7 +++++-- MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m | 2 +- MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift index 1ee7ee71..1565cf30 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift @@ -57,8 +57,11 @@ import Foundation var tabs: [UITabBarItem] = [] for (index, tab) in model.tabs.enumerated() { let tabBarItem = UITabBarItem(title: tab.title, image: MVMCoreCache.shared()?.getImageFromRegisteredBundles(tab.image), tag: index) - tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3) - tabBarItem.setTitleTextAttributes([NSAttributedString.Key.font: MFFonts.mfFontTXRegular(8)], for: .normal) + if #available(iOS 13.0, *) { + } else { + tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3) + tabBarItem.setTitleTextAttributes([NSAttributedString.Key.font: MFFonts.mfFontTXRegular(8)], for: .normal) + } tabs.append(tabBarItem) } setItems(tabs, animated: false) diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m index 55468c95..46ecd793 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertExpandableView.m @@ -211,7 +211,7 @@ if (topMessage && (!self.onlyShowTopMessageWhenCollapsed || !self.expanded)) { self.shortViewHeight.active = NO; - } else if (!topMessage && self.onlyShowTopMessageWhenCollapsed && self.expanded) { + } else if (!topMessage || (self.onlyShowTopMessageWhenCollapsed && self.expanded)) { self.shortViewHeight.active = YES; } }]; diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m index 4ac5aaa0..ad0a833f 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m @@ -113,8 +113,8 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed."; - (void)pinATopViewController:(UIViewController *)viewController { self.statusBarHeightConstraint.active = NO; - id topGuide = viewController.topLayoutGuide; - self.statusBarBottomConstraint = [NSLayoutConstraint constraintWithItem:self.statusBarView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:topGuide attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0]; + id topGuide = viewController.view.safeAreaLayoutGuide; + self.statusBarBottomConstraint = [NSLayoutConstraint constraintWithItem:self.statusBarView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:topGuide attribute:NSLayoutAttributeTop multiplier:1.0 constant:0]; self.statusBarBottomConstraint.active = YES; } From b36299b69592cf675670fa0ff4a23bf6708b4896 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 29 Jan 2021 17:07:57 -0500 Subject: [PATCH 12/17] latest and greatest --- MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift | 8 +++++++- .../Atomic/Molecules/Items/MoleculeTableViewCell.swift | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index 8a8ca5fb..14d2e247 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -41,6 +41,12 @@ public typealias ActionBlock = () -> () return NSRange(location: 0, length: text?.count ?? 0) } + open override var text: String? { + didSet { + // TODO....???? + } + } + //------------------------------------------------------ // MARK: - Multi-Action Text //------------------------------------------------------ @@ -892,7 +898,7 @@ extension Label { if clauses.isEmpty { // Replace the last whitespace with \u{00A0} No-break space. if let start = text?.lastIndex(of: " "), let end = text?.index(after: start) { -// text?.replaceSubrange(start.. CGSize { + guard let molecule = molecule as? HeadlineBody else { return super.frame.size } + let cell = self + cell.frame = CGRect(x: 0, y: 0, width: targetSize.width, height: CGFloat(MAXFLOAT)) + cell.layoutIfNeeded() + + return CGSize(width: molecule.bounds.width + cell.contentView.directionalLayoutMargins.leading + cell.contentView.directionalLayoutMargins.trailing, height: molecule.bounds.height + cell.contentView.directionalLayoutMargins.top + cell.contentView.directionalLayoutMargins.bottom) + } } From 5c23e80429bcfc964d0d1ed8d8bae78b89111d82 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 1 Feb 2021 14:13:39 -0500 Subject: [PATCH 13/17] addressing intrinsic content issue --- .../Atomic/Atoms/Views/Label/Label.swift | 71 ++---------------- .../Items/MoleculeTableViewCell.swift | 10 --- .../HeadlineBody.swift | 73 ++++++++----------- 3 files changed, 35 insertions(+), 119 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index 14d2e247..42827e67 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -38,13 +38,7 @@ public typealias ActionBlock = () -> () } public var getRange: NSRange { - return NSRange(location: 0, length: text?.count ?? 0) - } - - open override var text: String? { - didSet { - // TODO....???? - } + NSRange(location: 0, length: text?.count ?? 0) } //------------------------------------------------------ @@ -102,6 +96,10 @@ public typealias ActionBlock = () -> () accessibilityCustomActions = [] accessibilityTraits = .staticText +// if #available(iOS 14.0, *) { +// lineBreakStrategy = .init() +// } + let tapGesture = UITapGestureRecognizer(target: self, action: #selector(textLinkTapped)) tapGesture.numberOfTapsRequired = 1 addGestureRecognizer(tapGesture) @@ -918,64 +916,7 @@ extension Label { } } -extension Label { - - open func getSeparatedLines() -> [Any] { - - if lineBreakMode != .byWordWrapping { - lineBreakMode = .byWordWrapping - } - - var lines = [Any]() /* capacity: 10 */ - let wordSeparators = CharacterSet.whitespacesAndNewlines - var currentLine: String? = self.text - let textLength: Int = (self.text?.count ?? 0) - var rCurrentLine = NSRange(location: 0, length: textLength) - var rWhitespace = NSRange(location: 0, length: 0) - var rRemainingText = NSRange(location: 0, length: textLength) - var done: Bool = false - - while !done { - // determine the next whitespace word separator position - rWhitespace.location = rWhitespace.location + rWhitespace.length - rWhitespace.length = textLength - rWhitespace.location - rWhitespace = (self.text! as NSString).rangeOfCharacter(from: wordSeparators, options: .caseInsensitive, range: rWhitespace) - if rWhitespace.location == NSNotFound { - rWhitespace.location = textLength - done = true - } - let rTest = NSRange(location: rRemainingText.location, length: rWhitespace.location - rRemainingText.location) - let textTest: String = (self.text! as NSString).substring(with: rTest) - let fontAttributes: [String: Any]? = [NSAttributedString.Key.font.rawValue: font] - let maxWidth = (textTest as NSString).size(withAttributes: [NSAttributedString.Key(rawValue: NSAttributedString.Key.font.rawValue): font]).width - if maxWidth > self.bounds.size.width { - lines.append(currentLine?.trimmingCharacters(in: wordSeparators) ?? "") - rRemainingText.location = rCurrentLine.location + rCurrentLine.length - rRemainingText.length = textLength - rRemainingText.location - continue - } - rCurrentLine = rTest - currentLine = textTest - } - - lines.append(currentLine?.trimmingCharacters(in: wordSeparators) ?? "") - - return lines - } - - open var lastLineWidth: CGFloat { - - let lines: [Any] = self.getSeparatedLines() - - if !lines.isEmpty { - let lastLine: String = (lines.last as? String)! - let fontAttributes = [NSAttributedString.Key.font.rawValue: font] - return (lastLine as NSString).size(withAttributes: [NSAttributedString.Key(rawValue: NSAttributedString.Key.font.rawValue): font]).width - } - - return 0 - } -} + // MARK: - extension UITapGestureRecognizer { diff --git a/MVMCoreUI/Atomic/Molecules/Items/MoleculeTableViewCell.swift b/MVMCoreUI/Atomic/Molecules/Items/MoleculeTableViewCell.swift index 621cbeee..92d04bed 100644 --- a/MVMCoreUI/Atomic/Molecules/Items/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Atomic/Molecules/Items/MoleculeTableViewCell.swift @@ -42,14 +42,4 @@ import UIKit else { return 80 } return height } - - // TODO: Figure out height..... - open override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize { - guard let molecule = molecule as? HeadlineBody else { return super.frame.size } - let cell = self - cell.frame = CGRect(x: 0, y: 0, width: targetSize.width, height: CGFloat(MAXFLOAT)) - cell.layoutIfNeeded() - - return CGSize(width: molecule.bounds.width + cell.contentView.directionalLayoutMargins.leading + cell.contentView.directionalLayoutMargins.trailing, height: molecule.bounds.height + cell.contentView.directionalLayoutMargins.top + cell.contentView.directionalLayoutMargins.bottom) - } } diff --git a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift index d111d1c5..8144fc03 100644 --- a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift +++ b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift @@ -19,19 +19,15 @@ open class HeadlineBody: View { // MARK: - Constraints //-------------------------------------------------- - var spaceBetweenLabelsConstant = PaddingOne + var spaceBetweenLabelsConstant = Padding.One var spaceBetweenLabels: NSLayoutConstraint? - var leftConstraintTitle: NSLayoutConstraint? - var rightConstraintTitle: NSLayoutConstraint? - var leftConstraintMessage: NSLayoutConstraint? - var rightConstraintMessage: NSLayoutConstraint? //-------------------------------------------------- // MARK: - Methods //-------------------------------------------------- func hasText() -> Bool { - return headlineLabel.hasText || messageLabel.hasText + headlineLabel.hasText || messageLabel.hasText } // MARK: - Styling @@ -57,13 +53,13 @@ open class HeadlineBody: View { func styleLandingPageHeader() { headlineLabel.setFontStyle(.Title2XLarge) messageLabel.setFontStyle(.RegularBodySmall) - spaceBetweenLabelsConstant = PaddingTwo + spaceBetweenLabelsConstant = Padding.Two } func stylePageHeader() { headlineLabel.setFontStyle(.BoldTitleLarge) messageLabel.setFontStyle(.RegularBodySmall) - spaceBetweenLabelsConstant = PaddingOne + spaceBetweenLabelsConstant = Padding.Two } func styleListItem() { @@ -86,48 +82,38 @@ open class HeadlineBody: View { super.setupView() backgroundColor = .clear - clipsToBounds = true + isAccessibilityElement = false + shouldGroupAccessibilityChildren = true + accessibilityElements = [headlineLabel, messageLabel] - let view = MVMCoreUICommonViewsUtility.commonView() - addSubview(view) - NSLayoutConstraint.constraintPinSubview(toSuperview: view) + addSubview(headlineLabel) + addSubview(messageLabel) - view.isAccessibilityElement = false - view.shouldGroupAccessibilityChildren = true - view.accessibilityElements = [headlineLabel, messageLabel] + headlineLabel.setContentCompressionResistancePriority(.required, for: .vertical) + messageLabel.setContentCompressionResistancePriority(.required, for: .vertical) - view.addSubview(headlineLabel) - view.addSubview(messageLabel) - - headlineLabel.setContentHuggingPriority(.required, for: .vertical) - messageLabel.setContentHuggingPriority(.required, for: .vertical) - view.setContentHuggingPriority(.required, for: .vertical) - - headlineLabel.topAnchor.constraint(equalTo: view.topAnchor).isActive = true + headlineLabel.topAnchor.constraint(equalTo: topAnchor).isActive = true spaceBetweenLabels = messageLabel.topAnchor.constraint(equalTo: headlineLabel.bottomAnchor, constant: spaceBetweenLabelsConstant) spaceBetweenLabels?.isActive = true - leftConstraintTitle = headlineLabel.leftAnchor.constraint(equalTo: view.leftAnchor) - leftConstraintTitle?.isActive = true - - rightConstraintTitle = view.rightAnchor.constraint(equalTo: headlineLabel.rightAnchor) - rightConstraintTitle?.isActive = true - - leftConstraintMessage = messageLabel.leftAnchor.constraint(equalTo: view.leftAnchor) - leftConstraintMessage?.isActive = true - - rightConstraintMessage = view.rightAnchor.constraint(equalTo: messageLabel.rightAnchor) - rightConstraintMessage?.isActive = true - - view.bottomAnchor.constraint(equalTo: messageLabel.bottomAnchor).isActive = true + NSLayoutConstraint.activate([ + headlineLabel.leadingAnchor.constraint(equalTo: leadingAnchor), + trailingAnchor.constraint(equalTo: headlineLabel.trailingAnchor), + messageLabel.leadingAnchor.constraint(equalTo: leadingAnchor), + trailingAnchor.constraint(equalTo: messageLabel.trailingAnchor), + bottomAnchor.constraint(equalTo: messageLabel.bottomAnchor) + ]) } open override func updateView(_ size: CGFloat) { super.updateView(size) + setSpacing() headlineLabel.updateView(size) messageLabel.updateView(size) - setSpacing() + let padding = MFStyler.defaultHorizontalPadding(forSize: size) * 2 + let maximumTextWidth = (size - (padding + Padding.Four)) + messageLabel.preferredMaxLayoutWidth = maximumTextWidth } //-------------------------------------------------- @@ -146,19 +132,18 @@ open class HeadlineBody: View { // MARK: - MoleculeViewProtocol //-------------------------------------------------- - public override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { - return 58 - } + public override class func estimatedHeight(with model: MoleculeModelProtocol, + _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { 58 } public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) - guard let headlineBodyModel = model as? HeadlineBodyModel else { return } + guard let model = model as? HeadlineBodyModel else { return } - style(with: headlineBodyModel.style) + style(with: model.style) - headlineLabel.setOptional(with: headlineBodyModel.headline, delegateObject, additionalData) - messageLabel.setOptional(with: headlineBodyModel.body, delegateObject, additionalData) + headlineLabel.setOptional(with: model.headline, delegateObject, additionalData) + messageLabel.setOptional(with: model.body, delegateObject, additionalData) } open override func reset() { From 3872591d50021e8d5eec91d239f963ef7efbdefa Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 1 Feb 2021 14:28:21 -0500 Subject: [PATCH 14/17] rm --- MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift | 6 ------ 1 file changed, 6 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index 42827e67..9a452e3f 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -96,10 +96,6 @@ public typealias ActionBlock = () -> () accessibilityCustomActions = [] accessibilityTraits = .staticText -// if #available(iOS 14.0, *) { -// lineBreakStrategy = .init() -// } - let tapGesture = UITapGestureRecognizer(target: self, action: #selector(textLinkTapped)) tapGesture.numberOfTapsRequired = 1 addGestureRecognizer(tapGesture) @@ -916,8 +912,6 @@ extension Label { } } - - // MARK: - extension UITapGestureRecognizer { From a5febf586c21ca6e2497a10263b01e1f20198566 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 1 Feb 2021 14:41:51 -0500 Subject: [PATCH 15/17] updated --- MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift | 7 ------- .../Molecules/VerticalCombinationViews/HeadlineBody.swift | 3 +-- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index 9a452e3f..4cab6cd7 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -889,13 +889,6 @@ extension Label { /// Underlines the tappable region and stores the tap logic for interation. private func setTextLinkState(range: NSRange, actionBlock: @escaping ActionBlock) { - if clauses.isEmpty { - // Replace the last whitespace with \u{00A0} No-break space. - if let start = text?.lastIndex(of: " "), let end = text?.index(after: start) { - text?.replaceSubrange(start.. Date: Mon, 1 Feb 2021 14:43:35 -0500 Subject: [PATCH 16/17] updateds --- .../Molecules/VerticalCombinationViews/HeadlineBody.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift index 93eace61..fb744f3e 100644 --- a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift +++ b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift @@ -59,7 +59,7 @@ open class HeadlineBody: View { func stylePageHeader() { headlineLabel.setFontStyle(.BoldTitleLarge) messageLabel.setFontStyle(.RegularBodySmall) - spaceBetweenLabelsConstant = Padding.Two + spaceBetweenLabelsConstant = Padding.One } func styleListItem() { @@ -90,7 +90,9 @@ open class HeadlineBody: View { addSubview(messageLabel) headlineLabel.setContentCompressionResistancePriority(.required, for: .vertical) + headlineLabel.setContentHuggingPriority(.required, for: .vertical) messageLabel.setContentCompressionResistancePriority(.required, for: .vertical) + messageLabel.setContentHuggingPriority(.required, for: .vertical) headlineLabel.topAnchor.constraint(equalTo: topAnchor).isActive = true From 68d9473adcb407af57203938d26a723fbef25256 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 1 Feb 2021 14:45:20 -0500 Subject: [PATCH 17/17] comment --- .../Molecules/VerticalCombinationViews/HeadlineBody.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift index fb744f3e..703793f3 100644 --- a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift +++ b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift @@ -113,6 +113,8 @@ open class HeadlineBody: View { setSpacing() headlineLabel.updateView(size) messageLabel.updateView(size) + + // Provide the label additional size information to help calculate its intrinsic height. let padding = MFStyler.defaultHorizontalPadding(forSize: size) * 2 messageLabel.preferredMaxLayoutWidth = size - padding }