From 1d843ae29a6c2eafcaf5227ef4f97d2e3009fbb9 Mon Sep 17 00:00:00 2001 From: "Murugan, Vimal" Date: Thu, 26 Dec 2019 19:33:37 +0530 Subject: [PATCH 1/6] main thread update access modifier update --- MVMCoreUI/Molecules/MFTextFieldListView.swift | 24 ++++++++++++++----- .../TextFieldListFormViewController.swift | 14 +++++------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/MVMCoreUI/Molecules/MFTextFieldListView.swift b/MVMCoreUI/Molecules/MFTextFieldListView.swift index 6d24e19a..6655cf01 100644 --- a/MVMCoreUI/Molecules/MFTextFieldListView.swift +++ b/MVMCoreUI/Molecules/MFTextFieldListView.swift @@ -46,7 +46,7 @@ public class MFTextFieldListView: ViewConstrainingView { var viewList: [UIView] = [] for textFieldMap in textFieldMapList { - if let textField = MFTextField(map: textFieldMap, bothDelegates: self) { + if let textField = getTextFieldForMap(textFieldMap) { if textFieldMap.boolForKey("required") { textFieldsToValidate.append(textField) @@ -76,13 +76,25 @@ public class MFTextFieldListView: ViewConstrainingView { } public func getTextParamsList() -> [String: Any] { - var extraParam: [String: Any] = [:] - for textField in textFields { - if let fieldKey = textField.fieldKey { - extraParam[fieldKey as String] = textField.text ?? "" + return DispatchQueue.main.sync { + var extraParam: [String: Any] = [:] + for textField in textFields { + if let fieldKey = textField.fieldKey { + extraParam[fieldKey as String] = textField.text ?? "" + } } + return extraParam } - return extraParam + } + + private func getTextFieldForMap(_ map: [String: Any]) -> MFTextField? { + if map.boolForKey("dropDown") { + let dropDownFld = DropDown(map: map, bothDelegates: self) + dropDownFld?.setWithJSON(map, delegateObject: parentViewContoller?.delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil) + dropDownFld?.showDropDown(true) + return dropDownFld + } + return MFTextField(map: map, bothDelegates: self) } } diff --git a/MVMCoreUI/Templates/TextFieldListFormViewController.swift b/MVMCoreUI/Templates/TextFieldListFormViewController.swift index bf3b0bea..6aa3eec7 100644 --- a/MVMCoreUI/Templates/TextFieldListFormViewController.swift +++ b/MVMCoreUI/Templates/TextFieldListFormViewController.swift @@ -8,26 +8,26 @@ import UIKit -public class TextFieldListFormViewController: TopLabelsAndBottomButtonsViewController { +open class TextFieldListFormViewController: TopLabelsAndBottomButtonsViewController { public var textFieldListView: MFTextFieldListView? - public override func viewDidLoad() { + open override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } - public override func updateViews() { + open override func updateViews() { super.updateViews() } - public override func newDataBuildScreen() { + open override func newDataBuildScreen() { super.newDataBuildScreen() topLabelsView?.separatorView?.isHidden = true } - public override func buildViewsBetweenLabelsAndButtons() -> [UIView]? { + open override func buildViewsBetweenLabelsAndButtons() -> [UIView]? { var viewList: [UIView] = [] if let textFieldsList = loadObject?.pageJSON?.arrayForKey("textFieldList") as? [[String: Any]] { @@ -40,12 +40,12 @@ public class TextFieldListFormViewController: TopLabelsAndBottomButtonsViewContr return viewList } - public override func handleOpenPage(for requestParameters: MVMCoreRequestParameters, actionInformation: [AnyHashable : Any]?, additionalData: [AnyHashable : Any]?) { + open override func handleOpenPage(for requestParameters: MVMCoreRequestParameters, actionInformation: [AnyHashable : Any]?, additionalData: [AnyHashable : Any]?) { textFieldListView?.addParams(requestParameters: requestParameters) super.handleOpenPage(for: requestParameters, actionInformation: actionInformation, additionalData: additionalData) } - public override func spaceAboveBetweenView() -> NSNumber? { + open override func spaceAboveBetweenView() -> NSNumber? { return PaddingFour as NSNumber } From ccc535360c2a690ff48012f2bed7c3252b25f2d3 Mon Sep 17 00:00:00 2001 From: "Murugan, Vimal" Date: Fri, 27 Dec 2019 13:02:13 +0530 Subject: [PATCH 2/6] protocol implementation --- MVMCoreUI/Molecules/MFTextFieldListView.swift | 8 ++++++++ .../TextFieldListFormViewController.swift | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Molecules/MFTextFieldListView.swift b/MVMCoreUI/Molecules/MFTextFieldListView.swift index 6655cf01..c695c3a3 100644 --- a/MVMCoreUI/Molecules/MFTextFieldListView.swift +++ b/MVMCoreUI/Molecules/MFTextFieldListView.swift @@ -9,6 +9,10 @@ import UIKit import MVMCore +@objc public protocol TextFieldListHelperProtocol { + @objc optional func fieldForMap(_ map: [String: Any], textField: MFTextField) + @objc optional func spaceBetweenField() -> CGFloat +} public class MFTextFieldListView: ViewConstrainingView { @@ -48,6 +52,8 @@ public class MFTextFieldListView: ViewConstrainingView { for textFieldMap in textFieldMapList { if let textField = getTextFieldForMap(textFieldMap) { + (parentViewContoller as? TextFieldListHelperProtocol)?.fieldForMap?(textFieldMap, textField: textField) + if textFieldMap.boolForKey("required") { textFieldsToValidate.append(textField) } @@ -60,11 +66,13 @@ public class MFTextFieldListView: ViewConstrainingView { } } + let spaceBtwField = (parentViewContoller as? TextFieldListHelperProtocol)?.spaceBetweenField?() ?? 0.0 StackableViewController.populateView(self, withUIArray: viewList) { (viewObject) -> UIEdgeInsets in var edgeInsets = StackableViewController.standardSpaceAroundUIObject() edgeInsets.left = 0 edgeInsets.right = 0 edgeInsets.top = 0 + edgeInsets.bottom = spaceBtwField return edgeInsets } diff --git a/MVMCoreUI/Templates/TextFieldListFormViewController.swift b/MVMCoreUI/Templates/TextFieldListFormViewController.swift index 6aa3eec7..c0509679 100644 --- a/MVMCoreUI/Templates/TextFieldListFormViewController.swift +++ b/MVMCoreUI/Templates/TextFieldListFormViewController.swift @@ -8,7 +8,7 @@ import UIKit -open class TextFieldListFormViewController: TopLabelsAndBottomButtonsViewController { +open class TextFieldListFormViewController: TopLabelsAndBottomButtonsViewController, TextFieldListHelperProtocol { public var textFieldListView: MFTextFieldListView? @@ -30,7 +30,7 @@ open class TextFieldListFormViewController: TopLabelsAndBottomButtonsViewControl open override func buildViewsBetweenLabelsAndButtons() -> [UIView]? { var viewList: [UIView] = [] - if let textFieldsList = loadObject?.pageJSON?.arrayForKey("textFieldList") as? [[String: Any]] { + if let textFieldsList = textFieldsLists() { let textFieldListView = MFTextFieldListView(textFieldMapList: textFieldsList, parentViewContoller: self, primaryButton: self.primaryButton) @@ -48,5 +48,18 @@ open class TextFieldListFormViewController: TopLabelsAndBottomButtonsViewControl open override func spaceAboveBetweenView() -> NSNumber? { return PaddingFour as NSNumber } + + open func textFieldsLists() -> [[String: Any]]? { + return loadObject?.pageJSON?.arrayForKey("textFieldList") as? [[String: Any]] + } + + //MARK: - Textfield list protocol + open func spaceBetweenField() -> CGFloat { + return 0.0 + } + + open func fieldForMap(_ map: [String : Any], textField: MFTextField) { + + } } From e5ca7b5c9e2996091496750180a871843d3cbf97 Mon Sep 17 00:00:00 2001 From: "Murugan, Vimal" Date: Thu, 2 Jan 2020 21:33:31 +0530 Subject: [PATCH 3/6] bullet list molecule added --- MVMCoreUI.xcodeproj/project.pbxproj | 4 + MVMCoreUI/Molecules/BulletList.swift | 233 ++++++++++++++++++ .../MVMCoreUIMoleculeMappingObject.m | 3 +- 3 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 MVMCoreUI/Molecules/BulletList.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index e8c26f4c..14506f07 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 */; }; + C63D632123BDC3A0008F3B1F /* BulletList.swift in Sources */ = {isa = PBXBuildFile; fileRef = C63D632023BDC3A0008F3B1F /* BulletList.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 */; }; @@ -233,6 +234,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 = ""; }; + C63D632023BDC3A0008F3B1F /* BulletList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BulletList.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 = ""; }; @@ -633,6 +635,7 @@ 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */, 017BEB372360C6AC0024EF95 /* RadioButtonLabel.swift */, D2FB151A23A2B65B00C20E10 /* MoleculeContainer.swift */, + C63D632023BDC3A0008F3B1F /* BulletList.swift */, ); path = Molecules; sourceTree = ""; @@ -1177,6 +1180,7 @@ 0A41BA6E2344FCD400D4C0BC /* CATransaction+Extension.swift in Sources */, D29DF13221E6851E003B2FB9 /* MVMCoreUITopAlertBaseView.m in Sources */, D29DF29C21E7ADB9003B2FB9 /* MFProgrammaticTableViewController.m in Sources */, + C63D632123BDC3A0008F3B1F /* BulletList.swift in Sources */, 0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */, 0A1214A022C11A18007C7030 /* ActionDetailWithImage.swift in Sources */, D2B18B922361E65A00A9AEDC /* CoreUIObject.swift in Sources */, diff --git a/MVMCoreUI/Molecules/BulletList.swift b/MVMCoreUI/Molecules/BulletList.swift new file mode 100644 index 00000000..f680b36a --- /dev/null +++ b/MVMCoreUI/Molecules/BulletList.swift @@ -0,0 +1,233 @@ +// +// BulletList.swift +// MVMCoreUI +// +// Created by Murugan, Vimal on 02/01/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + +open class BulletList: Container { + + var contentView = MVMCoreUICommonViewsUtility.commonView() + var reusableViews: [LeftRightLabelView] = [] + var bulletChar: String? + + /// Restacks the existing items. + func restack() { + //setWithStackItems(items) + } + + /// Removes all stack items views from the view. + func removeAllItemInViews() { + reusableViews.forEach({ $0.removeFromSuperview() }) + } + + /// The spacing to use between each item in the stack. + var verticalSpacing: CGFloat = 8 { + didSet { + if verticalSpacing != oldValue { + restack() + } + } + } + + // MARK: - Inits + public override init() { + super.init() + } + + public override init(frame: CGRect) { + super.init(frame: frame) + } + + public init(withJSON json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + super.init(frame: CGRect.zero) + setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + } + + public required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + // MARK: - Helpers + public func pinView(_ view: UIView, toView: UIView, attribute: NSLayoutConstraint.Attribute, relation: NSLayoutConstraint.Relation, priority: UILayoutPriority, constant: CGFloat) { + let constraint = NSLayoutConstraint(item: view, attribute: attribute, relatedBy: relation, toItem: toView, attribute: attribute, multiplier: 1.0, constant: constant) + constraint.priority = priority + constraint.isActive = true + } + + // MARK: - MFViewProtocol + public override func setupView() { + super.setupView() + guard contentView.superview == nil else { + return + } + MVMCoreUIUtility.setMarginsFor(contentView, leading: 0, top: 0, trailing: 0, bottom: 0) + translatesAutoresizingMaskIntoConstraints = false + backgroundColor = .clear + addSubview(contentView) + containerHelper.constrainView(contentView) + contentView.setContentHuggingPriority(.defaultHigh, for: .vertical) + contentView.setContentHuggingPriority(.defaultHigh, for: .horizontal) + } + + public override func updateView(_ size: CGFloat) { + super.updateView(size) + directionalLayoutMargins.leading = 0 + directionalLayoutMargins.trailing = 0 + } + + // MARK: - MVMCoreUIMoleculeViewProtocol + public override func reset() { + super.reset() + backgroundColor = .clear + } + + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + // let previousJSON = self.json + super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + removeAllItemInViews() + guard let list = json?.arrayForKey("list") as? [[String: Any]] else { + return + } + + bulletChar = json?.optionalStringForKey("bulletChar") + + var views = [LeftLabelRightContainer]() + // Adds the molecules and sets the json. + for (index, map) in list.enumerated() { + let view = LeftLabelRightContainer() + let moleculeMap = ["left": leftItem(bulletChar ?? String(index + 1)), "right": map] + view.setWithJSON(moleculeMap, delegateObject: delegateObject, additionalData: additionalData) + views.append(view) + } + let lastObj = views.last + MVMCoreUIStackableViewController.populateView(contentView, withUIArray: views) { (obj) -> UIEdgeInsets in + return UIEdgeInsets(top: 0, left: 0, bottom: lastObj?.isEqual(obj) ?? false ? 0 : 16, right: 0) + } + } + + public class func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { + // This will aggregate names of molecules to make an id. + guard let molecules = molecule?.optionalArrayForKey("list") else { + return "stack<>" + } + var name = "stack<" + for case let item as [AnyHashable: Any] in molecules { + if let molecule = item.optionalDictionaryForKey(KeyMolecule), let moleculeName = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: molecule)?.name?(forReuse: molecule, delegateObject: delegateObject) ?? molecule.optionalStringForKey(KeyMoleculeName) { + name.append(moleculeName + ",") + } + } + name.append(">") + return name + } + + public class func requiredModules(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { + guard let items = json?.optionalArrayForKey("list") else { + return nil + } + var modules: [String] = [] + for case let item as [AnyHashable: AnyHashable] in items { + if let molecule = item.optionalDictionaryForKey(KeyMolecule), let modulesForMolecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: molecule)?.requiredModules?(molecule, delegateObject: delegateObject, error: error) { + modules += modulesForMolecule + } + } + return modules.count > 0 ? modules : nil + } + + func leftItem(_ string: String) -> [String: Any] { + return ["moleculeName":"label","text":string, "fontStyle":"B2"] + } + +} + +class LeftLabelRightContainer: View { + + var label = Label.commonLabelB2(true) + var rightContainer = MVMCoreUICommonViewsUtility.commonView() + var leftContainer = MVMCoreUICommonViewsUtility.commonView() + var rightMoleculeName: String? + var rightMolecule: View? + let containerHelper = ContainerHelper() + + var constraintBtwViews: NSLayoutConstraint? + var spaceBtwViews: CGFloat = 8 { + didSet { + if spaceBtwViews != oldValue { + constraintBtwViews?.constant = spaceBtwViews + layoutIfNeeded() + } + } + } + + override func setupView() { + super.setupView() + + guard rightContainer.superview == nil else { + return + } + + translatesAutoresizingMaskIntoConstraints = false + addSubview(rightContainer) + addSubview(leftContainer) + leftContainer.addSubview(label) + NSLayoutConstraint.constraintPinSubview(toSuperview: label) + + NSLayoutConstraint.constraintPinSubview(leftContainer, pinTop: true, pinBottom: false, pinLeft: true, pinRight: false) + bottomAnchor.constraint(greaterThanOrEqualTo: leftContainer.bottomAnchor).isActive = true + + NSLayoutConstraint.constraintPinSubview(rightContainer, pinTop: true, pinBottom: true, pinLeft: false, pinRight: true) + constraintBtwViews = rightContainer.leftAnchor.constraint(equalTo: leftContainer.rightAnchor, constant: spaceBtwViews) + constraintBtwViews?.priority = .required + constraintBtwViews?.isActive = true + + //TODO: Need to get confirmation on this + leftContainer.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 0.05, constant: 0).isActive = true + setContentHuggingPriority(.defaultHigh, for: .vertical) + setContentHuggingPriority(.defaultHigh, for: .horizontal) + rightContainer.setContentHuggingPriority(.defaultHigh, for: .vertical) + rightContainer.setContentHuggingPriority(.defaultHigh, for: .horizontal) + + label.setContentHuggingPriority(.defaultHigh, for: .horizontal) + label.setContentHuggingPriority(.defaultHigh, for: .vertical) + + } + + override func updateView(_ size: CGFloat) { + super.updateView(size) + } + + override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + let previousMoleculeName = rightMoleculeName + guard let moleculeJSON = json?.optionalDictionaryForKey("right") else { + removeSubviewsInRightContainer() + return + } + + Label.setUILabel(label, withJSON: json?.optionalDictionaryForKey("left"), delegate: delegateObject, additionalData: additionalData) + rightMoleculeName = moleculeJSON.optionalStringForKey(KeyMoleculeName) + //For reuse purpose check that allready added molecule is same + if rightMolecule != nil && previousMoleculeName == rightMoleculeName { + rightMolecule?.setWithJSON(json?.optionalDictionaryForKey("right"), delegateObject: delegateObject, additionalData: additionalData) + } else { + removeSubviewsInRightContainer() + if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: false) { + addView(molecule) + } + } + } + + func removeSubviewsInRightContainer() { + rightContainer.subviews.forEach({ $0.removeFromSuperview() }) + } + + func addView(_ view: UIView) { + view.translatesAutoresizingMaskIntoConstraints = false + rightContainer.addSubview(view) + containerHelper.constrainView(view) + rightMolecule = view as? View + } +} diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 9db7822d..47bbac98 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -66,7 +66,8 @@ @"tabsListItem": TabsTableViewCell.class, @"dropDownListItem": DropDownFilterTableViewCell.class, @"headlineBodyButton": HeadlineBodyButton.class, - @"eyebrowHeadlineBodyLink": EyebrowHeadlineBodyLink.class + @"eyebrowHeadlineBodyLink": EyebrowHeadlineBodyLink.class, + @"bulletList": BulletList.class } mutableCopy]; }); return mapping; From dd49c439462e02321657788a566efca17190a792 Mon Sep 17 00:00:00 2001 From: "Murugan, Vimal" Date: Fri, 3 Jan 2020 20:18:30 +0530 Subject: [PATCH 4/6] code cleanup --- MVMCoreUI/Molecules/BulletList.swift | 137 ++++++++++++++++++--------- 1 file changed, 94 insertions(+), 43 deletions(-) diff --git a/MVMCoreUI/Molecules/BulletList.swift b/MVMCoreUI/Molecules/BulletList.swift index f680b36a..5cb0dbd4 100644 --- a/MVMCoreUI/Molecules/BulletList.swift +++ b/MVMCoreUI/Molecules/BulletList.swift @@ -11,28 +11,14 @@ import UIKit open class BulletList: Container { var contentView = MVMCoreUICommonViewsUtility.commonView() - var reusableViews: [LeftRightLabelView] = [] + var reusableViews: [LeftLabelRightMoleculeContainer] = [] var bulletChar: String? - /// Restacks the existing items. - func restack() { - //setWithStackItems(items) - } - /// Removes all stack items views from the view. func removeAllItemInViews() { reusableViews.forEach({ $0.removeFromSuperview() }) } - /// The spacing to use between each item in the stack. - var verticalSpacing: CGFloat = 8 { - didSet { - if verticalSpacing != oldValue { - restack() - } - } - } - // MARK: - Inits public override init() { super.init() @@ -77,46 +63,72 @@ open class BulletList: Container { super.updateView(size) directionalLayoutMargins.leading = 0 directionalLayoutMargins.trailing = 0 + reusableViews.forEach({ $0.updateView(size) }) } // MARK: - MVMCoreUIMoleculeViewProtocol public override func reset() { super.reset() backgroundColor = .clear + reusableViews.forEach({ $0.reset() }) } open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - // let previousJSON = self.json + let previousJSON = self.json super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) removeAllItemInViews() + // If the items in the stack are the same, just update previous items instead of re-allocating. + var items: [LeftLabelRightMoleculeContainer]? + if BulletList.name(forReuse: previousJSON, delegateObject: delegateObject) == BulletList.name(forReuse: json, delegateObject: delegateObject) { + items = self.reusableViews + } + self.reusableViews = [] + guard let list = json?.arrayForKey("list") as? [[String: Any]] else { return } bulletChar = json?.optionalStringForKey("bulletChar") - - var views = [LeftLabelRightContainer]() // Adds the molecules and sets the json. for (index, map) in list.enumerated() { - let view = LeftLabelRightContainer() - let moleculeMap = ["left": leftItem(bulletChar ?? String(index + 1)), "right": map] - view.setWithJSON(moleculeMap, delegateObject: delegateObject, additionalData: additionalData) - views.append(view) + if let item = items?[index] { + item.leftText = bulletChar + item.setWithJSON(map, delegateObject: delegateObject, additionalData: nil) + addView(item, lastItem: index == list.count - 1) + } else { + let leftLabel = LeftLabelRightMoleculeContainer() + leftLabel.leftText = bulletChar + leftLabel.setWithJSON(map, delegateObject: delegateObject, additionalData: additionalData) + addView(leftLabel, lastItem: index == list.count - 1) + } } - let lastObj = views.last - MVMCoreUIStackableViewController.populateView(contentView, withUIArray: views) { (obj) -> UIEdgeInsets in - return UIEdgeInsets(top: 0, left: 0, bottom: lastObj?.isEqual(obj) ?? false ? 0 : 16, right: 0) + } + + func addView(_ container: LeftLabelRightMoleculeContainer, lastItem: Bool) { + container.translatesAutoresizingMaskIntoConstraints = false + contentView.addSubview(container) + let first = reusableViews.first == nil + if first { + pinView(container, toView: contentView, attribute: .top, relation: .equal, priority: .required, constant: 16) + } else if let previousView = reusableViews.last { + container.topAnchor.constraint(equalTo: previousView.bottomAnchor, constant: 16).isActive = true } + pinView(container, toView: contentView, attribute: .leading, relation: .equal, priority: .required, constant: 0) + pinView(contentView, toView: container, attribute: .trailing, relation: .equal, priority: .required, constant: 0) + if lastItem { + pinView(contentView, toView: container, attribute: .bottom, relation: .equal, priority: .required, constant: 0) + } + reusableViews.append(container) } public class func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { // This will aggregate names of molecules to make an id. guard let molecules = molecule?.optionalArrayForKey("list") else { - return "stack<>" + return "unordered<>" } - var name = "stack<" + var name = "unordered<" for case let item as [AnyHashable: Any] in molecules { - if let molecule = item.optionalDictionaryForKey(KeyMolecule), let moleculeName = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: molecule)?.name?(forReuse: molecule, delegateObject: delegateObject) ?? molecule.optionalStringForKey(KeyMoleculeName) { + if let moleculeName = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: item)?.name?(forReuse: molecule, delegateObject: delegateObject) ?? item.optionalStringForKey(KeyMoleculeName) { name.append(moleculeName + ",") } } @@ -124,26 +136,36 @@ open class BulletList: Container { return name } + public class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + guard let items = json?.optionalArrayForKey("list") else { + return 0 + } + var estimatedHeight: CGFloat = 0 + for case let item as [AnyHashable: AnyHashable] in items { + if let _ = item.optionalStringForKey(KeyMoleculeName) { + let height = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: item)?.estimatedHeight?(forRow: item, delegateObject: delegateObject) + estimatedHeight += ((height ?? 0) + 16) + } + } + return estimatedHeight + } + public class func requiredModules(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { guard let items = json?.optionalArrayForKey("list") else { return nil } var modules: [String] = [] for case let item as [AnyHashable: AnyHashable] in items { - if let molecule = item.optionalDictionaryForKey(KeyMolecule), let modulesForMolecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: molecule)?.requiredModules?(molecule, delegateObject: delegateObject, error: error) { + if let modulesForMolecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: item)?.requiredModules?(item, delegateObject: delegateObject, error: error) { modules += modulesForMolecule } } return modules.count > 0 ? modules : nil } - - func leftItem(_ string: String) -> [String: Any] { - return ["moleculeName":"label","text":string, "fontStyle":"B2"] - } } -class LeftLabelRightContainer: View { +class LeftLabelRightMoleculeContainer: View { var label = Label.commonLabelB2(true) var rightContainer = MVMCoreUICommonViewsUtility.commonView() @@ -151,6 +173,7 @@ class LeftLabelRightContainer: View { var rightMoleculeName: String? var rightMolecule: View? let containerHelper = ContainerHelper() + var leftText: String? var constraintBtwViews: NSLayoutConstraint? var spaceBtwViews: CGFloat = 8 { @@ -162,6 +185,24 @@ class LeftLabelRightContainer: View { } } + // MARK: - Inits + public override init() { + super.init() + } + + public override init(frame: CGRect) { + super.init(frame: frame) + } + + public init(withJSON json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + super.init(frame: CGRect.zero) + setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + } + + public required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + override func setupView() { super.setupView() @@ -173,7 +214,9 @@ class LeftLabelRightContainer: View { addSubview(rightContainer) addSubview(leftContainer) leftContainer.addSubview(label) - NSLayoutConstraint.constraintPinSubview(toSuperview: label) + //NSLayoutConstraint.constraintPinSubview(toSuperview: label) + NSLayoutConstraint.constraintPinSubview(label, pinTop: true, pinBottom: false, pinLeft: true, pinRight: false) + leftContainer.leftAnchor.constraint(greaterThanOrEqualTo: label.rightAnchor).isActive = true NSLayoutConstraint.constraintPinSubview(leftContainer, pinTop: true, pinBottom: false, pinLeft: true, pinRight: false) bottomAnchor.constraint(greaterThanOrEqualTo: leftContainer.bottomAnchor).isActive = true @@ -184,10 +227,10 @@ class LeftLabelRightContainer: View { constraintBtwViews?.isActive = true //TODO: Need to get confirmation on this - leftContainer.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 0.05, constant: 0).isActive = true + //leftContainer.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 0.05, constant: 0).isActive = true setContentHuggingPriority(.defaultHigh, for: .vertical) setContentHuggingPriority(.defaultHigh, for: .horizontal) - rightContainer.setContentHuggingPriority(.defaultHigh, for: .vertical) + rightContainer.setContentCompressionResistancePriority(.defaultHigh, for: .vertical) rightContainer.setContentHuggingPriority(.defaultHigh, for: .horizontal) label.setContentHuggingPriority(.defaultHigh, for: .horizontal) @@ -197,23 +240,31 @@ class LeftLabelRightContainer: View { override func updateView(_ size: CGFloat) { super.updateView(size) + rightMolecule?.updateView(size) + label.updateView(size) + } + + override func reset() { + super.reset() + rightMolecule?.reset() } override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) let previousMoleculeName = rightMoleculeName - guard let moleculeJSON = json?.optionalDictionaryForKey("right") else { - removeSubviewsInRightContainer() + removeSubviewsInRightContainer() + guard let moleculeJSON = json, let _ = moleculeJSON.optionalStringForKey(KeyMoleculeName) else { + super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) return } - Label.setUILabel(label, withJSON: json?.optionalDictionaryForKey("left"), delegate: delegateObject, additionalData: additionalData) + label.text = leftText rightMoleculeName = moleculeJSON.optionalStringForKey(KeyMoleculeName) //For reuse purpose check that allready added molecule is same - if rightMolecule != nil && previousMoleculeName == rightMoleculeName { - rightMolecule?.setWithJSON(json?.optionalDictionaryForKey("right"), delegateObject: delegateObject, additionalData: additionalData) + if let rightMolecule = self.rightMolecule, previousMoleculeName == rightMoleculeName { + rightMolecule.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: additionalData) + addView(rightMolecule) } else { - removeSubviewsInRightContainer() if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: false) { addView(molecule) } From 709277362f6a5a7bc6076d2b6a49a8674a95484e Mon Sep 17 00:00:00 2001 From: "Murugan, Vimal" Date: Fri, 3 Jan 2020 20:20:23 +0530 Subject: [PATCH 5/6] updated constraints --- MVMCoreUI/Molecules/BulletList.swift | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Molecules/BulletList.swift b/MVMCoreUI/Molecules/BulletList.swift index 5cb0dbd4..e5eab994 100644 --- a/MVMCoreUI/Molecules/BulletList.swift +++ b/MVMCoreUI/Molecules/BulletList.swift @@ -92,12 +92,12 @@ open class BulletList: Container { // Adds the molecules and sets the json. for (index, map) in list.enumerated() { if let item = items?[index] { - item.leftText = bulletChar + item.leftText = bulletChar ?? String(index+1) item.setWithJSON(map, delegateObject: delegateObject, additionalData: nil) addView(item, lastItem: index == list.count - 1) } else { let leftLabel = LeftLabelRightMoleculeContainer() - leftLabel.leftText = bulletChar + leftLabel.leftText = bulletChar ?? String(index+1) leftLabel.setWithJSON(map, delegateObject: delegateObject, additionalData: additionalData) addView(leftLabel, lastItem: index == list.count - 1) } @@ -214,9 +214,16 @@ class LeftLabelRightMoleculeContainer: View { addSubview(rightContainer) addSubview(leftContainer) leftContainer.addSubview(label) - //NSLayoutConstraint.constraintPinSubview(toSuperview: label) + NSLayoutConstraint.constraintPinSubview(label, pinTop: true, pinBottom: false, pinLeft: true, pinRight: false) - leftContainer.leftAnchor.constraint(greaterThanOrEqualTo: label.rightAnchor).isActive = true + label.rightAnchor.constraint(greaterThanOrEqualTo: leftContainer.leftAnchor).isActive = true + let labelRightAnchor = label.rightAnchor.constraint(equalTo: leftContainer.leftAnchor) + labelRightAnchor.priority = UILayoutPriority(rawValue: 200) + labelRightAnchor.isActive = true + leftContainer.bottomAnchor.constraint(greaterThanOrEqualTo: label.bottomAnchor).isActive = true + let labelBotAnchor = leftContainer.bottomAnchor.constraint(equalTo: label.bottomAnchor) + labelBotAnchor.priority = UILayoutPriority(rawValue: 200) + labelBotAnchor.isActive = true NSLayoutConstraint.constraintPinSubview(leftContainer, pinTop: true, pinBottom: false, pinLeft: true, pinRight: false) bottomAnchor.constraint(greaterThanOrEqualTo: leftContainer.bottomAnchor).isActive = true From f1f34b289307a4318f326010fd09cd8ab6ff65b5 Mon Sep 17 00:00:00 2001 From: "Murugan, Vimal" Date: Sat, 4 Jan 2020 14:26:09 +0530 Subject: [PATCH 6/6] textfield list view and textfield list form controller been moved to mobilefirstframework --- MVMCoreUI.xcodeproj/project.pbxproj | 12 - MVMCoreUI/Molecules/BulletList.swift | 291 ------------------ MVMCoreUI/Molecules/MFTextFieldListView.swift | 143 --------- .../MVMCoreUIMoleculeMappingObject.m | 3 +- .../MVMCoreUIViewControllerMappingObject.m | 1 - .../TextFieldListFormViewController.swift | 65 ---- 6 files changed, 1 insertion(+), 514 deletions(-) delete mode 100644 MVMCoreUI/Molecules/BulletList.swift delete mode 100644 MVMCoreUI/Molecules/MFTextFieldListView.swift delete mode 100644 MVMCoreUI/Templates/TextFieldListFormViewController.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 14506f07..b33ce6e9 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -20,8 +20,6 @@ 0198F79F225679880066C936 /* FormValidationProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0198F79E225679870066C936 /* FormValidationProtocol.swift */; }; 0198F7A62256A80B0066C936 /* MFRadioButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 0198F7A02256A80A0066C936 /* MFRadioButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; 0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 0198F7A22256A80A0066C936 /* MFRadioButton.m */; }; - 01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */; }; - 01DF567021FA5AB300CC099B /* TextFieldListFormViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */; }; 01E569D3223FFFA500327251 /* ThreeLayerViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = D2A5146A2214905000345BFB /* ThreeLayerViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 0A1214A022C11A18007C7030 /* ActionDetailWithImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */; }; 0A1B4A96233BB18F005B3FB4 /* CheckboxWithLabelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */; }; @@ -32,7 +30,6 @@ 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 */; }; - C63D632123BDC3A0008F3B1F /* BulletList.swift in Sources */ = {isa = PBXBuildFile; fileRef = C63D632023BDC3A0008F3B1F /* BulletList.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 */; }; @@ -223,8 +220,6 @@ 0198F79E225679870066C936 /* FormValidationProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidationProtocol.swift; sourceTree = ""; }; 0198F7A02256A80A0066C936 /* MFRadioButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFRadioButton.h; sourceTree = ""; }; 0198F7A22256A80A0066C936 /* MFRadioButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFRadioButton.m; sourceTree = ""; }; - 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MFTextFieldListView.swift; sourceTree = ""; }; - 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldListFormViewController.swift; sourceTree = ""; }; 0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionDetailWithImage.swift; sourceTree = ""; }; 0A41BA6D2344FCD400D4C0BC /* CATransaction+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CATransaction+Extension.swift"; sourceTree = ""; }; 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyButton.swift; sourceTree = ""; }; @@ -234,7 +229,6 @@ 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 = ""; }; - C63D632023BDC3A0008F3B1F /* BulletList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BulletList.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 = ""; }; @@ -586,7 +580,6 @@ D29DF0DF21E418B2003B2FB9 /* Templates */ = { isa = PBXGroup; children = ( - 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */, D2A5146022121FBF00345BFB /* MoleculeStackTemplate.swift */, D2A514622213643100345BFB /* MoleculeStackCenteredTemplate.swift */, D296E13B2295969C0051EBE7 /* MoleculeListCellProtocol.h */, @@ -624,7 +617,6 @@ D224798D2316A988003FCCF9 /* VerticalCombinationViews */, D2A5145C2211D22A00345BFB /* MVMCoreUIMoleculeViewProtocol.h */, 0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */, - 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */, D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */, D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */, D2A514662213885800345BFB /* StandardHeaderView.swift */, @@ -635,7 +627,6 @@ 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */, 017BEB372360C6AC0024EF95 /* RadioButtonLabel.swift */, D2FB151A23A2B65B00C20E10 /* MoleculeContainer.swift */, - C63D632023BDC3A0008F3B1F /* BulletList.swift */, ); path = Molecules; sourceTree = ""; @@ -1105,7 +1096,6 @@ D29DF12E21E6851E003B2FB9 /* MVMCoreUITopAlertView.m in Sources */, D29DF2CF21E7C104003B2FB9 /* MFLoadingViewController.m in Sources */, D22D1F572204CE5D0077CEC0 /* MVMCoreUIStackableViewController.m in Sources */, - 01DF567021FA5AB300CC099B /* TextFieldListFormViewController.swift in Sources */, D2A5145F2211DDC100345BFB /* MoleculeStackView.swift in Sources */, D29DF27621E79E81003B2FB9 /* MVMCoreUILoggingHandler.m in Sources */, D29DF24D21E6A177003B2FB9 /* MFTextField.m in Sources */, @@ -1141,7 +1131,6 @@ D29DF2BF21E7BEA4003B2FB9 /* MVMCoreUITabBarPageControlViewController.m in Sources */, D29DF28321E7AB24003B2FB9 /* MVMCoreUICommonViewsUtility.m in Sources */, D29DF27A21E7A533003B2FB9 /* MVMCoreUISession.m in Sources */, - 01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */, D2A5146B2214905000345BFB /* ThreeLayerViewController.swift in Sources */, D29DF2C921E7BFC6003B2FB9 /* MFSizeObject.m in Sources */, D2A6390522CBCE160052ED1F /* MoleculeCollectionViewCell.swift in Sources */, @@ -1180,7 +1169,6 @@ 0A41BA6E2344FCD400D4C0BC /* CATransaction+Extension.swift in Sources */, D29DF13221E6851E003B2FB9 /* MVMCoreUITopAlertBaseView.m in Sources */, D29DF29C21E7ADB9003B2FB9 /* MFProgrammaticTableViewController.m in Sources */, - C63D632123BDC3A0008F3B1F /* BulletList.swift in Sources */, 0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */, 0A1214A022C11A18007C7030 /* ActionDetailWithImage.swift in Sources */, D2B18B922361E65A00A9AEDC /* CoreUIObject.swift in Sources */, diff --git a/MVMCoreUI/Molecules/BulletList.swift b/MVMCoreUI/Molecules/BulletList.swift deleted file mode 100644 index e5eab994..00000000 --- a/MVMCoreUI/Molecules/BulletList.swift +++ /dev/null @@ -1,291 +0,0 @@ -// -// BulletList.swift -// MVMCoreUI -// -// Created by Murugan, Vimal on 02/01/20. -// Copyright © 2020 Verizon Wireless. All rights reserved. -// - -import UIKit - -open class BulletList: Container { - - var contentView = MVMCoreUICommonViewsUtility.commonView() - var reusableViews: [LeftLabelRightMoleculeContainer] = [] - var bulletChar: String? - - /// Removes all stack items views from the view. - func removeAllItemInViews() { - reusableViews.forEach({ $0.removeFromSuperview() }) - } - - // MARK: - Inits - public override init() { - super.init() - } - - public override init(frame: CGRect) { - super.init(frame: frame) - } - - public init(withJSON json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { - super.init(frame: CGRect.zero) - setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - } - - public required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - // MARK: - Helpers - public func pinView(_ view: UIView, toView: UIView, attribute: NSLayoutConstraint.Attribute, relation: NSLayoutConstraint.Relation, priority: UILayoutPriority, constant: CGFloat) { - let constraint = NSLayoutConstraint(item: view, attribute: attribute, relatedBy: relation, toItem: toView, attribute: attribute, multiplier: 1.0, constant: constant) - constraint.priority = priority - constraint.isActive = true - } - - // MARK: - MFViewProtocol - public override func setupView() { - super.setupView() - guard contentView.superview == nil else { - return - } - MVMCoreUIUtility.setMarginsFor(contentView, leading: 0, top: 0, trailing: 0, bottom: 0) - translatesAutoresizingMaskIntoConstraints = false - backgroundColor = .clear - addSubview(contentView) - containerHelper.constrainView(contentView) - contentView.setContentHuggingPriority(.defaultHigh, for: .vertical) - contentView.setContentHuggingPriority(.defaultHigh, for: .horizontal) - } - - public override func updateView(_ size: CGFloat) { - super.updateView(size) - directionalLayoutMargins.leading = 0 - directionalLayoutMargins.trailing = 0 - reusableViews.forEach({ $0.updateView(size) }) - } - - // MARK: - MVMCoreUIMoleculeViewProtocol - public override func reset() { - super.reset() - backgroundColor = .clear - reusableViews.forEach({ $0.reset() }) - } - - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - let previousJSON = self.json - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - removeAllItemInViews() - // If the items in the stack are the same, just update previous items instead of re-allocating. - var items: [LeftLabelRightMoleculeContainer]? - if BulletList.name(forReuse: previousJSON, delegateObject: delegateObject) == BulletList.name(forReuse: json, delegateObject: delegateObject) { - items = self.reusableViews - } - self.reusableViews = [] - - guard let list = json?.arrayForKey("list") as? [[String: Any]] else { - return - } - - bulletChar = json?.optionalStringForKey("bulletChar") - // Adds the molecules and sets the json. - for (index, map) in list.enumerated() { - if let item = items?[index] { - item.leftText = bulletChar ?? String(index+1) - item.setWithJSON(map, delegateObject: delegateObject, additionalData: nil) - addView(item, lastItem: index == list.count - 1) - } else { - let leftLabel = LeftLabelRightMoleculeContainer() - leftLabel.leftText = bulletChar ?? String(index+1) - leftLabel.setWithJSON(map, delegateObject: delegateObject, additionalData: additionalData) - addView(leftLabel, lastItem: index == list.count - 1) - } - } - } - - func addView(_ container: LeftLabelRightMoleculeContainer, lastItem: Bool) { - container.translatesAutoresizingMaskIntoConstraints = false - contentView.addSubview(container) - let first = reusableViews.first == nil - if first { - pinView(container, toView: contentView, attribute: .top, relation: .equal, priority: .required, constant: 16) - } else if let previousView = reusableViews.last { - container.topAnchor.constraint(equalTo: previousView.bottomAnchor, constant: 16).isActive = true - } - pinView(container, toView: contentView, attribute: .leading, relation: .equal, priority: .required, constant: 0) - pinView(contentView, toView: container, attribute: .trailing, relation: .equal, priority: .required, constant: 0) - if lastItem { - pinView(contentView, toView: container, attribute: .bottom, relation: .equal, priority: .required, constant: 0) - } - reusableViews.append(container) - } - - public class func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { - // This will aggregate names of molecules to make an id. - guard let molecules = molecule?.optionalArrayForKey("list") else { - return "unordered<>" - } - var name = "unordered<" - for case let item as [AnyHashable: Any] in molecules { - if let moleculeName = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: item)?.name?(forReuse: molecule, delegateObject: delegateObject) ?? item.optionalStringForKey(KeyMoleculeName) { - name.append(moleculeName + ",") - } - } - name.append(">") - return name - } - - public class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { - guard let items = json?.optionalArrayForKey("list") else { - return 0 - } - var estimatedHeight: CGFloat = 0 - for case let item as [AnyHashable: AnyHashable] in items { - if let _ = item.optionalStringForKey(KeyMoleculeName) { - let height = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: item)?.estimatedHeight?(forRow: item, delegateObject: delegateObject) - estimatedHeight += ((height ?? 0) + 16) - } - } - return estimatedHeight - } - - public class func requiredModules(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { - guard let items = json?.optionalArrayForKey("list") else { - return nil - } - var modules: [String] = [] - for case let item as [AnyHashable: AnyHashable] in items { - if let modulesForMolecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: item)?.requiredModules?(item, delegateObject: delegateObject, error: error) { - modules += modulesForMolecule - } - } - return modules.count > 0 ? modules : nil - } - -} - -class LeftLabelRightMoleculeContainer: View { - - var label = Label.commonLabelB2(true) - var rightContainer = MVMCoreUICommonViewsUtility.commonView() - var leftContainer = MVMCoreUICommonViewsUtility.commonView() - var rightMoleculeName: String? - var rightMolecule: View? - let containerHelper = ContainerHelper() - var leftText: String? - - var constraintBtwViews: NSLayoutConstraint? - var spaceBtwViews: CGFloat = 8 { - didSet { - if spaceBtwViews != oldValue { - constraintBtwViews?.constant = spaceBtwViews - layoutIfNeeded() - } - } - } - - // MARK: - Inits - public override init() { - super.init() - } - - public override init(frame: CGRect) { - super.init(frame: frame) - } - - public init(withJSON json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { - super.init(frame: CGRect.zero) - setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - } - - public required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override func setupView() { - super.setupView() - - guard rightContainer.superview == nil else { - return - } - - translatesAutoresizingMaskIntoConstraints = false - addSubview(rightContainer) - addSubview(leftContainer) - leftContainer.addSubview(label) - - NSLayoutConstraint.constraintPinSubview(label, pinTop: true, pinBottom: false, pinLeft: true, pinRight: false) - label.rightAnchor.constraint(greaterThanOrEqualTo: leftContainer.leftAnchor).isActive = true - let labelRightAnchor = label.rightAnchor.constraint(equalTo: leftContainer.leftAnchor) - labelRightAnchor.priority = UILayoutPriority(rawValue: 200) - labelRightAnchor.isActive = true - leftContainer.bottomAnchor.constraint(greaterThanOrEqualTo: label.bottomAnchor).isActive = true - let labelBotAnchor = leftContainer.bottomAnchor.constraint(equalTo: label.bottomAnchor) - labelBotAnchor.priority = UILayoutPriority(rawValue: 200) - labelBotAnchor.isActive = true - - NSLayoutConstraint.constraintPinSubview(leftContainer, pinTop: true, pinBottom: false, pinLeft: true, pinRight: false) - bottomAnchor.constraint(greaterThanOrEqualTo: leftContainer.bottomAnchor).isActive = true - - NSLayoutConstraint.constraintPinSubview(rightContainer, pinTop: true, pinBottom: true, pinLeft: false, pinRight: true) - constraintBtwViews = rightContainer.leftAnchor.constraint(equalTo: leftContainer.rightAnchor, constant: spaceBtwViews) - constraintBtwViews?.priority = .required - constraintBtwViews?.isActive = true - - //TODO: Need to get confirmation on this - //leftContainer.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 0.05, constant: 0).isActive = true - setContentHuggingPriority(.defaultHigh, for: .vertical) - setContentHuggingPriority(.defaultHigh, for: .horizontal) - rightContainer.setContentCompressionResistancePriority(.defaultHigh, for: .vertical) - rightContainer.setContentHuggingPriority(.defaultHigh, for: .horizontal) - - label.setContentHuggingPriority(.defaultHigh, for: .horizontal) - label.setContentHuggingPriority(.defaultHigh, for: .vertical) - - } - - override func updateView(_ size: CGFloat) { - super.updateView(size) - rightMolecule?.updateView(size) - label.updateView(size) - } - - override func reset() { - super.reset() - rightMolecule?.reset() - } - - override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - let previousMoleculeName = rightMoleculeName - removeSubviewsInRightContainer() - guard let moleculeJSON = json, let _ = moleculeJSON.optionalStringForKey(KeyMoleculeName) else { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - return - } - - label.text = leftText - rightMoleculeName = moleculeJSON.optionalStringForKey(KeyMoleculeName) - //For reuse purpose check that allready added molecule is same - if let rightMolecule = self.rightMolecule, previousMoleculeName == rightMoleculeName { - rightMolecule.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: additionalData) - addView(rightMolecule) - } else { - if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: false) { - addView(molecule) - } - } - } - - func removeSubviewsInRightContainer() { - rightContainer.subviews.forEach({ $0.removeFromSuperview() }) - } - - func addView(_ view: UIView) { - view.translatesAutoresizingMaskIntoConstraints = false - rightContainer.addSubview(view) - containerHelper.constrainView(view) - rightMolecule = view as? View - } -} diff --git a/MVMCoreUI/Molecules/MFTextFieldListView.swift b/MVMCoreUI/Molecules/MFTextFieldListView.swift deleted file mode 100644 index c695c3a3..00000000 --- a/MVMCoreUI/Molecules/MFTextFieldListView.swift +++ /dev/null @@ -1,143 +0,0 @@ -// -// MFTextFieldListView.swift -// MobileFirstFramework -// -// Created by Suresh, Kamlesh on 9/21/18. -// Copyright © 2018 Verizon Wireless. All rights reserved. -// - -import UIKit -import MVMCore - -@objc public protocol TextFieldListHelperProtocol { - @objc optional func fieldForMap(_ map: [String: Any], textField: MFTextField) - @objc optional func spaceBetweenField() -> CGFloat -} - -public class MFTextFieldListView: ViewConstrainingView { - - public var textFieldMapList: [[String: Any]]? - public var parentViewContoller: MFViewController? - public var textFieldsToValidate: [MFTextField] = [] - public var textFields: [MFTextField] = [] - public var primaryButton: PrimaryButton? - - public init(textFieldMapList: [[String: Any]], parentViewContoller: MFViewController, primaryButton: PrimaryButton?) { - self.textFieldMapList = textFieldMapList - self.parentViewContoller = parentViewContoller - self.primaryButton = primaryButton - super.init(frame: .zero) - } - - public required init?(coder decoder: NSCoder) { - super.init(coder: decoder) - } - - public override func updateView(_ size: CGFloat) { - super.updateView(size) - for textField in textFields { - textField.updateView(size) - } - } - - public override func setupView() { - super.setupView() - self.translatesAutoresizingMaskIntoConstraints = false - - guard let textFieldMapList = textFieldMapList else { - return - } - var viewList: [UIView] = [] - - for textFieldMap in textFieldMapList { - if let textField = getTextFieldForMap(textFieldMap) { - - (parentViewContoller as? TextFieldListHelperProtocol)?.fieldForMap?(textFieldMap, textField: textField) - - if textFieldMap.boolForKey("required") { - textFieldsToValidate.append(textField) - } - - textFields.append(textField) - if let fieldKey = textField.fieldKey { - parentViewContoller?.register(textField, forErrorKey: fieldKey as String) - } - viewList.append(textField) - } - } - - let spaceBtwField = (parentViewContoller as? TextFieldListHelperProtocol)?.spaceBetweenField?() ?? 0.0 - StackableViewController.populateView(self, withUIArray: viewList) { (viewObject) -> UIEdgeInsets in - var edgeInsets = StackableViewController.standardSpaceAroundUIObject() - edgeInsets.left = 0 - edgeInsets.right = 0 - edgeInsets.top = 0 - edgeInsets.bottom = spaceBtwField - return edgeInsets - } - - primaryButton?.handleEnabling(with: textFieldsToValidate) - } - - public func addParams(requestParameters: MVMCoreRequestParameters) { - requestParameters.add(getTextParamsList()) - } - - public func getTextParamsList() -> [String: Any] { - return DispatchQueue.main.sync { - var extraParam: [String: Any] = [:] - for textField in textFields { - if let fieldKey = textField.fieldKey { - extraParam[fieldKey as String] = textField.text ?? "" - } - } - return extraParam - } - } - - private func getTextFieldForMap(_ map: [String: Any]) -> MFTextField? { - if map.boolForKey("dropDown") { - let dropDownFld = DropDown(map: map, bothDelegates: self) - dropDownFld?.setWithJSON(map, delegateObject: parentViewContoller?.delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil) - dropDownFld?.showDropDown(true) - return dropDownFld - } - return MFTextField(map: map, bothDelegates: self) - } -} - -extension MFTextFieldListView: UITextFieldDelegate, UITextViewDelegate, MFTextFieldDelegate { - @objc open func textFieldDidEndEditing(_ textField: UITextField) { - parentViewContoller?.textFieldDidEndEditing(textField) - primaryButton?.handleEnabling(with: textFieldsToValidate) - } - - @objc open func dismissFieldInput(_ sender: Any?) { - parentViewContoller?.dismissFieldInput(sender) - } - - @objc open func textFieldShouldReturn(_ textField: UITextField) -> Bool { - textField.resignFirstResponder() - return true - } - - @objc open func textFieldDidBeginEditing(_ textField: UITextField) { - parentViewContoller?.textFieldDidBeginEditing(textField) - } - - @objc open func entryIsValid(_ textfield: MFTextField?) { - DispatchQueue.main.async { - if self.parentViewContoller?.responds(to: #selector(MFTextFieldDelegate.entryIsValid(_:))) ?? false { - self.parentViewContoller?.entryIsValid(textfield) - } - } - } - - @objc open func entryIsInvalid(_ textfield: MFTextField?) { - DispatchQueue.main.async { - if self.parentViewContoller?.responds(to: #selector(MFTextFieldDelegate.entryIsInvalid(_:))) ?? false { - self.parentViewContoller?.entryIsInvalid(textfield) - } - } - } -} diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 47bbac98..9db7822d 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -66,8 +66,7 @@ @"tabsListItem": TabsTableViewCell.class, @"dropDownListItem": DropDownFilterTableViewCell.class, @"headlineBodyButton": HeadlineBodyButton.class, - @"eyebrowHeadlineBodyLink": EyebrowHeadlineBodyLink.class, - @"bulletList": BulletList.class + @"eyebrowHeadlineBodyLink": EyebrowHeadlineBodyLink.class } mutableCopy]; }); return mapping; diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIViewControllerMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIViewControllerMappingObject.m index e770ede5..2bc1a0dd 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIViewControllerMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIViewControllerMappingObject.m @@ -19,7 +19,6 @@ static NSMutableDictionary *viewControllerMapping; dispatch_once(&onceToken, ^{ viewControllerMapping = [@{ - @"textFieldListForm" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[TextFieldListFormViewController class]], @"moleculeStack" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[MoleculeStackTemplate class]], @"centerMoleculeStack" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[MoleculeStackCenteredTemplate class]], @"moleculeList" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[MoleculeListTemplate class]], diff --git a/MVMCoreUI/Templates/TextFieldListFormViewController.swift b/MVMCoreUI/Templates/TextFieldListFormViewController.swift deleted file mode 100644 index c0509679..00000000 --- a/MVMCoreUI/Templates/TextFieldListFormViewController.swift +++ /dev/null @@ -1,65 +0,0 @@ -// -// MVMCoreUITextFormViewController.swift -// MVMCoreUI -// -// Created by Suresh, Kamlesh on 1/24/19. -// Copyright © 2019 Verizon Wireless. All rights reserved. -// - -import UIKit - -open class TextFieldListFormViewController: TopLabelsAndBottomButtonsViewController, TextFieldListHelperProtocol { - - - public var textFieldListView: MFTextFieldListView? - - open override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view. - } - - open override func updateViews() { - super.updateViews() - } - - open override func newDataBuildScreen() { - super.newDataBuildScreen() - topLabelsView?.separatorView?.isHidden = true - } - - open override func buildViewsBetweenLabelsAndButtons() -> [UIView]? { - var viewList: [UIView] = [] - - if let textFieldsList = textFieldsLists() { - let textFieldListView = MFTextFieldListView(textFieldMapList: textFieldsList, - parentViewContoller: self, - primaryButton: self.primaryButton) - self.textFieldListView = textFieldListView - viewList.append(textFieldListView) - } - return viewList - } - - open override func handleOpenPage(for requestParameters: MVMCoreRequestParameters, actionInformation: [AnyHashable : Any]?, additionalData: [AnyHashable : Any]?) { - textFieldListView?.addParams(requestParameters: requestParameters) - super.handleOpenPage(for: requestParameters, actionInformation: actionInformation, additionalData: additionalData) - } - - open override func spaceAboveBetweenView() -> NSNumber? { - return PaddingFour as NSNumber - } - - open func textFieldsLists() -> [[String: Any]]? { - return loadObject?.pageJSON?.arrayForKey("textFieldList") as? [[String: Any]] - } - - //MARK: - Textfield list protocol - open func spaceBetweenField() -> CGFloat { - return 0.0 - } - - open func fieldForMap(_ map: [String : Any], textField: MFTextField) { - - } - -}