From 988e30daa9bca0163a5a234a156638aa2ea90d71 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Mon, 2 Dec 2019 11:15:50 -0500 Subject: [PATCH 01/34] Creates Link atom to replace MFTextButton --- MVMCoreUI.xcodeproj/project.pbxproj | 4 + MVMCoreUI/Atoms/Buttons/Link.swift | 155 +++++++++++++++++++++++++ MVMCoreUI/Utility/MVMCoreUIConstants.h | 1 + MVMCoreUI/Utility/MVMCoreUIConstants.m | 1 + 4 files changed, 161 insertions(+) create mode 100644 MVMCoreUI/Atoms/Buttons/Link.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 391e20f5..70cbe5ff 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -32,6 +32,7 @@ 943784F6236B77BB006A1E82 /* GraphViewAnimationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943784F4236B77BB006A1E82 /* GraphViewAnimationHandler.swift */; }; 9455B19C234F8A0400A574DB /* MVMAnimationFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9455B19B234F8A0400A574DB /* MVMAnimationFramework.framework */; }; 948DB67E2326DCD90011F916 /* MultiProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 948DB67D2326DCD90011F916 /* MultiProgress.swift */; }; + C07065C42395677300FBF997 /* Link.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07065C32395677300FBF997 /* Link.swift */; }; D20A9A5E2243D3E300ADE781 /* TwoButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */; }; D213347723843825008E41B3 /* Line.swift in Sources */ = {isa = PBXBuildFile; fileRef = D213347623843825008E41B3 /* Line.swift */; }; D224798A2314445E003FCCF9 /* LabelSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = D22479892314445E003FCCF9 /* LabelSwitch.swift */; }; @@ -228,6 +229,7 @@ 943784F4236B77BB006A1E82 /* GraphViewAnimationHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphViewAnimationHandler.swift; sourceTree = ""; }; 9455B19B234F8A0400A574DB /* MVMAnimationFramework.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MVMAnimationFramework.framework; path = ../SharedFrameworks/MVMAnimationFramework.framework; sourceTree = ""; }; 948DB67D2326DCD90011F916 /* MultiProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiProgress.swift; sourceTree = ""; }; + C07065C32395677300FBF997 /* Link.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Link.swift; sourceTree = ""; }; D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoButtonView.swift; sourceTree = ""; }; D213347623843825008E41B3 /* Line.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Line.swift; sourceTree = ""; }; D22479892314445E003FCCF9 /* LabelSwitch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelSwitch.swift; sourceTree = ""; }; @@ -729,6 +731,7 @@ D282AACA2243C61700C46919 /* ButtonView.swift */, D29DF16D21E69E1F003B2FB9 /* MFTextButton.h */, D29DF17221E69E1F003B2FB9 /* MFTextButton.m */, + C07065C32395677300FBF997 /* Link.swift */, ); path = Buttons; sourceTree = ""; @@ -1060,6 +1063,7 @@ 943784F5236B77BB006A1E82 /* GraphView.swift in Sources */, D29DF32121ED0CBA003B2FB9 /* LabelView.m in Sources */, DBC4391822442197001AB423 /* CaretView.swift in Sources */, + C07065C42395677300FBF997 /* Link.swift in Sources */, D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */, D29B771022C281F400D6ACE0 /* ModuleMolecule.swift in Sources */, DBC4391922442197001AB423 /* DashLine.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift new file mode 100644 index 00000000..a89f8e71 --- /dev/null +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -0,0 +1,155 @@ +// +// Link.swift +// MVMCoreUI +// +// Created by Robinson, Blake on 11/26/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers open class Link: MFCustomButton { + + lazy var sizeObject:MFSizeObject? = { + return MFSizeObject(standardSize: 30, standardiPadPortraitSize: 36, iPadProLandscapeSize: 42) + }() + + public override init(frame: CGRect) { + super.init(frame: frame) + self.setupView() + } + + public required init?(coder: NSCoder) { + super.init(coder: coder) + self.setupView() + } + + open override func draw(_ rect: CGRect) { + guard let textRect = self.titleLabel?.frame else { return } + + let contextRef = UIGraphicsGetCurrentContext() + + //set to the same color as the text + if let color = self.titleLabel?.textColor?.cgColor { + contextRef?.setStrokeColor(color) + } + + //x should be according to the text, not the button + let x = textRect.origin.x + // line is 1 point below the text + let y = textRect.origin.y + textRect.size.height + 1 + + contextRef?.move(to: CGPoint(x: x, y: y)) + contextRef?.addLine(to: CGPoint(x: x + textRect.size.width, y: y)) + contextRef?.closePath() + contextRef?.drawPath(using: .stroke) + } + + public static func link() -> Link { + return Link.link(nil, constrainHeight: true, width: CGFloat.leastNormalMagnitude) + } + + public static func link(_ button: UIButton?, constrainHeight: Bool, width:CGFloat) -> Link { + + let link = linkHelper(button) + + //Adds the height constraint. + if let constant = link.sizeObject?.standardSize, + constrainHeight { + + let heightConstraint = NSLayoutConstraint(item: link as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: constant) + link.addConstraint(heightConstraint) + heightConstraint.isActive = true + link.heightConstraint = heightConstraint + + } else { + link.setContentHuggingPriority(.required, for: .vertical) + } + link.updateView(width) + + return link + } + + public static func linkHelper(_ button: UIButton?) -> Link { + guard let unwrappedButton = button else { return Link(type:.custom) } + guard let link = unwrappedButton as? Link else { return Link(type:.custom) } + return link + } +} + +extension Link: MVMCoreViewProtocol { + + public func updateView(_ size: CGFloat) { + MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in + guard let self = self else { return } + + var width = size + if MVMCoreGetterUtility.fequal(a: Float(CGFloat.leastNormalMagnitude), b: Float(size)) { + width = MVMCoreUISplitViewController.getApplicationViewWidth() + } + self.titleLabel?.font = MFStyler.fontB2(forWidth: width) + guard let heightConstraint = self.heightConstraint else { return } + if !MVMCoreGetterUtility.fequal(a: 0, b: Float(heightConstraint.constant)) { + guard let sizeObject = self.sizeObject else { return } + self.heightConstraint?.constant = sizeObject.getValueBased(onSize: width) + } + }) + } + + public func setupView() { + self.translatesAutoresizingMaskIntoConstraints = false; + self.backgroundColor = .clear + self.contentMode = .redraw + self.setTitleColor(UIColor.mfTextButton(), for: .normal) + self.setTitleColor(UIColor.mfCharcoal(), for: .highlighted) + // left alignment by default + self.titleLabel?.textAlignment = .left + self.contentHorizontalAlignment = .left + } +} + +extension Link: MVMCoreUIMoleculeViewProtocol { + + public func reset() { + self.setTitleColor(UIColor.mfTextButton(), for: .normal) + } + + public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + if let unwrappedJson = json { + let color = unwrappedJson.stringForkey(KeyTextColor) + setTitleColor(UIColor.mfGet(forHex: color), for: .normal) + + setWithActionMap(json, delegateObject: delegateObject, additionalData: additionalData) + + //enabling must happen after setWithActionMap is called because + //that method enables buttons when the actionMap does not contain + //disableAction = true + if let enabled = unwrappedJson[KeyEnabled] as? Bool { + isEnabled = enabled + } + } + + if let title = self.title(for: .normal), + title.isEmpty { + self.heightConstraint?.constant = 0 + } else { + guard let standardSize = sizeObject?.standardSize else { return } + self.heightConstraint?.constant = standardSize + } + } + + public static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + return 31 + } +} + +extension Link: MVMCoreUIViewConstrainingProtocol { + + public func needsToBeConstrained() -> Bool { + return true + } + + public func alignment() -> UIStackView.Alignment { + return .leading + } +} diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.h b/MVMCoreUI/Utility/MVMCoreUIConstants.h index 778ede4f..2cb09859 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.h +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.h @@ -22,6 +22,7 @@ extern NSString * const KeyDisableButton; extern NSString * const KeyValue; extern NSString * const KeyLabel; extern NSString * const KeyDisable; +extern NSString * const KeyEnabled; extern NSString * const KeyFieldName; extern NSString * const KeyHideMainMenu; diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.m b/MVMCoreUI/Utility/MVMCoreUIConstants.m index 26636266..0ac5fcdb 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.m +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.m @@ -21,6 +21,7 @@ NSString * const KeyDisableButton = @"disableAction"; NSString * const KeyValue = @"value"; NSString * const KeyLabel = @"label"; NSString * const KeyDisable = @"disable"; +NSString * const KeyEnabled = @"enabled"; NSString * const KeyFieldName = @"fieldName"; NSString * const KeyFieldKey = @"fieldKey"; NSString * const KeyRequired = @"required"; From 1d647ec662a51da4e80a74e263b6d9e2b5ebe27e Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Tue, 3 Dec 2019 15:21:45 -0500 Subject: [PATCH 02/34] Code standard change. Removed legacy-like methods. --- MVMCoreUI/Atoms/Buttons/Link.swift | 48 ++++++++++-------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index a89f8e71..ef4a1477 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -10,7 +10,7 @@ import UIKit @objcMembers open class Link: MFCustomButton { - lazy var sizeObject:MFSizeObject? = { + lazy var sizeObject: MFSizeObject? = { return MFSizeObject(standardSize: 30, standardiPadPortraitSize: 36, iPadProLandscapeSize: 42) }() @@ -24,6 +24,12 @@ import UIKit self.setupView() } + public convenience init(width:CGFloat) { + self.init() + self.setupView() + self.updateView(width) + } + open override func draw(_ rect: CGRect) { guard let textRect = self.titleLabel?.frame else { return } @@ -44,37 +50,6 @@ import UIKit contextRef?.closePath() contextRef?.drawPath(using: .stroke) } - - public static func link() -> Link { - return Link.link(nil, constrainHeight: true, width: CGFloat.leastNormalMagnitude) - } - - public static func link(_ button: UIButton?, constrainHeight: Bool, width:CGFloat) -> Link { - - let link = linkHelper(button) - - //Adds the height constraint. - if let constant = link.sizeObject?.standardSize, - constrainHeight { - - let heightConstraint = NSLayoutConstraint(item: link as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: constant) - link.addConstraint(heightConstraint) - heightConstraint.isActive = true - link.heightConstraint = heightConstraint - - } else { - link.setContentHuggingPriority(.required, for: .vertical) - } - link.updateView(width) - - return link - } - - public static func linkHelper(_ button: UIButton?) -> Link { - guard let unwrappedButton = button else { return Link(type:.custom) } - guard let link = unwrappedButton as? Link else { return Link(type:.custom) } - return link - } } extension Link: MVMCoreViewProtocol { @@ -105,6 +80,15 @@ extension Link: MVMCoreViewProtocol { // left alignment by default self.titleLabel?.textAlignment = .left self.contentHorizontalAlignment = .left + + if let constant = self.sizeObject?.standardSize { + + let heightConstraint = NSLayoutConstraint(item: self as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: constant) + self.addConstraint(heightConstraint) + heightConstraint.isActive = true + self.heightConstraint = heightConstraint + + } } } From 16cc667b02bc6218c95e1ef32300f3df5a4efeb4 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Mon, 9 Dec 2019 14:15:55 -0500 Subject: [PATCH 03/34] Expands tappable area of Link --- MVMCoreUI/Atoms/Buttons/Link.swift | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index ef4a1477..2880fcd3 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -14,6 +14,9 @@ import UIKit return MFSizeObject(standardSize: 30, standardiPadPortraitSize: 36, iPadProLandscapeSize: 42) }() + private var additionalData: [AnyHashable: Any]? + private var delegateObject: MVMCoreUIDelegateObject? + public override init(frame: CGRect) { super.init(frame: frame) self.setupView() @@ -50,6 +53,17 @@ import UIKit contextRef?.closePath() contextRef?.drawPath(using: .stroke) } + + override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool { + + let faultTolerance: CGFloat = 20.0 + let area = bounds.insetBy(dx: -faultTolerance, dy: -faultTolerance) + return area.contains(point) + } + + open override func touchesEnded(_ touches: Set, with event: UIEvent?) { + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + } } extension Link: MVMCoreViewProtocol { @@ -100,14 +114,18 @@ extension Link: MVMCoreUIMoleculeViewProtocol { public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { if let unwrappedJson = json { + actionMap = unwrappedJson + self.additionalData = additionalData + self.delegateObject = delegateObject + buttonDelegate = delegateObject?.buttonDelegate + let color = unwrappedJson.stringForkey(KeyTextColor) setTitleColor(UIColor.mfGet(forHex: color), for: .normal) - setWithActionMap(json, delegateObject: delegateObject, additionalData: additionalData) + self.titleLabel?.numberOfLines = 0 + self.titleLabel?.lineBreakMode = .byWordWrapping; + self.setTitle(actionMap?.stringForkey(KeyTitle), for: .normal) - //enabling must happen after setWithActionMap is called because - //that method enables buttons when the actionMap does not contain - //disableAction = true if let enabled = unwrappedJson[KeyEnabled] as? Bool { isEnabled = enabled } From fb2cade1574d8935a810ff78a060c8695314c038 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 12 Dec 2019 09:30:00 -0500 Subject: [PATCH 04/34] Fixed spacing before colon as per code review comment --- MVMCoreUI/Atoms/Buttons/Link.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 2880fcd3..f7dd492e 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -27,7 +27,7 @@ import UIKit self.setupView() } - public convenience init(width:CGFloat) { + public convenience init(width: CGFloat) { self.init() self.setupView() self.updateView(width) @@ -112,7 +112,7 @@ extension Link: MVMCoreUIMoleculeViewProtocol { self.setTitleColor(UIColor.mfTextButton(), for: .normal) } - public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { if let unwrappedJson = json { actionMap = unwrappedJson self.additionalData = additionalData @@ -140,7 +140,7 @@ extension Link: MVMCoreUIMoleculeViewProtocol { } } - public static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + public static func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { return 31 } } From 513583547170c5db35cc66c496fd1a1835fa6f83 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 12 Dec 2019 09:32:09 -0500 Subject: [PATCH 05/34] Removed UIColor prefix as per code review comments --- MVMCoreUI/Atoms/Buttons/Link.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index f7dd492e..b38c5f04 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -89,8 +89,8 @@ extension Link: MVMCoreViewProtocol { self.translatesAutoresizingMaskIntoConstraints = false; self.backgroundColor = .clear self.contentMode = .redraw - self.setTitleColor(UIColor.mfTextButton(), for: .normal) - self.setTitleColor(UIColor.mfCharcoal(), for: .highlighted) + self.setTitleColor(.mfTextButton(), for: .normal) + self.setTitleColor(.mfCharcoal(), for: .highlighted) // left alignment by default self.titleLabel?.textAlignment = .left self.contentHorizontalAlignment = .left @@ -109,7 +109,7 @@ extension Link: MVMCoreViewProtocol { extension Link: MVMCoreUIMoleculeViewProtocol { public func reset() { - self.setTitleColor(UIColor.mfTextButton(), for: .normal) + self.setTitleColor(.mfTextButton(), for: .normal) } public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { @@ -120,7 +120,7 @@ extension Link: MVMCoreUIMoleculeViewProtocol { buttonDelegate = delegateObject?.buttonDelegate let color = unwrappedJson.stringForkey(KeyTextColor) - setTitleColor(UIColor.mfGet(forHex: color), for: .normal) + setTitleColor(.mfGet(forHex: color), for: .normal) self.titleLabel?.numberOfLines = 0 self.titleLabel?.lineBreakMode = .byWordWrapping; From b8e0fbff75bc54256eca9d7e6e91dc8d8106bce0 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 12 Dec 2019 09:33:03 -0500 Subject: [PATCH 06/34] Removed line spaces --- MVMCoreUI/Atoms/Buttons/Link.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index b38c5f04..d3e153f8 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -96,12 +96,10 @@ extension Link: MVMCoreViewProtocol { self.contentHorizontalAlignment = .left if let constant = self.sizeObject?.standardSize { - let heightConstraint = NSLayoutConstraint(item: self as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: constant) self.addConstraint(heightConstraint) heightConstraint.isActive = true self.heightConstraint = heightConstraint - } } } From 3001f1df781e5f056377d38ec84a0a8f88fa01d7 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 12 Dec 2019 10:00:59 -0500 Subject: [PATCH 07/34] Remove self where it is not necessary for clarity --- MVMCoreUI/Atoms/Buttons/Link.swift | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index d3e153f8..1aa7b40d 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -86,18 +86,18 @@ extension Link: MVMCoreViewProtocol { } public func setupView() { - self.translatesAutoresizingMaskIntoConstraints = false; - self.backgroundColor = .clear - self.contentMode = .redraw - self.setTitleColor(.mfTextButton(), for: .normal) - self.setTitleColor(.mfCharcoal(), for: .highlighted) + translatesAutoresizingMaskIntoConstraints = false + backgroundColor = .clear + contentMode = .redraw + setTitleColor(.mfTextButton(), for: .normal) + setTitleColor(.mfCharcoal(), for: .highlighted) // left alignment by default - self.titleLabel?.textAlignment = .left - self.contentHorizontalAlignment = .left + titleLabel?.textAlignment = .left + contentHorizontalAlignment = .left if let constant = self.sizeObject?.standardSize { let heightConstraint = NSLayoutConstraint(item: self as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: constant) - self.addConstraint(heightConstraint) + addConstraint(heightConstraint) heightConstraint.isActive = true self.heightConstraint = heightConstraint } @@ -120,9 +120,9 @@ extension Link: MVMCoreUIMoleculeViewProtocol { let color = unwrappedJson.stringForkey(KeyTextColor) setTitleColor(.mfGet(forHex: color), for: .normal) - self.titleLabel?.numberOfLines = 0 - self.titleLabel?.lineBreakMode = .byWordWrapping; - self.setTitle(actionMap?.stringForkey(KeyTitle), for: .normal) + titleLabel?.numberOfLines = 0 + titleLabel?.lineBreakMode = .byWordWrapping; + setTitle(actionMap?.stringForkey(KeyTitle), for: .normal) if let enabled = unwrappedJson[KeyEnabled] as? Bool { isEnabled = enabled @@ -134,7 +134,7 @@ extension Link: MVMCoreUIMoleculeViewProtocol { self.heightConstraint?.constant = 0 } else { guard let standardSize = sizeObject?.standardSize else { return } - self.heightConstraint?.constant = standardSize + heightConstraint?.constant = standardSize } } From 3fc3b6cb0a431863a39217542beb064cb8a6e9b9 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 12 Dec 2019 10:39:21 -0500 Subject: [PATCH 08/34] Removes convenience init since updateView is called by the framework and so does not need to be part of initialization --- MVMCoreUI/Atoms/Buttons/Link.swift | 6 ------ 1 file changed, 6 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 1aa7b40d..49292fe5 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -27,12 +27,6 @@ import UIKit self.setupView() } - public convenience init(width: CGFloat) { - self.init() - self.setupView() - self.updateView(width) - } - open override func draw(_ rect: CGRect) { guard let textRect = self.titleLabel?.frame else { return } From d3dbfdd9976d7b9680750ccaaa188cc45018551c Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 12 Dec 2019 15:01:54 -0500 Subject: [PATCH 09/34] changes size object to private since it shouldn't be accessed from outside the class --- MVMCoreUI/Atoms/Buttons/Link.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 49292fe5..6107fce0 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -10,7 +10,7 @@ import UIKit @objcMembers open class Link: MFCustomButton { - lazy var sizeObject: MFSizeObject? = { + private lazy var sizeObject: MFSizeObject? = { return MFSizeObject(standardSize: 30, standardiPadPortraitSize: 36, iPadProLandscapeSize: 42) }() From 439261e4c4f6ca782c991a3f4162681a05b6ce65 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 12 Dec 2019 15:23:30 -0500 Subject: [PATCH 10/34] Make Link subclass from View instead of MFCustomButton The bounds of the Link often extend far beyond the width of the button text, which, if MFCustomButton is used, extend the tappable area far beyond the link. --- MVMCoreUI/Atoms/Buttons/Link.swift | 78 +++++++++++++++++------------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 6107fce0..99a01114 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -8,7 +8,7 @@ import UIKit -@objcMembers open class Link: MFCustomButton { +@objcMembers open class Link: View { private lazy var sizeObject: MFSizeObject? = { return MFSizeObject(standardSize: 30, standardiPadPortraitSize: 36, iPadProLandscapeSize: 42) @@ -16,6 +16,7 @@ import UIKit private var additionalData: [AnyHashable: Any]? private var delegateObject: MVMCoreUIDelegateObject? + public let linkButton = MFCustomButton() public override init(frame: CGRect) { super.init(frame: frame) @@ -28,12 +29,12 @@ import UIKit } open override func draw(_ rect: CGRect) { - guard let textRect = self.titleLabel?.frame else { return } + guard let textRect = self.linkButton.titleLabel?.frame else { return } let contextRef = UIGraphicsGetCurrentContext() //set to the same color as the text - if let color = self.titleLabel?.textColor?.cgColor { + if let color = self.linkButton.titleLabel?.textColor?.cgColor { contextRef?.setStrokeColor(color) } @@ -49,86 +50,97 @@ import UIKit } override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool { - let faultTolerance: CGFloat = 20.0 - let area = bounds.insetBy(dx: -faultTolerance, dy: -faultTolerance) + let area = linkButton.bounds.insetBy(dx: -faultTolerance, dy: -faultTolerance) return area.contains(point) } open override func touchesEnded(_ touches: Set, with event: UIEvent?) { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + if linkButton.isEnabled { + MVMCoreActionHandler.shared()?.handleAction(with: linkButton.actionMap, additionalData: additionalData, delegateObject: delegateObject) + } } } -extension Link: MVMCoreViewProtocol { +//MARK: MVMCoreViewProtocol +extension Link { - public func updateView(_ size: CGFloat) { + public override func updateView(_ size: CGFloat) { MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in guard let self = self else { return } - var width = size if MVMCoreGetterUtility.fequal(a: Float(CGFloat.leastNormalMagnitude), b: Float(size)) { width = MVMCoreUISplitViewController.getApplicationViewWidth() } - self.titleLabel?.font = MFStyler.fontB2(forWidth: width) - guard let heightConstraint = self.heightConstraint else { return } + self.linkButton.titleLabel?.font = MFStyler.fontB2(forWidth: width) + guard let heightConstraint = self.linkButton.heightConstraint else { return } if !MVMCoreGetterUtility.fequal(a: 0, b: Float(heightConstraint.constant)) { guard let sizeObject = self.sizeObject else { return } - self.heightConstraint?.constant = sizeObject.getValueBased(onSize: width) + self.linkButton.heightConstraint?.constant = sizeObject.getValueBased(onSize: width) } }) } - public func setupView() { + public override func setupView() { + linkButton.isUserInteractionEnabled = false + linkButton.translatesAutoresizingMaskIntoConstraints = false + addSubview(linkButton) + NSLayoutConstraint.activate([ + linkButton.leadingAnchor.constraint(equalTo: leadingAnchor), + linkButton.topAnchor.constraint(equalTo: topAnchor), + trailingAnchor.constraint(greaterThanOrEqualTo: linkButton.trailingAnchor), + bottomAnchor.constraint(equalTo: linkButton.bottomAnchor) + ]) translatesAutoresizingMaskIntoConstraints = false backgroundColor = .clear contentMode = .redraw - setTitleColor(.mfTextButton(), for: .normal) - setTitleColor(.mfCharcoal(), for: .highlighted) - // left alignment by default - titleLabel?.textAlignment = .left - contentHorizontalAlignment = .left + linkButton.setTitleColor(.mfTextButton(), for: .normal) + linkButton.setTitleColor(.mfCharcoal(), for: .highlighted) + linkButton.titleLabel?.textAlignment = .left + linkButton.contentHorizontalAlignment = .left if let constant = self.sizeObject?.standardSize { let heightConstraint = NSLayoutConstraint(item: self as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: constant) addConstraint(heightConstraint) heightConstraint.isActive = true - self.heightConstraint = heightConstraint + self.linkButton.heightConstraint = heightConstraint } } } -extension Link: MVMCoreUIMoleculeViewProtocol { +//MARK: MVMCoreUIMoleculeViewProtocol +extension Link { - public func reset() { - self.setTitleColor(.mfTextButton(), for: .normal) + public override func reset() { + self.linkButton.setTitleColor(.mfTextButton(), for: .normal) + self.linkButton.isEnabled = true } - public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + public override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { if let unwrappedJson = json { - actionMap = unwrappedJson + linkButton.actionMap = unwrappedJson self.additionalData = additionalData self.delegateObject = delegateObject - buttonDelegate = delegateObject?.buttonDelegate + linkButton.buttonDelegate = delegateObject?.buttonDelegate let color = unwrappedJson.stringForkey(KeyTextColor) - setTitleColor(.mfGet(forHex: color), for: .normal) + linkButton.setTitleColor(.mfGet(forHex: color), for: .normal) - titleLabel?.numberOfLines = 0 - titleLabel?.lineBreakMode = .byWordWrapping; - setTitle(actionMap?.stringForkey(KeyTitle), for: .normal) + linkButton.titleLabel?.numberOfLines = 0 + linkButton.titleLabel?.lineBreakMode = .byWordWrapping; + linkButton.setTitle(linkButton.actionMap?.stringForkey(KeyTitle), for: .normal) if let enabled = unwrappedJson[KeyEnabled] as? Bool { - isEnabled = enabled + linkButton.isEnabled = enabled } } - if let title = self.title(for: .normal), + if let title = self.linkButton.title(for: .normal), title.isEmpty { - self.heightConstraint?.constant = 0 + self.linkButton.heightConstraint?.constant = 0 } else { guard let standardSize = sizeObject?.standardSize else { return } - heightConstraint?.constant = standardSize + linkButton.heightConstraint?.constant = standardSize } } From f731b56f2ec5cd62ddadf9d2fcd0bc8d23c115e4 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Tue, 17 Dec 2019 10:23:56 -0500 Subject: [PATCH 11/34] Revert "Make Link subclass from View instead of MFCustomButton" This reverts commit 439261e4c4f6ca782c991a3f4162681a05b6ce65. --- MVMCoreUI/Atoms/Buttons/Link.swift | 78 +++++++++++++----------------- 1 file changed, 33 insertions(+), 45 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 99a01114..6107fce0 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -8,7 +8,7 @@ import UIKit -@objcMembers open class Link: View { +@objcMembers open class Link: MFCustomButton { private lazy var sizeObject: MFSizeObject? = { return MFSizeObject(standardSize: 30, standardiPadPortraitSize: 36, iPadProLandscapeSize: 42) @@ -16,7 +16,6 @@ import UIKit private var additionalData: [AnyHashable: Any]? private var delegateObject: MVMCoreUIDelegateObject? - public let linkButton = MFCustomButton() public override init(frame: CGRect) { super.init(frame: frame) @@ -29,12 +28,12 @@ import UIKit } open override func draw(_ rect: CGRect) { - guard let textRect = self.linkButton.titleLabel?.frame else { return } + guard let textRect = self.titleLabel?.frame else { return } let contextRef = UIGraphicsGetCurrentContext() //set to the same color as the text - if let color = self.linkButton.titleLabel?.textColor?.cgColor { + if let color = self.titleLabel?.textColor?.cgColor { contextRef?.setStrokeColor(color) } @@ -50,97 +49,86 @@ import UIKit } override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool { + let faultTolerance: CGFloat = 20.0 - let area = linkButton.bounds.insetBy(dx: -faultTolerance, dy: -faultTolerance) + let area = bounds.insetBy(dx: -faultTolerance, dy: -faultTolerance) return area.contains(point) } open override func touchesEnded(_ touches: Set, with event: UIEvent?) { - if linkButton.isEnabled { - MVMCoreActionHandler.shared()?.handleAction(with: linkButton.actionMap, additionalData: additionalData, delegateObject: delegateObject) - } + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } } -//MARK: MVMCoreViewProtocol -extension Link { +extension Link: MVMCoreViewProtocol { - public override func updateView(_ size: CGFloat) { + public func updateView(_ size: CGFloat) { MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in guard let self = self else { return } + var width = size if MVMCoreGetterUtility.fequal(a: Float(CGFloat.leastNormalMagnitude), b: Float(size)) { width = MVMCoreUISplitViewController.getApplicationViewWidth() } - self.linkButton.titleLabel?.font = MFStyler.fontB2(forWidth: width) - guard let heightConstraint = self.linkButton.heightConstraint else { return } + self.titleLabel?.font = MFStyler.fontB2(forWidth: width) + guard let heightConstraint = self.heightConstraint else { return } if !MVMCoreGetterUtility.fequal(a: 0, b: Float(heightConstraint.constant)) { guard let sizeObject = self.sizeObject else { return } - self.linkButton.heightConstraint?.constant = sizeObject.getValueBased(onSize: width) + self.heightConstraint?.constant = sizeObject.getValueBased(onSize: width) } }) } - public override func setupView() { - linkButton.isUserInteractionEnabled = false - linkButton.translatesAutoresizingMaskIntoConstraints = false - addSubview(linkButton) - NSLayoutConstraint.activate([ - linkButton.leadingAnchor.constraint(equalTo: leadingAnchor), - linkButton.topAnchor.constraint(equalTo: topAnchor), - trailingAnchor.constraint(greaterThanOrEqualTo: linkButton.trailingAnchor), - bottomAnchor.constraint(equalTo: linkButton.bottomAnchor) - ]) + public func setupView() { translatesAutoresizingMaskIntoConstraints = false backgroundColor = .clear contentMode = .redraw - linkButton.setTitleColor(.mfTextButton(), for: .normal) - linkButton.setTitleColor(.mfCharcoal(), for: .highlighted) - linkButton.titleLabel?.textAlignment = .left - linkButton.contentHorizontalAlignment = .left + setTitleColor(.mfTextButton(), for: .normal) + setTitleColor(.mfCharcoal(), for: .highlighted) + // left alignment by default + titleLabel?.textAlignment = .left + contentHorizontalAlignment = .left if let constant = self.sizeObject?.standardSize { let heightConstraint = NSLayoutConstraint(item: self as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: constant) addConstraint(heightConstraint) heightConstraint.isActive = true - self.linkButton.heightConstraint = heightConstraint + self.heightConstraint = heightConstraint } } } -//MARK: MVMCoreUIMoleculeViewProtocol -extension Link { +extension Link: MVMCoreUIMoleculeViewProtocol { - public override func reset() { - self.linkButton.setTitleColor(.mfTextButton(), for: .normal) - self.linkButton.isEnabled = true + public func reset() { + self.setTitleColor(.mfTextButton(), for: .normal) } - public override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { if let unwrappedJson = json { - linkButton.actionMap = unwrappedJson + actionMap = unwrappedJson self.additionalData = additionalData self.delegateObject = delegateObject - linkButton.buttonDelegate = delegateObject?.buttonDelegate + buttonDelegate = delegateObject?.buttonDelegate let color = unwrappedJson.stringForkey(KeyTextColor) - linkButton.setTitleColor(.mfGet(forHex: color), for: .normal) + setTitleColor(.mfGet(forHex: color), for: .normal) - linkButton.titleLabel?.numberOfLines = 0 - linkButton.titleLabel?.lineBreakMode = .byWordWrapping; - linkButton.setTitle(linkButton.actionMap?.stringForkey(KeyTitle), for: .normal) + titleLabel?.numberOfLines = 0 + titleLabel?.lineBreakMode = .byWordWrapping; + setTitle(actionMap?.stringForkey(KeyTitle), for: .normal) if let enabled = unwrappedJson[KeyEnabled] as? Bool { - linkButton.isEnabled = enabled + isEnabled = enabled } } - if let title = self.linkButton.title(for: .normal), + if let title = self.title(for: .normal), title.isEmpty { - self.linkButton.heightConstraint?.constant = 0 + self.heightConstraint?.constant = 0 } else { guard let standardSize = sizeObject?.standardSize else { return } - linkButton.heightConstraint?.constant = standardSize + heightConstraint?.constant = standardSize } } From 7c17889b574ddf0d50d91b415256ee206c13b60a Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 19 Dec 2019 12:23:01 -0500 Subject: [PATCH 12/34] Changed to MVMCoreUIUtility.getWidth() as per pr comments --- MVMCoreUI/Atoms/Buttons/Link.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 6107fce0..b31b2c34 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -68,7 +68,7 @@ extension Link: MVMCoreViewProtocol { var width = size if MVMCoreGetterUtility.fequal(a: Float(CGFloat.leastNormalMagnitude), b: Float(size)) { - width = MVMCoreUISplitViewController.getApplicationViewWidth() + width = MVMCoreUIUtility.getWidth() } self.titleLabel?.font = MFStyler.fontB2(forWidth: width) guard let heightConstraint = self.heightConstraint else { return } From 6e233e9babec0e320c42f301f1630e4d505fa1e0 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 19 Dec 2019 12:23:18 -0500 Subject: [PATCH 13/34] Removes self where unnecessary --- MVMCoreUI/Atoms/Buttons/Link.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index b31b2c34..068227b7 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -19,21 +19,21 @@ import UIKit public override init(frame: CGRect) { super.init(frame: frame) - self.setupView() + setupView() } public required init?(coder: NSCoder) { super.init(coder: coder) - self.setupView() + setupView() } open override func draw(_ rect: CGRect) { - guard let textRect = self.titleLabel?.frame else { return } + guard let textRect = titleLabel?.frame else { return } let contextRef = UIGraphicsGetCurrentContext() //set to the same color as the text - if let color = self.titleLabel?.textColor?.cgColor { + if let color = titleLabel?.textColor?.cgColor { contextRef?.setStrokeColor(color) } @@ -89,7 +89,7 @@ extension Link: MVMCoreViewProtocol { titleLabel?.textAlignment = .left contentHorizontalAlignment = .left - if let constant = self.sizeObject?.standardSize { + if let constant = sizeObject?.standardSize { let heightConstraint = NSLayoutConstraint(item: self as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: constant) addConstraint(heightConstraint) heightConstraint.isActive = true @@ -101,7 +101,7 @@ extension Link: MVMCoreViewProtocol { extension Link: MVMCoreUIMoleculeViewProtocol { public func reset() { - self.setTitleColor(.mfTextButton(), for: .normal) + setTitleColor(.mfTextButton(), for: .normal) } public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { @@ -123,9 +123,9 @@ extension Link: MVMCoreUIMoleculeViewProtocol { } } - if let title = self.title(for: .normal), + if let title = title(for: .normal), title.isEmpty { - self.heightConstraint?.constant = 0 + heightConstraint?.constant = 0 } else { guard let standardSize = sizeObject?.standardSize else { return } heightConstraint?.constant = standardSize From 8d417068a9f0653b5d941daddd82eb904dfdc1e0 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 19 Dec 2019 13:13:57 -0500 Subject: [PATCH 14/34] Removed heightConstraint-related logic because the heightConstraint was added to increase the tappable area of Link's predecessor, MFTextButton. --- MVMCoreUI/Atoms/Buttons/Link.swift | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 068227b7..7c78e349 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -10,10 +10,6 @@ import UIKit @objcMembers open class Link: MFCustomButton { - private lazy var sizeObject: MFSizeObject? = { - return MFSizeObject(standardSize: 30, standardiPadPortraitSize: 36, iPadProLandscapeSize: 42) - }() - private var additionalData: [AnyHashable: Any]? private var delegateObject: MVMCoreUIDelegateObject? @@ -71,11 +67,6 @@ extension Link: MVMCoreViewProtocol { width = MVMCoreUIUtility.getWidth() } self.titleLabel?.font = MFStyler.fontB2(forWidth: width) - guard let heightConstraint = self.heightConstraint else { return } - if !MVMCoreGetterUtility.fequal(a: 0, b: Float(heightConstraint.constant)) { - guard let sizeObject = self.sizeObject else { return } - self.heightConstraint?.constant = sizeObject.getValueBased(onSize: width) - } }) } @@ -88,13 +79,6 @@ extension Link: MVMCoreViewProtocol { // left alignment by default titleLabel?.textAlignment = .left contentHorizontalAlignment = .left - - if let constant = sizeObject?.standardSize { - let heightConstraint = NSLayoutConstraint(item: self as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: constant) - addConstraint(heightConstraint) - heightConstraint.isActive = true - self.heightConstraint = heightConstraint - } } } @@ -122,14 +106,6 @@ extension Link: MVMCoreUIMoleculeViewProtocol { isEnabled = enabled } } - - if let title = title(for: .normal), - title.isEmpty { - heightConstraint?.constant = 0 - } else { - guard let standardSize = sizeObject?.standardSize else { return } - heightConstraint?.constant = standardSize - } } public static func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { From 87613fb3752855ac7d3ceb356e65bc6502576728 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 19 Dec 2019 13:38:51 -0500 Subject: [PATCH 15/34] Used guard instead of if let because some code after the if let was removed --- MVMCoreUI/Atoms/Buttons/Link.swift | 31 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 7c78e349..9116cc51 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -89,22 +89,21 @@ extension Link: MVMCoreUIMoleculeViewProtocol { } public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - if let unwrappedJson = json { - actionMap = unwrappedJson - self.additionalData = additionalData - self.delegateObject = delegateObject - buttonDelegate = delegateObject?.buttonDelegate - - let color = unwrappedJson.stringForkey(KeyTextColor) - setTitleColor(.mfGet(forHex: color), for: .normal) - - titleLabel?.numberOfLines = 0 - titleLabel?.lineBreakMode = .byWordWrapping; - setTitle(actionMap?.stringForkey(KeyTitle), for: .normal) - - if let enabled = unwrappedJson[KeyEnabled] as? Bool { - isEnabled = enabled - } + guard let unwrappedJson = json else { return } + actionMap = unwrappedJson + self.additionalData = additionalData + self.delegateObject = delegateObject + buttonDelegate = delegateObject?.buttonDelegate + + let color = unwrappedJson.stringForkey(KeyTextColor) + setTitleColor(.mfGet(forHex: color), for: .normal) + + titleLabel?.numberOfLines = 0 + titleLabel?.lineBreakMode = .byWordWrapping; + setTitle(unwrappedJson.stringForkey(KeyTitle), for: .normal) + + if let enabled = unwrappedJson[KeyEnabled] as? Bool { + isEnabled = enabled } } From e11f64f0a4e298bdc3117dec298994ed6429836d Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 19 Dec 2019 13:41:27 -0500 Subject: [PATCH 16/34] Changed to optionalStringForKey --- MVMCoreUI/Atoms/Buttons/Link.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 9116cc51..10aae78b 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -100,7 +100,9 @@ extension Link: MVMCoreUIMoleculeViewProtocol { titleLabel?.numberOfLines = 0 titleLabel?.lineBreakMode = .byWordWrapping; - setTitle(unwrappedJson.stringForkey(KeyTitle), for: .normal) + if let title = unwrappedJson.optionalStringForKey(KeyTitle) { + setTitle(title, for: .normal) + } if let enabled = unwrappedJson[KeyEnabled] as? Bool { isEnabled = enabled From 5ce8446be2edbf2857fc56b8cbc4fe06dc47ab26 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 13 Jan 2020 13:31:25 -0500 Subject: [PATCH 17/34] Updating Link class. adding identifier to molecule mapping. --- MVMCoreUI/Atoms/Buttons/Link.swift | 65 ++++++++++++------- .../MVMCoreUIMoleculeMappingObject.m | 1 + 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 9008c398..394807b6 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -14,6 +14,11 @@ import UIKit //-------------------------------------------------- private var additionalData: [AnyHashable: Any]? + + //-------------------------------------------------- + // MARK: - Delegate + //-------------------------------------------------- + private var delegateObject: MVMCoreUIDelegateObject? //-------------------------------------------------- @@ -25,6 +30,10 @@ import UIKit setupView() } + public convenience init() { + self.init(frame: .zero) + } + public required init?(coder: NSCoder) { super.init(coder: coder) setupView() @@ -35,69 +44,77 @@ import UIKit //-------------------------------------------------- open override func draw(_ rect: CGRect) { + guard let textRect = titleLabel?.frame else { return } - let contextRef = UIGraphicsGetCurrentContext() + let context = UIGraphicsGetCurrentContext() - //set to the same color as the text + // Set to the same color as the text if let color = titleLabel?.textColor?.cgColor { - contextRef?.setStrokeColor(color) + context?.setStrokeColor(color) } - //x should be according to the text, not the button + // x should be according to the text, not the button let x = textRect.origin.x - // line is 1 point below the text + + // Line is 1 point below the text let y = textRect.origin.y + textRect.size.height + 1 - contextRef?.move(to: CGPoint(x: x, y: y)) - contextRef?.addLine(to: CGPoint(x: x + textRect.size.width, y: y)) - contextRef?.closePath() - contextRef?.drawPath(using: .stroke) + context?.move(to: CGPoint(x: x, y: y)) + context?.addLine(to: CGPoint(x: x + textRect.size.width, y: y)) + context?.closePath() + context?.drawPath(using: .stroke) } //-------------------------------------------------- // MARK: - UITouch //-------------------------------------------------- - override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool { - - let faultTolerance: CGFloat = 20.0 - let area = bounds.insetBy(dx: -faultTolerance, dy: -faultTolerance) - return area.contains(point) - } - open override func touchesEnded(_ touches: Set, with event: UIEvent?) { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } } +// MARK: - AppleGuidelinesProtocol +extension Link: AppleGuidelinesProtocol { + + override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool { + + return Self.acceptablyOutsideBounds(point: point, bounds: bounds) + } +} + // MARK: - MVMCoreViewProtocol extension Link: MVMCoreViewProtocol { public func updateView(_ size: CGFloat) { - MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in + + DispatchQueue.main.async { [weak self] in guard let self = self else { return } var width = size if MVMCoreGetterUtility.fequal(a: Float(CGFloat.leastNormalMagnitude), b: Float(size)) { width = MVMCoreUIUtility.getWidth() } + self.titleLabel?.font = MFStyler.fontB2(forWidth: width) - }) + } } public func setupView() { + translatesAutoresizingMaskIntoConstraints = false backgroundColor = .clear contentMode = .redraw setTitleColor(.mfTextButton(), for: .normal) setTitleColor(.mfCharcoal(), for: .highlighted) - // left alignment by default titleLabel?.textAlignment = .left contentHorizontalAlignment = .left + titleLabel?.numberOfLines = 1 } } +// MARK: - MVMCoreUIMoleculeViewProtocol extension Link: MVMCoreUIMoleculeViewProtocol { public func reset() { @@ -105,17 +122,18 @@ extension Link: MVMCoreUIMoleculeViewProtocol { } public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - guard let unwrappedJson = json else { return } - actionMap = unwrappedJson self.additionalData = additionalData self.delegateObject = delegateObject + + guard let unwrappedJson = json else { return } + actionMap = unwrappedJson + buttonDelegate = delegateObject?.buttonDelegate let color = unwrappedJson.stringForkey(KeyTextColor) setTitleColor(.mfGet(forHex: color), for: .normal) - titleLabel?.numberOfLines = 0 - titleLabel?.lineBreakMode = .byWordWrapping; + if let title = unwrappedJson.optionalStringForKey(KeyTitle) { setTitle(title, for: .normal) } @@ -130,6 +148,7 @@ extension Link: MVMCoreUIMoleculeViewProtocol { } } +// MARK:- MVMCoreUIViewConstrainingProtocol extension Link: MVMCoreUIViewConstrainingProtocol { public func needsToBeConstrained() -> Bool { diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index ecad0fc7..b43852a0 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -27,6 +27,7 @@ mapping = [@{ @"label": Label.class, @"line": Line.class, + @"link": Link.class, @"button": PrimaryButton.class, @"textButton": MFTextButton.class, @"header": StandardHeaderView.class, From 8ff92b5cc0b44762e6c067fa0a917ef476f1c367 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 13 Jan 2020 14:31:04 -0500 Subject: [PATCH 18/34] one line, truncation. --- MVMCoreUI/Atoms/Buttons/Link.swift | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 394807b6..4a23281b 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -8,6 +8,7 @@ import UIKit + @objcMembers open class Link: MFCustomButton { //-------------------------------------------------- // MARK: - Properties @@ -62,8 +63,7 @@ import UIKit context?.move(to: CGPoint(x: x, y: y)) context?.addLine(to: CGPoint(x: x + textRect.size.width, y: y)) - context?.closePath() - context?.drawPath(using: .stroke) + context?.strokePath() } //-------------------------------------------------- @@ -77,7 +77,7 @@ import UIKit // MARK: - AppleGuidelinesProtocol extension Link: AppleGuidelinesProtocol { - + override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool { return Self.acceptablyOutsideBounds(point: point, bounds: bounds) @@ -108,9 +108,10 @@ extension Link: MVMCoreViewProtocol { contentMode = .redraw setTitleColor(.mfTextButton(), for: .normal) setTitleColor(.mfCharcoal(), for: .highlighted) + titleLabel?.numberOfLines = 1 + titleLabel?.lineBreakMode = .byTruncatingTail titleLabel?.textAlignment = .left contentHorizontalAlignment = .left - titleLabel?.numberOfLines = 1 } } @@ -125,20 +126,19 @@ extension Link: MVMCoreUIMoleculeViewProtocol { self.additionalData = additionalData self.delegateObject = delegateObject - guard let unwrappedJson = json else { return } - actionMap = unwrappedJson + guard let dictionary = json else { return } + actionMap = dictionary buttonDelegate = delegateObject?.buttonDelegate - let color = unwrappedJson.stringForkey(KeyTextColor) + let color = dictionary.stringForkey(KeyTextColor) setTitleColor(.mfGet(forHex: color), for: .normal) - - if let title = unwrappedJson.optionalStringForKey(KeyTitle) { + if let title = dictionary.optionalStringForKey(KeyTitle) { setTitle(title, for: .normal) } - if let enabled = unwrappedJson[KeyEnabled] as? Bool { + if let enabled = dictionary[KeyEnabled] as? Bool { isEnabled = enabled } } From 8490ef3572191d28aaa92bd7c5042f7cb03a4f22 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 13 Jan 2020 15:46:50 -0500 Subject: [PATCH 19/34] enabled/disabled colors. --- MVMCoreUI/Atoms/Buttons/Link.swift | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 4a23281b..04484307 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -16,6 +16,15 @@ import UIKit private var additionalData: [AnyHashable: Any]? + public var titleColor: (enabled: UIColor?, disabled: UIColor?) = (.mfTextButton(), .mfSilver()) + + public override var isEnabled: Bool { + didSet { + setTitleColor(isEnabled ? titleColor.enabled : titleColor.disabled, for: .normal) + setNeedsDisplay() + } + } + //-------------------------------------------------- // MARK: - Delegate //-------------------------------------------------- @@ -50,7 +59,7 @@ import UIKit let context = UIGraphicsGetCurrentContext() - // Set to the same color as the text + // Set line to the same color as the text if let color = titleLabel?.textColor?.cgColor { context?.setStrokeColor(color) } @@ -108,6 +117,7 @@ extension Link: MVMCoreViewProtocol { contentMode = .redraw setTitleColor(.mfTextButton(), for: .normal) setTitleColor(.mfCharcoal(), for: .highlighted) + titleColor = (.mfTextButton(), .mfSilver()) titleLabel?.numberOfLines = 1 titleLabel?.lineBreakMode = .byTruncatingTail titleLabel?.textAlignment = .left @@ -125,14 +135,15 @@ extension Link: MVMCoreUIMoleculeViewProtocol { public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { self.additionalData = additionalData self.delegateObject = delegateObject + buttonDelegate = delegateObject?.buttonDelegate guard let dictionary = json else { return } actionMap = dictionary - buttonDelegate = delegateObject?.buttonDelegate - - let color = dictionary.stringForkey(KeyTextColor) - setTitleColor(.mfGet(forHex: color), for: .normal) + if let colorHex = dictionary[KeyTextColor] as? String { + titleColor.enabled = .mfGet(forHex: colorHex) + setTitleColor(titleColor.enabled, for: .normal) + } if let title = dictionary.optionalStringForKey(KeyTitle) { setTitle(title, for: .normal) From d7844d607eb038fbc34b2d177afdee1caec6a7dc Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 13 Jan 2020 16:00:00 -0500 Subject: [PATCH 20/34] space. --- MVMCoreUI/Atoms/Buttons/Link.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 04484307..4c5e6f03 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -80,6 +80,7 @@ import UIKit //-------------------------------------------------- open override func touchesEnded(_ touches: Set, with event: UIEvent?) { + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } } From 3d2137fc11821ef262314f4f2dac3359498bb430 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 13 Jan 2020 16:19:49 -0500 Subject: [PATCH 21/34] Now subclassing Button. --- MVMCoreUI/Atoms/Buttons/Link.swift | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 4c5e6f03..550870fc 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -9,7 +9,7 @@ import UIKit -@objcMembers open class Link: MFCustomButton { +@objcMembers open class Link: Button { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -85,19 +85,11 @@ import UIKit } } -// MARK: - AppleGuidelinesProtocol -extension Link: AppleGuidelinesProtocol { - - override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool { - - return Self.acceptablyOutsideBounds(point: point, bounds: bounds) - } -} - // MARK: - MVMCoreViewProtocol -extension Link: MVMCoreViewProtocol { +extension Link { - public func updateView(_ size: CGFloat) { + public override func updateView(_ size: CGFloat) { + super.updateView(size) DispatchQueue.main.async { [weak self] in guard let self = self else { return } @@ -111,7 +103,7 @@ extension Link: MVMCoreViewProtocol { } } - public func setupView() { + public override func setupView() { translatesAutoresizingMaskIntoConstraints = false backgroundColor = .clear @@ -127,13 +119,15 @@ extension Link: MVMCoreViewProtocol { } // MARK: - MVMCoreUIMoleculeViewProtocol -extension Link: MVMCoreUIMoleculeViewProtocol { +extension Link { - public func reset() { + public override func reset() { + super.reset() setTitleColor(.mfTextButton(), for: .normal) } - public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + public override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) self.additionalData = additionalData self.delegateObject = delegateObject buttonDelegate = delegateObject?.buttonDelegate From 32f85dfbf1a4d37b3355647152e034d6a2352664 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 13 Jan 2020 16:30:29 -0500 Subject: [PATCH 22/34] renamed func. changed location of action. --- MVMCoreUI/Atoms/Buttons/Link.swift | 3 +-- MVMCoreUI/BaseClasses/Button.swift | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 550870fc..1ec7e9a3 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -80,8 +80,7 @@ import UIKit //-------------------------------------------------- open override func touchesEnded(_ touches: Set, with event: UIEvent?) { - - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + callActionBlock(self) } } diff --git a/MVMCoreUI/BaseClasses/Button.swift b/MVMCoreUI/BaseClasses/Button.swift index 1d5d743e..55ac0195 100644 --- a/MVMCoreUI/BaseClasses/Button.swift +++ b/MVMCoreUI/BaseClasses/Button.swift @@ -64,10 +64,10 @@ public typealias ButtonBlock = (Button) -> () public func addBlock( event: Event, _ buttonBlock: @escaping ButtonBlock) { self.buttonBlock = buttonBlock - addTarget(self, action: #selector(callBlock(_:)), for: event) + addTarget(self, action: #selector(callActionBlock(_:)), for: event) } - func callBlock(_ sender: Button) { + func callActionBlock(_ sender: Button) { buttonBlock?(self) } @@ -90,6 +90,7 @@ public typealias ButtonBlock = (Button) -> () extension Button: MVMCoreUIMoleculeViewProtocol { public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + setWithActionMap(json, delegateObject: delegateObject, additionalData: additionalData) self.json = json guard let dictionary = json else { return } From 874addef638149acdd86d20be47a14a3380ee2e9 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 14 Jan 2020 09:06:39 -0500 Subject: [PATCH 23/34] Changed name. New disabled KV. mild updates. --- MVMCoreUI/Atoms/Buttons/Link.swift | 14 +++++--------- MVMCoreUI/BaseClasses/Button.swift | 12 ++++++------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 1ec7e9a3..3b6cabb8 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -74,14 +74,6 @@ import UIKit context?.addLine(to: CGPoint(x: x + textRect.size.width, y: y)) context?.strokePath() } - - //-------------------------------------------------- - // MARK: - UITouch - //-------------------------------------------------- - - open override func touchesEnded(_ touches: Set, with event: UIEvent?) { - callActionBlock(self) - } } // MARK: - MVMCoreViewProtocol @@ -134,6 +126,10 @@ extension Link { guard let dictionary = json else { return } actionMap = dictionary + if let disabledColorHex = dictionary["disabledColor"] as? String { + titleColor.disabled = .mfGet(forHex: disabledColorHex) + } + if let colorHex = dictionary[KeyTextColor] as? String { titleColor.enabled = .mfGet(forHex: colorHex) setTitleColor(titleColor.enabled, for: .normal) @@ -153,7 +149,7 @@ extension Link { } } -// MARK:- MVMCoreUIViewConstrainingProtocol +// MARK: - MVMCoreUIViewConstrainingProtocol extension Link: MVMCoreUIViewConstrainingProtocol { public func needsToBeConstrained() -> Bool { diff --git a/MVMCoreUI/BaseClasses/Button.swift b/MVMCoreUI/BaseClasses/Button.swift index 55ac0195..356ef59d 100644 --- a/MVMCoreUI/BaseClasses/Button.swift +++ b/MVMCoreUI/BaseClasses/Button.swift @@ -6,7 +6,7 @@ // Copyright © 2019 Verizon Wireless. All rights reserved. // -public typealias ButtonBlock = (Button) -> () +public typealias ButtonAction = (Button) -> () @objcMembers open class Button: UIButton, MFButtonProtocol { @@ -19,7 +19,7 @@ public typealias ButtonBlock = (Button) -> () private var initialSetupPerformed = false - private var buttonBlock: ButtonBlock? + private var buttonAction: ButtonAction? //-------------------------------------------------- // MARK: - Delegate @@ -62,13 +62,13 @@ public typealias ButtonBlock = (Button) -> () // MARK: - Methods //-------------------------------------------------- - public func addBlock( event: Event, _ buttonBlock: @escaping ButtonBlock) { - self.buttonBlock = buttonBlock + public func addActionBlock( event: Event, _ buttonBlock: @escaping ButtonAction) { + self.buttonAction = buttonBlock addTarget(self, action: #selector(callActionBlock(_:)), for: event) } func callActionBlock(_ sender: Button) { - buttonBlock?(self) + buttonAction?(self) } public func setWithActionMap(_ actionMap: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { @@ -76,7 +76,7 @@ public typealias ButtonBlock = (Button) -> () buttonDelegate = delegateObject?.buttonDelegate - addBlock(event: .touchUpInside) { [weak self] sender in + addActionBlock(event: .touchUpInside) { [weak self] sender in guard let self = self else { return } if self.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true { From e3b0b43272c38917d2abc15f68d74e872c5bb211 Mon Sep 17 00:00:00 2001 From: "Xinlei(Ryan) Pan" Date: Thu, 16 Jan 2020 10:30:20 -0500 Subject: [PATCH 24/34] update link method --- MVMCoreUI/Atoms/Buttons/Link.swift | 12 ++++++++++++ MVMCoreUI/BaseClasses/Button.swift | 12 ++++++++++++ .../OtherHandlers/MVMCoreUIMoleculeMappingObject.m | 1 - 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 3b6cabb8..39187ac8 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -109,6 +109,18 @@ extension Link { } } +extension Link: ModelMoleculeViewProtocol { + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + guard let model = model as? LinkModel else { return } + setTitle(model.title, for: .normal) + setTitleColor(model.textColor.uiColor, for: .normal) + isEnabled = model.enabled + backgroundColor = model.backgroundColor?.uiColor + set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) + } +} + + // MARK: - MVMCoreUIMoleculeViewProtocol extension Link { diff --git a/MVMCoreUI/BaseClasses/Button.swift b/MVMCoreUI/BaseClasses/Button.swift index 356ef59d..816063f4 100644 --- a/MVMCoreUI/BaseClasses/Button.swift +++ b/MVMCoreUI/BaseClasses/Button.swift @@ -84,6 +84,18 @@ public typealias ButtonAction = (Button) -> () } } } + + public func set(with action: ActionProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + buttonDelegate = delegateObject?.buttonDelegate + addActionBlock(event: .touchUpInside) { [weak self] (sender) in + guard let self = self else { return } + if let data = try? action.encode(using: JSONEncoder()), + let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any], + delegateObject?.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true { + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + } + } + } } // MARK: - MVMCoreUIMoleculeViewProtocol diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 19c4d9ef..5a4bfd5b 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -30,7 +30,6 @@ @"line": Line.class, @"link": Link.class, @"button": PrimaryButton.class, - @"link": MFTextButton.class, @"header": StandardHeaderView.class, @"stack": MoleculeStackView.class, @"twoButtonView": TwoButtonView.class, From 01780e708f71e350684a89adb54c63c9a94bd9c3 Mon Sep 17 00:00:00 2001 From: "Xinlei(Ryan) Pan" Date: Tue, 21 Jan 2020 15:33:10 -0500 Subject: [PATCH 25/34] update link --- MVMCoreUI/Atoms/Buttons/Link.swift | 37 ++++++------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 39187ac8..02778bce 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -30,25 +30,7 @@ import UIKit //-------------------------------------------------- private var delegateObject: MVMCoreUIDelegateObject? - - //-------------------------------------------------- - // MARK: - Initializers - //-------------------------------------------------- - - public override init(frame: CGRect) { - super.init(frame: frame) - setupView() - } - - public convenience init() { - self.init(frame: .zero) - } - - public required init?(coder: NSCoder) { - super.init(coder: coder) - setupView() - } - + //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- @@ -95,8 +77,7 @@ extension Link { } public override func setupView() { - - translatesAutoresizingMaskIntoConstraints = false + super.setupView() backgroundColor = .clear contentMode = .redraw setTitleColor(.mfTextButton(), for: .normal) @@ -118,17 +99,17 @@ extension Link: ModelMoleculeViewProtocol { backgroundColor = model.backgroundColor?.uiColor set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) } + + + public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + return 31.0 + } } // MARK: - MVMCoreUIMoleculeViewProtocol extension Link { - public override func reset() { - super.reset() - setTitleColor(.mfTextButton(), for: .normal) - } - public override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) self.additionalData = additionalData @@ -164,10 +145,6 @@ extension Link { // MARK: - MVMCoreUIViewConstrainingProtocol extension Link: MVMCoreUIViewConstrainingProtocol { - public func needsToBeConstrained() -> Bool { - return true - } - public func alignment() -> UIStackView.Alignment { return .leading } From 66ee6bbc72df38cbae180b9df91c9d5ab944458d Mon Sep 17 00:00:00 2001 From: "Xinlei(Ryan) Pan" Date: Tue, 21 Jan 2020 15:35:14 -0500 Subject: [PATCH 26/34] update mftextbutton missing --- MVMCoreUI.xcodeproj/project.pbxproj | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index ae599266..6b203dec 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -97,7 +97,6 @@ 9455B19C234F8A0400A574DB /* MVMAnimationFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9455B19B234F8A0400A574DB /* MVMAnimationFramework.framework */; }; 946EE1BA237B66D80036751F /* MoleculeModelHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1B9237B66D80036751F /* MoleculeModelHelper.swift */; }; 948DB67E2326DCD90011F916 /* MultiProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 948DB67D2326DCD90011F916 /* MultiProgress.swift */; }; - C07065C42395677300FBF997 /* Link.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07065C32395677300FBF997 /* Link.swift */; }; 94C2D9842386F3F80006CF46 /* LabelAttributeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9832386F3F80006CF46 /* LabelAttributeModel.swift */; }; 94C2D9A123872BCC0006CF46 /* LabelAttributeUnderlineModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9A023872BCC0006CF46 /* LabelAttributeUnderlineModel.swift */; }; 94C2D9A323872C110006CF46 /* LabelAttributeStrikeThroughModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9A223872C110006CF46 /* LabelAttributeStrikeThroughModel.swift */; }; @@ -107,7 +106,10 @@ 94C2D9AB23872EB50006CF46 /* LabelAttributeActionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9AA23872EB50006CF46 /* LabelAttributeActionModel.swift */; }; 94C661D923CCF4B400D9FE5B /* LeftRightLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9402C34F23A2CEA3004B974C /* LeftRightLabelModel.swift */; }; 94C661DA23CCF4FB00D9FE5B /* UIColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AA33B33239813C50067DD0F /* UIColor+Extension.swift */; }; + 94FB966223D797DA003D482B /* MFTextButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 94FB966023D797DA003D482B /* MFTextButton.h */; }; + 94FB966323D797DA003D482B /* MFTextButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 94FB966123D797DA003D482B /* MFTextButton.m */; }; C003506123AA94CD00B6AC29 /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = C003506023AA94CD00B6AC29 /* Button.swift */; }; + C07065C42395677300FBF997 /* Link.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07065C32395677300FBF997 /* Link.swift */; }; C695A67F23C9830600BFB94E /* UnOrderedListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C695A67E23C9830600BFB94E /* UnOrderedListModel.swift */; }; C695A68123C9830D00BFB94E /* NumberedListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C695A68023C9830D00BFB94E /* NumberedListModel.swift */; }; C695A69423C9909000BFB94E /* DoughnutChartModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C695A69323C9909000BFB94E /* DoughnutChartModel.swift */; }; @@ -205,10 +207,8 @@ D29DF17421E69E1F003B2FB9 /* MFCustomButton.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF16A21E69E1F003B2FB9 /* MFCustomButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29DF17521E69E1F003B2FB9 /* ButtonDelegateProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF16B21E69E1F003B2FB9 /* ButtonDelegateProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29DF17621E69E1F003B2FB9 /* PrimaryButton.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF16C21E69E1F003B2FB9 /* PrimaryButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; - D29DF17721E69E1F003B2FB9 /* MFTextButton.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF16D21E69E1F003B2FB9 /* MFTextButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29DF17A21E69E1F003B2FB9 /* MFCustomButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D29DF17021E69E1F003B2FB9 /* MFCustomButton.m */; }; D29DF17B21E69E1F003B2FB9 /* PrimaryButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D29DF17121E69E1F003B2FB9 /* PrimaryButton.m */; }; - D29DF17C21E69E1F003B2FB9 /* MFTextButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D29DF17221E69E1F003B2FB9 /* MFTextButton.m */; }; D29DF18021E69E49003B2FB9 /* MFView.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF17E21E69E2E003B2FB9 /* MFView.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29DF18121E69E50003B2FB9 /* MFView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29DF17F21E69E2E003B2FB9 /* MFView.m */; }; D29DF18221E69E54003B2FB9 /* SeparatorView.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF15921E697DA003B2FB9 /* SeparatorView.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -392,7 +392,6 @@ 9455B19B234F8A0400A574DB /* MVMAnimationFramework.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MVMAnimationFramework.framework; path = ../SharedFrameworks/MVMAnimationFramework.framework; sourceTree = ""; }; 946EE1B9237B66D80036751F /* MoleculeModelHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeModelHelper.swift; sourceTree = ""; }; 948DB67D2326DCD90011F916 /* MultiProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiProgress.swift; sourceTree = ""; }; - C07065C32395677300FBF997 /* Link.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Link.swift; sourceTree = ""; }; 94C2D9832386F3F80006CF46 /* LabelAttributeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeModel.swift; sourceTree = ""; }; 94C2D9A023872BCC0006CF46 /* LabelAttributeUnderlineModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeUnderlineModel.swift; sourceTree = ""; }; 94C2D9A223872C110006CF46 /* LabelAttributeStrikeThroughModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeStrikeThroughModel.swift; sourceTree = ""; }; @@ -400,7 +399,10 @@ 94C2D9A623872DA90006CF46 /* LabelAttributeColorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeColorModel.swift; sourceTree = ""; }; 94C2D9A823872E5E0006CF46 /* LabelAttributeImageModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeImageModel.swift; sourceTree = ""; }; 94C2D9AA23872EB50006CF46 /* LabelAttributeActionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeActionModel.swift; sourceTree = ""; }; + 94FB966023D797DA003D482B /* MFTextButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFTextButton.h; sourceTree = ""; }; + 94FB966123D797DA003D482B /* MFTextButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFTextButton.m; sourceTree = ""; }; C003506023AA94CD00B6AC29 /* Button.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Button.swift; sourceTree = ""; }; + C07065C32395677300FBF997 /* Link.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Link.swift; sourceTree = ""; }; C695A67E23C9830600BFB94E /* UnOrderedListModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnOrderedListModel.swift; sourceTree = ""; }; C695A68023C9830D00BFB94E /* NumberedListModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumberedListModel.swift; sourceTree = ""; }; C695A69323C9909000BFB94E /* DoughnutChartModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DoughnutChartModel.swift; sourceTree = ""; }; @@ -509,10 +511,8 @@ D29DF16A21E69E1F003B2FB9 /* MFCustomButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFCustomButton.h; sourceTree = ""; }; D29DF16B21E69E1F003B2FB9 /* ButtonDelegateProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ButtonDelegateProtocol.h; sourceTree = ""; }; D29DF16C21E69E1F003B2FB9 /* PrimaryButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrimaryButton.h; sourceTree = ""; }; - D29DF16D21E69E1F003B2FB9 /* MFTextButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFTextButton.h; sourceTree = ""; }; D29DF17021E69E1F003B2FB9 /* MFCustomButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFCustomButton.m; sourceTree = ""; }; D29DF17121E69E1F003B2FB9 /* PrimaryButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PrimaryButton.m; sourceTree = ""; }; - D29DF17221E69E1F003B2FB9 /* MFTextButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFTextButton.m; sourceTree = ""; }; D29DF17E21E69E2E003B2FB9 /* MFView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MFView.h; sourceTree = ""; }; D29DF17F21E69E2E003B2FB9 /* MFView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MFView.m; sourceTree = ""; }; D29DF24221E6A176003B2FB9 /* MFTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFTextField.m; sourceTree = ""; }; @@ -751,6 +751,8 @@ D213347523842FF5008E41B3 /* Views */ = { isa = PBXGroup; children = ( + 94FB966023D797DA003D482B /* MFTextButton.h */, + 94FB966123D797DA003D482B /* MFTextButton.m */, D29DF17E21E69E2E003B2FB9 /* MFView.h */, D29DF17F21E69E2E003B2FB9 /* MFView.m */, D29DF31E21ED0CBA003B2FB9 /* LabelView.h */, @@ -778,8 +780,6 @@ D22D1F45220496A30077CEC0 /* MVMCoreUISwitch.m */, D29DF16A21E69E1F003B2FB9 /* MFCustomButton.h */, D29DF17021E69E1F003B2FB9 /* MFCustomButton.m */, - D29DF16D21E69E1F003B2FB9 /* MFTextButton.h */, - D29DF17221E69E1F003B2FB9 /* MFTextButton.m */, D29DF16C21E69E1F003B2FB9 /* PrimaryButton.h */, D29DF17121E69E1F003B2FB9 /* PrimaryButton.m */, D29DF25821E6A22D003B2FB9 /* MFButtonProtocol.h */, @@ -1123,8 +1123,6 @@ D28A838C23CCDCC200DFE4FC /* PrimaryButton+MoleculeProtocolExtension.swift */, D28A838623CCCF6500DFE4FC /* MFTextButton+ModelExtension.swift */, D28A837623C79FC600DFE4FC /* MFCustomButton+ActionModel.swift */, - D29DF16D21E69E1F003B2FB9 /* MFTextButton.h */, - D29DF17221E69E1F003B2FB9 /* MFTextButton.m */, C07065C32395677300FBF997 /* Link.swift */, ); path = Buttons; @@ -1359,6 +1357,7 @@ D29DF2CE21E7C104003B2FB9 /* MFLoadingViewController.h in Headers */, 0A21DB84235E06EF00C160A2 /* MFTextField.h in Headers */, D29DF12A21E6851E003B2FB9 /* MVMCoreUITopAlertView.h in Headers */, + 94FB966223D797DA003D482B /* MFTextButton.h in Headers */, D29DF27521E79E81003B2FB9 /* MVMCoreUILoggingHandler.h in Headers */, D29DF28B21E7AC2B003B2FB9 /* ViewConstrainingView.h in Headers */, D29DF2B321E7B76D003B2FB9 /* MFLoadingSpinner.h in Headers */, @@ -1371,7 +1370,6 @@ D29DF18221E69E54003B2FB9 /* SeparatorView.h in Headers */, D29DF26E21E6AA0B003B2FB9 /* FLAnimatedImage.h in Headers */, D29DF11621E6805F003B2FB9 /* NSLayoutConstraint+MFConvenience.h in Headers */, - D29DF17721E69E1F003B2FB9 /* MFTextButton.h in Headers */, 01E569D3223FFFA500327251 /* ThreeLayerViewController.swift in Headers */, D29DF16221E69996003B2FB9 /* MFViewController.h in Headers */, 0A21DB88235E06EF00C160A2 /* MFMdnTextField.h in Headers */, @@ -1515,7 +1513,6 @@ D224798C231450C8003FCCF9 /* HeadlineBodySwitch.swift in Sources */, 017BEB442362192F0024EF95 /* MVMCoreUIMoleculeMappingObject+ModelExtension.swift in Sources */, 9445890C2385BCE300DE9FD4 /* ProgressBarModel.swift in Sources */, - D29DF17C21E69E1F003B2FB9 /* MFTextButton.m in Sources */, 9445891F2385D2E900DE9FD4 /* CaretViewModel.swift in Sources */, 01C851D323CF9E740021F976 /* LabelToggleModel.swift in Sources */, D29DF2C521E7BF57003B2FB9 /* MFTabBarSwipeAnimator.m in Sources */, @@ -1574,6 +1571,7 @@ D2B18B812360945C00A9AEDC /* View.swift in Sources */, C6FA7D5423C77A4A00A3614A /* NumberedList.swift in Sources */, D29DF26D21E6AA0B003B2FB9 /* FLAnimatedImageView.m in Sources */, + 94FB966323D797DA003D482B /* MFTextButton.m in Sources */, D260105323CEA61600764D80 /* ToggleModel.swift in Sources */, 014AA72523C501E2006F3E93 /* ContainerModel.swift in Sources */, D29DF2EF21ECEAE1003B2FB9 /* MFFonts.m in Sources */, From cc27b7e6cf2b3b8cd9a023850039945dd863c80c Mon Sep 17 00:00:00 2001 From: "Xinlei(Ryan) Pan" Date: Tue, 21 Jan 2020 15:36:22 -0500 Subject: [PATCH 27/34] public mftextbutton --- MVMCoreUI.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 6b203dec..65e1df33 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -106,7 +106,7 @@ 94C2D9AB23872EB50006CF46 /* LabelAttributeActionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9AA23872EB50006CF46 /* LabelAttributeActionModel.swift */; }; 94C661D923CCF4B400D9FE5B /* LeftRightLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9402C34F23A2CEA3004B974C /* LeftRightLabelModel.swift */; }; 94C661DA23CCF4FB00D9FE5B /* UIColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AA33B33239813C50067DD0F /* UIColor+Extension.swift */; }; - 94FB966223D797DA003D482B /* MFTextButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 94FB966023D797DA003D482B /* MFTextButton.h */; }; + 94FB966223D797DA003D482B /* MFTextButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 94FB966023D797DA003D482B /* MFTextButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; 94FB966323D797DA003D482B /* MFTextButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 94FB966123D797DA003D482B /* MFTextButton.m */; }; C003506123AA94CD00B6AC29 /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = C003506023AA94CD00B6AC29 /* Button.swift */; }; C07065C42395677300FBF997 /* Link.swift in Sources */ = {isa = PBXBuildFile; fileRef = C07065C32395677300FBF997 /* Link.swift */; }; From 25db4b1e1450059cc951b7b0c891e48ae53f537e Mon Sep 17 00:00:00 2001 From: "Xinlei(Ryan) Pan" Date: Tue, 21 Jan 2020 15:40:45 -0500 Subject: [PATCH 28/34] update link based on naming change --- MVMCoreUI/Atoms/Buttons/Link.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 02778bce..8bef1a2b 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -91,7 +91,8 @@ extension Link { } extension Link: ModelMoleculeViewProtocol { - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + + public func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { guard let model = model as? LinkModel else { return } setTitle(model.title, for: .normal) setTitleColor(model.textColor.uiColor, for: .normal) @@ -100,8 +101,7 @@ extension Link: ModelMoleculeViewProtocol { set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) } - - public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + public static func estimatedHeight(forRow molecule: ModuleMoleculeModel?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { return 31.0 } } From cd231746cf3aa4eabbf6fcb534403b00a837fc35 Mon Sep 17 00:00:00 2001 From: "Xinlei(Ryan) Pan" Date: Wed, 22 Jan 2020 10:16:18 -0500 Subject: [PATCH 29/34] update link model --- MVMCoreUI/Atoms/Buttons/Link.swift | 21 +++++---------------- MVMCoreUI/Atoms/Buttons/LinkModel.swift | 9 ++++++++- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 8bef1a2b..685ba233 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -16,15 +16,6 @@ import UIKit private var additionalData: [AnyHashable: Any]? - public var titleColor: (enabled: UIColor?, disabled: UIColor?) = (.mfTextButton(), .mfSilver()) - - public override var isEnabled: Bool { - didSet { - setTitleColor(isEnabled ? titleColor.enabled : titleColor.disabled, for: .normal) - setNeedsDisplay() - } - } - //-------------------------------------------------- // MARK: - Delegate //-------------------------------------------------- @@ -80,9 +71,8 @@ extension Link { super.setupView() backgroundColor = .clear contentMode = .redraw - setTitleColor(.mfTextButton(), for: .normal) - setTitleColor(.mfCharcoal(), for: .highlighted) - titleColor = (.mfTextButton(), .mfSilver()) + setTitleColor(.mvmBlack, for: .normal) + setTitleColor(.mvmCoolGray6, for: .disabled) titleLabel?.numberOfLines = 1 titleLabel?.lineBreakMode = .byTruncatingTail titleLabel?.textAlignment = .left @@ -96,6 +86,7 @@ extension Link: ModelMoleculeViewProtocol { guard let model = model as? LinkModel else { return } setTitle(model.title, for: .normal) setTitleColor(model.textColor.uiColor, for: .normal) + setTitleColor(model.disabledColor.uiColor, for: .disabled) isEnabled = model.enabled backgroundColor = model.backgroundColor?.uiColor set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) @@ -120,18 +111,16 @@ extension Link { actionMap = dictionary if let disabledColorHex = dictionary["disabledColor"] as? String { - titleColor.disabled = .mfGet(forHex: disabledColorHex) + setTitleColor(.mfGet(forHex: disabledColorHex), for: .disabled) } if let colorHex = dictionary[KeyTextColor] as? String { - titleColor.enabled = .mfGet(forHex: colorHex) - setTitleColor(titleColor.enabled, for: .normal) + setTitleColor(.mfGet(forHex: colorHex), for: .normal) } if let title = dictionary.optionalStringForKey(KeyTitle) { setTitle(title, for: .normal) } - if let enabled = dictionary[KeyEnabled] as? Bool { isEnabled = enabled } diff --git a/MVMCoreUI/Atoms/Buttons/LinkModel.swift b/MVMCoreUI/Atoms/Buttons/LinkModel.swift index 27cbd6c6..2f348310 100644 --- a/MVMCoreUI/Atoms/Buttons/LinkModel.swift +++ b/MVMCoreUI/Atoms/Buttons/LinkModel.swift @@ -14,7 +14,8 @@ public class LinkModel: MoleculeModelProtocol { public var title: String public var action: ActionProtocol public var enabled = true - public var textColor = Color(uiColor: .mfTextButton()) + public var textColor = Color(uiColor: .mvmBlack) + public var disabledColor = Color(uiColor: .mvmCoolGray6) public init(title: String, action: ActionProtocol) { self.title = title @@ -27,6 +28,7 @@ public class LinkModel: MoleculeModelProtocol { case action case enabled case textColor + case disabledColor } required public init(from decoder: Decoder) throws { @@ -40,6 +42,10 @@ public class LinkModel: MoleculeModelProtocol { if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor) { textColor = color } + + if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) { + disabledColor = color + } } public func encode(to encoder: Encoder) throws { @@ -49,5 +55,6 @@ public class LinkModel: MoleculeModelProtocol { try container.encodeModel(action, forKey: .action) try container.encode(enabled, forKey: .enabled) try container.encode(textColor, forKey: .textColor) + try container.encode(disabledColor, forKey: .disabledColor) } } From ab66cfae3c8800ddd9b3811853649592ee939a15 Mon Sep 17 00:00:00 2001 From: "Xinlei(Ryan) Pan" Date: Wed, 22 Jan 2020 10:42:01 -0500 Subject: [PATCH 30/34] update method --- MVMCoreUI/Atoms/Buttons/Link.swift | 65 +++++++----------------------- MVMCoreUI/BaseClasses/Button.swift | 2 +- 2 files changed, 15 insertions(+), 52 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 685ba233..6abcd48a 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -47,6 +47,20 @@ import UIKit context?.addLine(to: CGPoint(x: x + textRect.size.width, y: y)) context?.strokePath() } + + public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + super.setWithModel(model, delegateObject, additionalData) + guard let model = model as? LinkModel else { return } + setTitle(model.title, for: .normal) + setTitleColor(model.textColor.uiColor, for: .normal) + setTitleColor(model.disabledColor.uiColor, for: .disabled) + isEnabled = model.enabled + set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) + } + + public static func estimatedHeight(forRow molecule: ModuleMoleculeModel?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + return 31.0 + } } // MARK: - MVMCoreViewProtocol @@ -80,57 +94,6 @@ extension Link { } } -extension Link: ModelMoleculeViewProtocol { - - public func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { - guard let model = model as? LinkModel else { return } - setTitle(model.title, for: .normal) - setTitleColor(model.textColor.uiColor, for: .normal) - setTitleColor(model.disabledColor.uiColor, for: .disabled) - isEnabled = model.enabled - backgroundColor = model.backgroundColor?.uiColor - set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) - } - - public static func estimatedHeight(forRow molecule: ModuleMoleculeModel?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { - return 31.0 - } -} - - -// MARK: - MVMCoreUIMoleculeViewProtocol -extension Link { - - public override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - self.additionalData = additionalData - self.delegateObject = delegateObject - buttonDelegate = delegateObject?.buttonDelegate - - guard let dictionary = json else { return } - actionMap = dictionary - - if let disabledColorHex = dictionary["disabledColor"] as? String { - setTitleColor(.mfGet(forHex: disabledColorHex), for: .disabled) - } - - if let colorHex = dictionary[KeyTextColor] as? String { - setTitleColor(.mfGet(forHex: colorHex), for: .normal) - } - - if let title = dictionary.optionalStringForKey(KeyTitle) { - setTitle(title, for: .normal) - } - if let enabled = dictionary[KeyEnabled] as? Bool { - isEnabled = enabled - } - } - - public static func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { - return 31 - } -} - // MARK: - MVMCoreUIViewConstrainingProtocol extension Link: MVMCoreUIViewConstrainingProtocol { diff --git a/MVMCoreUI/BaseClasses/Button.swift b/MVMCoreUI/BaseClasses/Button.swift index e50e492f..7909d1dd 100644 --- a/MVMCoreUI/BaseClasses/Button.swift +++ b/MVMCoreUI/BaseClasses/Button.swift @@ -69,7 +69,7 @@ public typealias ButtonAction = (Button) -> () buttonAction?(self) } - public func setWithAction(_ actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + public func set(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { self.actionModel = actionModel buttonDelegate = delegateObject?.buttonDelegate From b512db7b923c5f992f5b63137fcde76a26d66fb7 Mon Sep 17 00:00:00 2001 From: "Xinlei(Ryan) Pan" Date: Wed, 22 Jan 2020 10:52:57 -0500 Subject: [PATCH 31/34] remove space --- MVMCoreUI/Atoms/Buttons/Link.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 6abcd48a..b314dd5c 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -68,15 +68,12 @@ extension Link { public override func updateView(_ size: CGFloat) { super.updateView(size) - DispatchQueue.main.async { [weak self] in guard let self = self else { return } - var width = size if MVMCoreGetterUtility.fequal(a: Float(CGFloat.leastNormalMagnitude), b: Float(size)) { width = MVMCoreUIUtility.getWidth() } - self.titleLabel?.font = MFStyler.fontB2(forWidth: width) } } From 712d18d123745dcd2d425851ab3ceac28afabc53 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 22 Jan 2020 11:12:07 -0500 Subject: [PATCH 32/34] Model organizing --- .../MVMCoreUIMoleculeMappingObject.m | 52 +------- .../OtherHandlers/MoleculeObjectMapping.swift | 116 +++++++++++------- 2 files changed, 76 insertions(+), 92 deletions(-) diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index b5a39119..ccaa9115 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -25,57 +25,7 @@ static dispatch_once_t onceToken; static NSMutableDictionary *mapping; dispatch_once(&onceToken, ^{ - mapping = [@{ - @"label": Label.class, - @"line": Line.class, - @"button": PrimaryButton.class, - @"link": MFTextButton.class, - @"header": HeaderView.class, - @"twoButtonView": TwoButtonView.class, - @"footer": FooterView.class, - @"caretView": CaretView.class, - @"caretLink": CaretButton.class, - @"textField": MFTextField.class, - @"dropDown": DropDown.class, - @"digitTextField": MFDigitTextField.class, - @"digitEntryField": DigitEntryField.class, - @"textEntryField": TextEntryField.class, - @"itemDropdownEntryField": ItemDropdownEntryField.class, - @"dateDropdownEntryField": DateDropdownEntryField.class, - @"checkbox": Checkbox.class, - @"checkboxLabel": CheckboxWithLabelView.class, - @"cornerLabels" : CornerLabels.class, - @"progressBar": ProgressBar.class, - @"circleProgress": GraphView.class, - @"multiProgressBar": MultiProgress.class, - @"radioButton": RadioButton.class, - @"radioButtonLabel": RadioButtonLabel.class, - @"listItem": MoleculeTableViewCell.class, - @"accordionListItem": AccordionMoleculeTableViewCell.class, - @"toggle": Toggle.class, - @"leftRightLabelView": LeftRightLabelView.class, - @"actionDetailWithImage": ActionDetailWithImage.class, - @"image": MFLoadImageView.class, - @"moduleMolecule": ModuleMolecule.class, - @"headlineBody": HeadlineBody.class, - @"carousel": Carousel.class, - @"carouselItem": MoleculeCollectionViewCell.class, - @"barsPager": MVMCoreUIPageControl.class, - @"scroller": Scroller.class, - @"imageHeadlineBody": ImageHeadlineBody.class, - @"labelToggle": LabelSwitch.class, - @"headlineBodyToggle": HeadlineBodySwitch.class, - @"headlineBodyLink": HeadlineBodyTextButton.class, - @"headlineBodyLinkToggle": HeadlineBodyTextButtonSwitch.class, - @"tabsListItem": TabsTableViewCell.class, - @"dropDownListItem": DropDownFilterTableViewCell.class, - @"headlineBodyButton": HeadlineBodyButton.class, - @"stackItem": MoleculeStackItem.class, - @"eyebrowHeadlineBodyLink": EyebrowHeadlineBodyLink.class, - @"headlineBodyCaretLinkImage" : HeadLineBodyCaretLinkImage.class, - @"doughnutChart": DoughnutChartView.class, - @"headLineBodyCaretLinkImage" : HeadLineBodyCaretLinkImage.class - } mutableCopy]; + mapping = [@{} mutableCopy]; }); return mapping; } diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index b9a847ac..308e8cf6 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -10,42 +10,14 @@ import Foundation @objcMembers public class MoleculeObjectMapping: NSObject { public static func registerObjects() { + // Stacks MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: MoleculeStackView.self, viewModelClass: MoleculeStackModel.self) MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Stack.self, viewModelClass: StackModel.self) - MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: MoleculeStackItem.self, viewModelClass: MoleculeStackItemModel.self) - MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: StackItem.self, viewModelClass: StackItemModel.self) - MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: StringAndMoleculeView.self, viewModelClass: StringAndMoleculeModel.self) MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: UnOrderedList.self, viewModelClass: UnOrderedListModel.self) MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: NumberedList.self, viewModelClass: NumberedListModel.self) + + // Label MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Label.self, viewModelClass: LabelModel.self) - MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: HeaderView.self, viewModelClass: HeaderModel.self) - MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: FooterView.self, viewModelClass: FooterModel.self) - MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: HeadlineBody.self, viewModelClass: HeadlineBodyModel.self) - ModelRegistry.register(MoleculeStackItemModel.self) - ModelRegistry.register(TextFieldModel.self) - ModelRegistry.register(ProgressBarModel.self) - ModelRegistry.register(MultiProgressBarModel.self) - ModelRegistry.register(CaretViewModel.self) - ModelRegistry.register(DashLineModel.self) - ModelRegistry.register(ImageViewModel.self) - ModelRegistry.register(TabsModel.self) - ModelRegistry.register(ScrollerModel.self) - ModelRegistry.register(CornerLabelsModel.self) - ModelRegistry.register(LineModel.self) - ModelRegistry.register(CircleProgressModel.self) - ModelRegistry.register(HeadlineBodyCaretLinkImageModel.self) - ModelRegistry.register(ToggleModel.self) - // buttons - ModelRegistry.register(ButtonModel.self) - ModelRegistry.register(TwoButtonViewModel.self) - ModelRegistry.register(LinkModel.self) - ModelRegistry.register(CaretLinkModel.self) - // list items - ModelRegistry.register(ListItemModel.self) - ModelRegistry.register(DropDownListItemModel.self) - ModelRegistry.register(AccordionListItemModel.self) - ModelRegistry.register(TabsListItemModel.self) - //need to move labelattributemodel to different method ModelRegistry.register(LabelAttributeFontModel.self) ModelRegistry.register(LabelAttributeColorModel.self) @@ -53,16 +25,78 @@ import Foundation ModelRegistry.register(LabelAttributeUnderlineModel.self) ModelRegistry.register(LabelAttributeStrikeThroughModel.self) ModelRegistry.register(LabelAttributeActionModel.self) + + // Buttons + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: PrimaryButton.self, viewModelClass: ButtonModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: TwoButtonView.self, viewModelClass: TwoButtonViewModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: MFTextButton.self, viewModelClass: LinkModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: CaretButton.self, viewModelClass: CaretLinkModel.self) + + // Other Atoms + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Label.self, viewModelClass: LabelModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: TextEntryField.self, viewModelClass: TextFieldModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: DropDown.self, viewModelClass: DropDownModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: ProgressBar.self, viewModelClass: ProgressBarModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: MultiProgress.self, viewModelClass: MultiProgressBarModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: CaretView.self, viewModelClass: CaretViewModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: DashLine.self, viewModelClass: DashLineModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: MFLoadImageView.self, viewModelClass: ImageViewModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Line.self, viewModelClass: LineModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: GraphView.self, viewModelClass: CircleProgressModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Toggle.self, viewModelClass: ToggleModel.self) - // - //ModelRegistry.register(ModuleMoleculeModel.self) - ModelRegistry.register(LeftRightLabelModel.self) - ModelRegistry.register(CaretViewModel.self) - ModelRegistry.register(CaretLinkModel.self) - ModelRegistry.register(LabelToggleModel.self) - ModelRegistry.register(DoughnutChartModel.self) - ModelRegistry.register(NumberedListModel.self) - ModelRegistry.register(UnOrderedListModel.self) - ModelRegistry.register(HeadlineBodyToggleModel.self) + // Horizontal Combination Molecules + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: StringAndMoleculeView.self, viewModelClass: StringAndMoleculeModel.self) + + // Vertical Combination Molecules + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: HeadlineBody.self, viewModelClass: HeadlineBodyModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: HeadLineBodyCaretLinkImage.self, viewModelClass: HeadlineBodyCaretLinkImageModel.self) + + // Left Right Molecules + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: CornerLabels.self, viewModelClass: CornerLabelsModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: LeftRightLabelView.self, viewModelClass: LeftRightLabelModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: LabelSwitch.self, viewModelClass: LabelToggleModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: HeadlineBodySwitch.self, viewModelClass: HeadlineBodyToggleModel.self) + + // List items + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: MoleculeTableViewCell.self, viewModelClass: ListItemModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: DropDownFilterTableViewCell.self, viewModelClass: DropDownListItemModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: AccordionMoleculeTableViewCell.self, viewModelClass: AccordionListItemModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: TabsTableViewCell.self, viewModelClass: TabsListItemModel.self) + + // Other Items + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: MoleculeStackItem.self, viewModelClass: MoleculeStackItemModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: StackItem.self, viewModelClass: StackItemModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: MoleculeCollectionViewCell.self, viewModelClass: CarouselItemModel.self) + + // Other Container Molecules + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: HeaderView.self, viewModelClass: HeaderModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: FooterView.self, viewModelClass: FooterModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Scroller.self, viewModelClass: ScrollerModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: ModuleMolecule.self, viewModelClass: ModuleMoleculeModel.self) + + // Other Molecules + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: DoughnutChartView.self, viewModelClass: DoughnutChartModel.self) + + // Other Organisms + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Carousel.self, viewModelClass: CarouselModel.self) + + // TODO: Need model + MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(DigitEntryField.self, forKey: "digitTextField" as NSString) + MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(DateDropdownEntryField.self, forKey: "dateDropdownEntryField" as NSString) + MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(Checkbox.self, forKey: "checkbox" as NSString) + MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(CheckboxWithLabelView.self, forKey: "checkboxLabel" as NSString) + MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(RadioButton.self, forKey: "radioButton" as NSString) + MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(RadioButtonLabel.self, forKey: "radioButtonLabel" as NSString) + MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(ActionDetailWithImage.self, forKey: "actionDetailWithImage" as NSString) + MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(MVMCoreUIPageControl.self, forKey: "barsPager" as NSString) + MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(ImageHeadlineBody.self, forKey: "imageHeadlineBody" as NSString) + MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(HeadlineBodyTextButton.self, forKey: "headlineBodyLink" as NSString) + MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(HeadlineBodyTextButtonSwitch.self, forKey: "headlineBodyLinkToggle" as NSString) + MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(HeadlineBodyButton.self, forKey: "headlineBodyButton" as NSString) + MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(EyebrowHeadlineBodyLink.self, forKey: "eyebrowHeadlineBodyLink" as NSString) + + // TODO: Need View + ModelRegistry.register(TabsModel.self) } } From d30f6314a563134c92c2de61273b155ed7012251 Mon Sep 17 00:00:00 2001 From: "Xinlei(Ryan) Pan" Date: Wed, 22 Jan 2020 11:27:24 -0500 Subject: [PATCH 33/34] remove unneeded property --- MVMCoreUI/Atoms/Buttons/Link.swift | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index b314dd5c..4a498fdd 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -10,18 +10,6 @@ import UIKit @objcMembers open class Link: Button { - //-------------------------------------------------- - // MARK: - Properties - //-------------------------------------------------- - - private var additionalData: [AnyHashable: Any]? - - //-------------------------------------------------- - // MARK: - Delegate - //-------------------------------------------------- - - private var delegateObject: MVMCoreUIDelegateObject? - //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- From d22715585e3d0ec1163a73237c68f125fb5fcdb5 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 22 Jan 2020 11:44:02 -0500 Subject: [PATCH 34/34] Eyebrow headline body to link --- MVMCoreUI.xcodeproj/project.pbxproj | 8 +++---- .../Buttons/MFTextButton+ModelExtension.swift | 21 ------------------- .../EyebrowHeadlineBodyLink.swift | 12 +---------- .../EyebrowHeadlineBodyLinkModel.swift | 19 +++++++++++++++++ .../OtherHandlers/MoleculeObjectMapping.swift | 2 +- 5 files changed, 25 insertions(+), 37 deletions(-) delete mode 100644 MVMCoreUI/Atoms/Buttons/MFTextButton+ModelExtension.swift create mode 100644 MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLinkModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index f7070766..3dbc59de 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -167,7 +167,6 @@ D28A838123CCB0D800DFE4FC /* AccordionListItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838023CCB0D800DFE4FC /* AccordionListItemModel.swift */; }; D28A838323CCBD3F00DFE4FC /* CircleProgressModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838223CCBD3F00DFE4FC /* CircleProgressModel.swift */; }; D28A838523CCCA8900DFE4FC /* ScrollerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838423CCCA8900DFE4FC /* ScrollerModel.swift */; }; - D28A838723CCCF6500DFE4FC /* MFTextButton+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838623CCCF6500DFE4FC /* MFTextButton+ModelExtension.swift */; }; D28A838923CCCFCB00DFE4FC /* LinkModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838823CCCFCB00DFE4FC /* LinkModel.swift */; }; D28A838B23CCDA6B00DFE4FC /* ButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838A23CCDA6B00DFE4FC /* ButtonModel.swift */; }; D28A838D23CCDCC200DFE4FC /* PrimaryButton+MoleculeProtocolExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838C23CCDCC200DFE4FC /* PrimaryButton+MoleculeProtocolExtension.swift */; }; @@ -300,6 +299,7 @@ D2E1FADB2260D3D200AEFD8C /* MVMCoreUIDelegateObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E1FADA2260D3D200AEFD8C /* MVMCoreUIDelegateObject.swift */; }; D2E1FADF2268B8E700AEFD8C /* ThreeLayerTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E1FADE2268B8E700AEFD8C /* ThreeLayerTableViewController.swift */; }; D2E1FAE12268E81D00AEFD8C /* MoleculeListTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E1FAE02268E81D00AEFD8C /* MoleculeListTemplate.swift */; }; + D2E2A98323D8B32D000B42E6 /* EyebrowHeadlineBodyLinkModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E2A98223D8B32D000B42E6 /* EyebrowHeadlineBodyLinkModel.swift */; }; D2FB151B23A2B65B00C20E10 /* MoleculeContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2FB151A23A2B65B00C20E10 /* MoleculeContainer.swift */; }; D2FB151D23A40F1500C20E10 /* MoleculeStackItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2FB151C23A40F1500C20E10 /* MoleculeStackItem.swift */; }; DB06250B2293456500B72DD3 /* LeftRightLabelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB06250A2293456500B72DD3 /* LeftRightLabelView.swift */; }; @@ -460,7 +460,6 @@ D28A838023CCB0D800DFE4FC /* AccordionListItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccordionListItemModel.swift; sourceTree = ""; }; D28A838223CCBD3F00DFE4FC /* CircleProgressModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircleProgressModel.swift; sourceTree = ""; }; D28A838423CCCA8900DFE4FC /* ScrollerModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollerModel.swift; sourceTree = ""; }; - D28A838623CCCF6500DFE4FC /* MFTextButton+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFTextButton+ModelExtension.swift"; sourceTree = ""; }; D28A838823CCCFCB00DFE4FC /* LinkModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkModel.swift; sourceTree = ""; }; D28A838A23CCDA6B00DFE4FC /* ButtonModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonModel.swift; sourceTree = ""; }; D28A838C23CCDCC200DFE4FC /* PrimaryButton+MoleculeProtocolExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PrimaryButton+MoleculeProtocolExtension.swift"; sourceTree = ""; }; @@ -608,6 +607,7 @@ D2E1FADA2260D3D200AEFD8C /* MVMCoreUIDelegateObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMCoreUIDelegateObject.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 = ""; }; + D2E2A98223D8B32D000B42E6 /* EyebrowHeadlineBodyLinkModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EyebrowHeadlineBodyLinkModel.swift; sourceTree = ""; }; D2F4DDE52371A4CB00CD28BB /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; D2FB151A23A2B65B00C20E10 /* MoleculeContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeContainer.swift; sourceTree = ""; }; D2FB151C23A40F1500C20E10 /* MoleculeStackItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeStackItem.swift; sourceTree = ""; }; @@ -814,6 +814,7 @@ 01EB368D23609801006832FA /* HeadlineBodyModel.swift */, D2A638FC22CA98280052ED1F /* HeadlineBody.swift */, D22479952316AF6D003FCCF9 /* HeadlineBodyTextButton.swift */, + D2E2A98223D8B32D000B42E6 /* EyebrowHeadlineBodyLinkModel.swift */, D27CD40F2339057800C1DC07 /* EyebrowHeadlineBodyLink.swift */, D28A839223CE828900DFE4FC /* HeadlineBodyCaretLinkImageModel.swift */, C7192E7C23C301750050C2A0 /* HeadLineBodyCaretLinkImage.swift */, @@ -1116,7 +1117,6 @@ D282AACA2243C61700C46919 /* ButtonView.swift */, D28A838823CCCFCB00DFE4FC /* LinkModel.swift */, D28A838C23CCDCC200DFE4FC /* PrimaryButton+MoleculeProtocolExtension.swift */, - D28A838623CCCF6500DFE4FC /* MFTextButton+ModelExtension.swift */, D28A837623C79FC600DFE4FC /* MFCustomButton+ActionModel.swift */, C07065C32395677300FBF997 /* Link.swift */, ); @@ -1511,6 +1511,7 @@ 9445891F2385D2E900DE9FD4 /* CaretViewModel.swift in Sources */, 01C851D323CF9E740021F976 /* LabelToggleModel.swift in Sources */, D29DF2C521E7BF57003B2FB9 /* MFTabBarSwipeAnimator.m in Sources */, + D2E2A98323D8B32D000B42E6 /* EyebrowHeadlineBodyLinkModel.swift in Sources */, 012A88AD238C418100FE3DA1 /* TemplateProtocol.swift in Sources */, D29DF2B421E7B76D003B2FB9 /* MFLoadingSpinner.m in Sources */, D260106323D0C05000764D80 /* StackItemModel.swift in Sources */, @@ -1527,7 +1528,6 @@ D28A838D23CCDCC200DFE4FC /* PrimaryButton+MoleculeProtocolExtension.swift in Sources */, D2A5145F2211DDC100345BFB /* MoleculeStackView.swift in Sources */, D29DF27621E79E81003B2FB9 /* MVMCoreUILoggingHandler.m in Sources */, - D28A838723CCCF6500DFE4FC /* MFTextButton+ModelExtension.swift in Sources */, C695A69623C990BC00BFB94E /* DoughnutChart.swift in Sources */, 014AA72D23C5059B006F3E93 /* StackPageTemplateModel.swift in Sources */, D260106123D0C02A00764D80 /* StackItemModelProtocol.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Buttons/MFTextButton+ModelExtension.swift b/MVMCoreUI/Atoms/Buttons/MFTextButton+ModelExtension.swift deleted file mode 100644 index dc5399ef..00000000 --- a/MVMCoreUI/Atoms/Buttons/MFTextButton+ModelExtension.swift +++ /dev/null @@ -1,21 +0,0 @@ -// -// MFTextButton_ModelExtension.swift -// MVMCoreUI -// -// Created by Scott Pfeil on 1/13/20. -// Copyright © 2020 Verizon Wireless. All rights reserved. -// - -import UIKit - -// temporary until link is finished -extension MFTextButton: ModelMoleculeViewProtocol { - public func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { - guard let model = model as? LinkModel else { return } - setTitle(model.title, for: .normal) - setTitleColor(model.textColor.uiColor, for: .normal) - isEnabled = model.enabled - backgroundColor = model.backgroundColor?.uiColor - set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) - } -} diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift index 3f5d13aa..77a479c5 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift @@ -8,22 +8,12 @@ import UIKit -struct EyebrowHeadlineBodyLinkModel: MoleculeModelProtocol { - static var identifier: String = "eyebrowHeadlineBodyLink" - var backgroundColor: Color? - - public var eyeBrow: LabelModel? - public var headline: LabelModel? - public var body: LabelModel? - public var link: LineModel? -} - @objcMembers open class EyebrowHeadlineBodyLink: Container { let stack = Stack(frame: .zero) let eyebrow = Label.commonLabelB3(true) let headline = Label.commonLabelB1(true) let body = Label.commonLabelB2(true) - let link = MFTextButton(nil, constrainHeight: false, forWidth: MVMCoreUIUtility.getWidth()) + let link = Link() var casteModel: EyebrowHeadlineBodyLinkModel? { get { return model as? EyebrowHeadlineBodyLinkModel } } diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLinkModel.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLinkModel.swift new file mode 100644 index 00000000..e9341535 --- /dev/null +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLinkModel.swift @@ -0,0 +1,19 @@ +// +// EyebrowHeadlineBodyLinkModel.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 1/22/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +struct EyebrowHeadlineBodyLinkModel: MoleculeModelProtocol { + static var identifier: String = "eyebrowHeadlineBodyLink" + var backgroundColor: Color? + + public var eyeBrow: LabelModel? + public var headline: LabelModel? + public var body: LabelModel? + public var link: LinkModel? +} diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 528351d3..59e7cdef 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -51,6 +51,7 @@ import Foundation // Vertical Combination Molecules MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: HeadlineBody.self, viewModelClass: HeadlineBodyModel.self) MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: HeadLineBodyCaretLinkImage.self, viewModelClass: HeadlineBodyCaretLinkImageModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: EyebrowHeadlineBodyLink.self, viewModelClass: EyebrowHeadlineBodyLinkModel.self) // Left Right Molecules MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: CornerLabels.self, viewModelClass: CornerLabelsModel.self) @@ -94,7 +95,6 @@ import Foundation MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(HeadlineBodyTextButton.self, forKey: "headlineBodyLink" as NSString) MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(HeadlineBodyTextButtonSwitch.self, forKey: "headlineBodyLinkToggle" as NSString) MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(HeadlineBodyButton.self, forKey: "headlineBodyButton" as NSString) - MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(EyebrowHeadlineBodyLink.self, forKey: "eyebrowHeadlineBodyLink" as NSString) // TODO: Need View ModelRegistry.register(TabsModel.self)