From 845036b4ec8639efaecc340e2dba538c076d95ec Mon Sep 17 00:00:00 2001 From: "Christiano, Kevin" Date: Wed, 29 May 2019 21:10:29 -0400 Subject: [PATCH] Changed atom name. making changes to LabelWithIntenralButton. --- MVMCoreUI.xcodeproj/project.pbxproj | 8 ++-- MVMCoreUI/Atoms/Views/Label.swift | 18 ++----- .../Atoms/Views/LabelWithInternalButton.swift | 2 +- ...istItem.swift => LeftRightLabelView.swift} | 48 +++++++++++++------ .../MVMCoreUIMoleculeMappingObject.m | 2 +- 5 files changed, 42 insertions(+), 36 deletions(-) rename MVMCoreUI/Atoms/Views/{StandardListItem.swift => LeftRightLabelView.swift} (79%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 79ac0668..f63e075d 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -164,7 +164,7 @@ D2E1FADD2268B25E00AEFD8C /* MoleculeTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E1FADC2268B25E00AEFD8C /* MoleculeTableViewCell.swift */; }; D2E1FADF2268B8E700AEFD8C /* ThreeLayerTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E1FADE2268B8E700AEFD8C /* ThreeLayerTableViewController.swift */; }; D2E1FAE12268E81D00AEFD8C /* MoleculeListTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E1FAE02268E81D00AEFD8C /* MoleculeListTemplate.swift */; }; - DB06250B2293456500B72DD3 /* StandardListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB06250A2293456500B72DD3 /* StandardListItem.swift */; }; + DB06250B2293456500B72DD3 /* LeftRightLabelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB06250A2293456500B72DD3 /* LeftRightLabelView.swift */; }; DBC4391822442197001AB423 /* CaretView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391622442196001AB423 /* CaretView.swift */; }; DBC4391922442197001AB423 /* DashLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391722442197001AB423 /* DashLine.swift */; }; DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391A224421A0001AB423 /* CaretButton.swift */; }; @@ -333,7 +333,7 @@ D2E1FADC2268B25E00AEFD8C /* MoleculeTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeTableViewCell.swift; sourceTree = ""; }; D2E1FADE2268B8E700AEFD8C /* ThreeLayerTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeLayerTableViewController.swift; sourceTree = ""; }; D2E1FAE02268E81D00AEFD8C /* MoleculeListTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeListTemplate.swift; sourceTree = ""; }; - DB06250A2293456500B72DD3 /* StandardListItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StandardListItem.swift; sourceTree = ""; }; + DB06250A2293456500B72DD3 /* LeftRightLabelView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LeftRightLabelView.swift; sourceTree = ""; }; DB891E822253FA8500022516 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = ""; }; DBC4391622442196001AB423 /* CaretView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaretView.swift; sourceTree = ""; }; DBC4391722442197001AB423 /* DashLine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DashLine.swift; sourceTree = ""; }; @@ -584,7 +584,7 @@ children = ( DBC4391622442196001AB423 /* CaretView.swift */, DBC4391722442197001AB423 /* DashLine.swift */, - DB06250A2293456500B72DD3 /* StandardListItem.swift */, + DB06250A2293456500B72DD3 /* LeftRightLabelView.swift */, D29DF17E21E69E2E003B2FB9 /* MFView.h */, D29DF17F21E69E2E003B2FB9 /* MFView.m */, D29DF31E21ED0CBA003B2FB9 /* LabelView.h */, @@ -942,7 +942,7 @@ D29DF29521E7ADB8003B2FB9 /* ProgrammaticScrollViewController.m in Sources */, D29DF16121E69996003B2FB9 /* MFViewController.m in Sources */, D2E1FAE12268E81D00AEFD8C /* MoleculeListTemplate.swift in Sources */, - DB06250B2293456500B72DD3 /* StandardListItem.swift in Sources */, + DB06250B2293456500B72DD3 /* LeftRightLabelView.swift in Sources */, D22D1F47220496A30077CEC0 /* MVMCoreUISwitch.m in Sources */, D29DF28C21E7AC2B003B2FB9 /* ViewConstrainingView.m in Sources */, D29DF17B21E69E1F003B2FB9 /* PrimaryButton.m in Sources */, diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 65ac4c70..e0bb2a25 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -154,11 +154,6 @@ public typealias ActionBlock = () -> Void // MARK: - Functions //------------------------------------------------------ - /** - - Parameters: - - label: The label to be set. - - html: any html string. - */ @objc public static func setLabel(_ label: UILabel?, withHTML html: String?) { guard let data = html?.data(using: .utf8) else { return } @@ -175,17 +170,10 @@ public typealias ActionBlock = () -> Void } } - /** - - Parameters: - - label: The current label view that will have an actionable range of text. - - json: Contains values which det the values of Label. - - delegate: - - additionalData: - */ @objc public static func setUILabel(_ label: UILabel?, withJSON json: [AnyHashable: Any]?, delegate: DelegateObject?, additionalData: [AnyHashable: Any]?) { guard let label = label else { return } - + label.attributedText = nil label.text = json?.optionalStringForKey(KeyText) setLabel(label, withHTML: json?.optionalStringForKey("html")) @@ -376,8 +364,8 @@ extension Label { } public func createActionBlockFrom(actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) -> ActionBlock { - return { - if (delegateObject as? MVMCoreUIDelegateObject)?.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true { + return { [weak self] in + if (delegateObject as? MVMCoreUIDelegateObject)?.buttonDelegate?.button?(self!, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } } diff --git a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift index e7d30fb0..76fb8db4 100644 --- a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift +++ b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift @@ -450,7 +450,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt setText(fullText, startTag: startTag, endTag: endTag) - actionBlock = { + actionBlock = { [weak delegate] in MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegate: delegate as? CoreObjectActionLoadPresentDelegate) } } diff --git a/MVMCoreUI/Atoms/Views/StandardListItem.swift b/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift similarity index 79% rename from MVMCoreUI/Atoms/Views/StandardListItem.swift rename to MVMCoreUI/Atoms/Views/LeftRightLabelView.swift index e4ef7133..118502b6 100644 --- a/MVMCoreUI/Atoms/Views/StandardListItem.swift +++ b/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift @@ -9,7 +9,7 @@ import Foundation -@objcMembers open class StandardListItem: ViewConstrainingView { +@objcMembers open class LeftRightLabelView: ViewConstrainingView { //------------------------------------------------------ // MARK: - Properties //------------------------------------------------------ @@ -25,6 +25,9 @@ import Foundation var messageTrail: NSLayoutConstraint? var titleTrail: NSLayoutConstraint? + var titleDetailBaseline: NSLayoutConstraint? + var messageDetailBaseline: NSLayoutConstraint? + //------------------------------------------------------ // MARK: - Initialization //------------------------------------------------------ @@ -41,7 +44,7 @@ import Foundation super.init(coder: aDecoder) } - public convenience init(actionMap: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + public convenience init(actionMap: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { self.init() setWithJSON(actionMap: actionMap, delegateObject: delegateObject, additionalData: additionalData) } @@ -60,9 +63,14 @@ import Foundation override open func updateView(_ size: CGFloat) { super.updateView(size) + title?.updateView(size) + message?.updateView(size) + detail?.updateView(size) + if let titleText = title?.text, let messageText = message?.text, titleText.isEmpty && messageText.isEmpty { detailWidth?.constant = size detail?.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -PaddingTwo).isActive = true + titleDetailBaseline?.isActive = false return } @@ -81,6 +89,8 @@ import Foundation messageWidth?.constant = size * 0.6 - PaddingOne detailWidth?.constant = size * 0.2 titleWidth?.constant = 0 + titleDetailBaseline?.isActive = false + messageDetailBaseline?.isActive = true return } @@ -116,19 +126,27 @@ import Foundation message.textAlignment = .left detail.textAlignment = .right - NSLayoutConstraint.constraintPinSubview(title, pinTop: true, topConstant: PaddingTwo, pinBottom: false, bottomConstant: 0, pinLeft: true, leftConstant: 0, pinRight: false, rightConstant: 0) - NSLayoutConstraint.constraintPinSubview(message, pinTop: false, topConstant: 0, pinBottom: true, bottomConstant: PaddingTwo, pinLeft: true, leftConstant: 0, pinRight: false, rightConstant: 0) - NSLayoutConstraint.constraintPinSubview(detail, pinTop: true, topConstant: PaddingTwo, pinBottom: false, bottomConstant: 0, pinLeft: false, leftConstant: 0, pinRight: true, rightConstant: 0) - NSLayoutConstraint(pinFirstView: title, toSecondView: message, withConstant: 0, directionVertical: true)?.isActive = true - - let titleTrail = title.trailingAnchor.constraint(greaterThanOrEqualTo: detail.leadingAnchor, constant: PaddingOne) + title.topAnchor.constraint(equalTo: topAnchor).isActive = true + title.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true + let titleTrail = title.trailingAnchor.constraint(greaterThanOrEqualTo: detail.leadingAnchor) titleTrail.isActive = true - let messageTrail = message.trailingAnchor.constraint(greaterThanOrEqualTo: detail.leadingAnchor, constant: PaddingOne) + message.topAnchor.constraint(equalTo: title.bottomAnchor).isActive = true + message.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true + message.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true + let messageTrail = message.trailingAnchor.constraint(greaterThanOrEqualTo: detail.leadingAnchor) messageTrail.isActive = true + detail.topAnchor.constraint(equalTo: topAnchor).isActive = true + detail.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true + + titleDetailBaseline = detail.firstBaselineAnchor.constraint(equalTo: title.firstBaselineAnchor) + titleDetailBaseline?.isActive = true + + messageDetailBaseline = detail.firstBaselineAnchor.constraint(equalTo: message.firstBaselineAnchor) + titleWidth = title.widthAnchor.constraint(lessThanOrEqualToConstant: bounds.width * 0.8 - PaddingOne) - titleWidth?.priority = UILayoutPriority(rawValue: 750) + titleWidth?.priority = UILayoutPriority(rawValue: 751) titleWidth?.isActive = true messageWidth = message.widthAnchor.constraint(lessThanOrEqualToConstant: bounds.width * 0.8 - PaddingOne) @@ -136,7 +154,7 @@ import Foundation messageWidth?.isActive = true detailWidth = detail.widthAnchor.constraint(equalToConstant: bounds.width * 0.2) - detailWidth?.priority = UILayoutPriority(rawValue: 755) + detailWidth?.priority = UILayoutPriority(rawValue: 850) detailWidth?.isActive = true title.setContentHuggingPriority(UILayoutPriority(rawValue: 251), for: .horizontal) @@ -149,14 +167,14 @@ import Foundation message.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 749), for: .horizontal) message.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 250), for: .vertical) - detail.setContentHuggingPriority(UILayoutPriority(rawValue: 251), for: .horizontal) + detail.setContentHuggingPriority(UILayoutPriority(rawValue: 750), for: .horizontal) detail.setContentHuggingPriority(UILayoutPriority(rawValue: 249), for: .vertical) detail.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 750), for: .horizontal) - detail.setContentCompressionResistancePriority(.required, for: .vertical) + detail.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 999), for: .vertical) } } - func setWithJSON(actionMap: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + func setWithJSON(actionMap: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { guard let dictionary = actionMap else { return } @@ -178,7 +196,7 @@ import Foundation defaultState() } - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) setWithJSON(actionMap: json, delegateObject: delegateObject, additionalData: additionalData) } diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index e03c495f..30f0aff6 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -38,7 +38,7 @@ @"listItem": MoleculeTableViewCell.class, @"switchLineItem": SwitchLineItem.class, @"switch": Switch.class, - @"standardListItem": StandardListItem.class + @"leftRightLabelView": LeftRightLabelView.class } mutableCopy]; }); return mapping;