From 14b01d0ae0aeccf8054d1415e892a33fc6fce623 Mon Sep 17 00:00:00 2001 From: Priya Date: Tue, 7 May 2019 12:55:46 -0400 Subject: [PATCH 01/17] switch changes --- MVMCoreUI.xcodeproj/project.pbxproj | 6 +- MVMCoreUI/Molecules/Switch.swift | 78 +++++++++++++++++++ .../MVMCoreUIMoleculeMappingObject.m | 3 +- 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 MVMCoreUI/Molecules/Switch.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 83b51092..45a09419 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 0105618D224BBE7700E1557D /* FormValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618A224BBE7700E1557D /* FormValidator.swift */; }; 0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */; }; 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */; }; + 016A1071228122180009D605 /* Switch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016A1070228122180009D605 /* Switch.swift */; }; 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 */; }; @@ -170,6 +171,7 @@ 0105618A224BBE7700E1557D /* FormValidator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidator.swift; sourceTree = ""; }; 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+TextFields.swift"; sourceTree = ""; }; 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+FormParams.swift"; sourceTree = ""; }; + 016A1070228122180009D605 /* Switch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Switch.swift; sourceTree = ""; }; 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 = ""; }; @@ -319,10 +321,10 @@ D2C5001621F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIViewControllerMappingObject.h; sourceTree = ""; }; D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIViewControllerMappingObject.m; sourceTree = ""; }; D2E1FADA2260D3D200AEFD8C /* MVMCoreUIDelegateObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMCoreUIDelegateObject.swift; sourceTree = ""; }; - DB891E822253FA8500022516 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = ""; }; D2E1FADC2268B25E00AEFD8C /* MoleculeTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeTableViewCell.swift; sourceTree = ""; }; D2E1FADE2268B8E700AEFD8C /* ThreeLayerTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeLayerTableViewController.swift; sourceTree = ""; }; D2E1FAE02268E81D00AEFD8C /* MoleculeListTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeListTemplate.swift; sourceTree = ""; }; + DB891E822253FA8500022516 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = ""; }; DBC4391622442196001AB423 /* CaretView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaretView.swift; sourceTree = ""; }; DBC4391722442197001AB423 /* DashLine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DashLine.swift; sourceTree = ""; }; DBC4391A224421A0001AB423 /* CaretButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaretButton.swift; sourceTree = ""; }; @@ -442,6 +444,7 @@ D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */, D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */, D282AACA2243C61700C46919 /* ButtonView.swift */, + 016A1070228122180009D605 /* Switch.swift */, D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */, D2A514662213885800345BFB /* StandardHeaderView.swift */, D2A5145C2211D22A00345BFB /* MVMCoreUIMoleculeViewProtocol.h */, @@ -917,6 +920,7 @@ D2A5146B2214905000345BFB /* ThreeLayerViewController.swift in Sources */, D29DF2C921E7BFC6003B2FB9 /* MFSizeObject.m in Sources */, D29DF2C721E7BF57003B2FB9 /* MFTabBarInteractor.m in Sources */, + 016A1071228122180009D605 /* Switch.swift in Sources */, D29DF29521E7ADB8003B2FB9 /* ProgrammaticScrollViewController.m in Sources */, D29DF16121E69996003B2FB9 /* MFViewController.m in Sources */, D2E1FAE12268E81D00AEFD8C /* MoleculeListTemplate.swift in Sources */, diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift new file mode 100644 index 00000000..dec7f46b --- /dev/null +++ b/MVMCoreUI/Molecules/Switch.swift @@ -0,0 +1,78 @@ +// +// Switch.swift +// MVMCoreUI +// +// Created by Priya on 5/6/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +public class Switch: ViewConstrainingView { + var isRequired: Bool? = false + var state: Bool? = false + var onTintColor: UIColor? = .clear + var offTintColor: UIColor? = .clear + var isOnState: Bool? = false + var fieldKey: String? = "" + // MARK: - Inits + public init() { + super.init(frame: .zero) + } + + public override init(frame: CGRect) { + super.init(frame: frame) + } + + required public init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + + // MARK: - MVMCoreUIMoleculeViewProtocol + open override func setAsMolecule() { + super.setAsMolecule() + } + + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + self.isRequired = json?[KeyRequired] as? Bool + self.state = json?["state"] as? Bool + if let onColorString = json?.optionalStringForKey("onTintColor") { + self.onTintColor = .mfGet(forHex: onColorString) + } + if let offColorString = json?.optionalStringForKey("offTintColor") { + self.offTintColor = .mfGet(forHex: offColorString) + } + self.fieldKey = json?[KeyFieldKey] as? String + + } + + func setupConstraints(forView view: UIView) { + leftPin = view.leftAnchor.constraint(equalTo: leftAnchor) + topPin = view.topAnchor.constraint(equalTo: topAnchor) + rightPin = rightAnchor.constraint(equalTo: view.rightAnchor) + bottomPin = bottomAnchor.constraint(equalTo: view.bottomAnchor) + leftPin?.isActive = true + topPin?.isActive = true + rightPin?.isActive = true + bottomPin?.isActive = true + } + + // MARK: - FormValidationProtocol + + func isValidField() -> Bool { + if self.isRequired ?? false { + return self.isOnState ?? false + } + return true + } + + func formFieldName() -> String { + return self.fieldKey ?? "" + } + + func formFieldValue() -> Bool { + return self.isOnState ?? false + } + +} diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index e1101191..391dd561 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -33,7 +33,8 @@ @"caretView": CaretView.class, @"caretButton": CaretButton.class, @"textField" : MFTextField.class, - @"checkbox" : MVMCoreUICheckBox.class + @"checkbox" : MVMCoreUICheckBox.class, + @"switch" : Switch.class } mutableCopy]; }); return mapping; From af81b62f9353631abcd1cf335a8ed29ed14ad555 Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 9 May 2019 10:58:05 -0400 Subject: [PATCH 02/17] switch --- MVMCoreUI/Molecules/Switch.swift | 111 ++++++++++++++++++++++++++----- 1 file changed, 93 insertions(+), 18 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index dec7f46b..f3fc775c 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -8,13 +8,16 @@ import UIKit -public class Switch: ViewConstrainingView { +public class Switch: ViewConstrainingView, FormValidationProtocol { + var aSwitch = UISwitch() + var label = Label() var isRequired: Bool? = false var state: Bool? = false var onTintColor: UIColor? = .clear var offTintColor: UIColor? = .clear var isOnState: Bool? = false var fieldKey: String? = "" + // MARK: - Inits public init() { super.init(frame: .zero) @@ -33,10 +36,47 @@ public class Switch: ViewConstrainingView { super.setAsMolecule() } + @objc func switchChanged(mySwitch: UISwitch) { + let value = mySwitch.isOn + let str = value ? "Switch is On" : "Switch is Off" + print("\(str)") + // Do something + } + + + open override func setupView() { + super.setupView() + aSwitch.onTintColor = self.onTintColor + aSwitch.addTarget(self, action: #selector(switchChanged), for: UIControl.Event.valueChanged) + self.addSubview(aSwitch) + self.addSubview(label) + label.translatesAutoresizingMaskIntoConstraints = false + aSwitch.translatesAutoresizingMaskIntoConstraints = false + } + + + public override func updateView(_ size: CGFloat) { + super.updateView(size) + self.setupConstraints(forView: self) + } + + + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) self.isRequired = json?[KeyRequired] as? Bool self.state = json?["state"] as? Bool + if let dict = json?.optionalDictionaryForKey("label") { + label.text = dict["text"] as? String + if let textColor = json?.optionalStringForKey("textColor") { + label.textColor = .mfGet(forHex: textColor) + } + } + + if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { + FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) + } + if let onColorString = json?.optionalStringForKey("onTintColor") { self.onTintColor = .mfGet(forHex: onColorString) } @@ -44,35 +84,70 @@ public class Switch: ViewConstrainingView { self.offTintColor = .mfGet(forHex: offColorString) } self.fieldKey = json?[KeyFieldKey] as? String - + aSwitch.onTintColor = self.onTintColor } func setupConstraints(forView view: UIView) { - leftPin = view.leftAnchor.constraint(equalTo: leftAnchor) - topPin = view.topAnchor.constraint(equalTo: topAnchor) - rightPin = rightAnchor.constraint(equalTo: view.rightAnchor) - bottomPin = bottomAnchor.constraint(equalTo: view.bottomAnchor) - leftPin?.isActive = true - topPin?.isActive = true - rightPin?.isActive = true - bottomPin?.isActive = true + label.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 0).isActive = true + label.trailingAnchor.constraint(equalTo: aSwitch.leadingAnchor, constant: 20).isActive = true + label.topAnchor.constraint(equalTo: view.topAnchor).isActive = true + label.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true + + aSwitch.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: PaddingOne).isActive = true + //aSwitch.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -50).isActive = true + + + view.trailingAnchor.constraint(equalTo: aSwitch.trailingAnchor, constant: 0).isActive = true + + + aSwitch.topAnchor.constraint(equalTo: view.topAnchor).isActive = true + aSwitch.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true + // aSwitch.widthAnchor.constraint(equalToConstant: 60.0).isActive = true + } + // MARK: - FormValidationProtocol - func isValidField() -> Bool { - if self.isRequired ?? false { - return self.isOnState ?? false - } - return true + +// { +// "moleculeName":"switch", +// "fieldName": "switchOption", +// "fieldKey": "switchImei1", +// "onTintColor": "#ffff00", +// "offTintColor": "#ffffff", +// "state": true, +// "label": { +// "moleculeName": "label", +// "text": "This is a switch", +// "textColor": "#000000", +// "backgroundColor": "#FFFFFF" +// }, +// "required": false, +// +// } + public func isValidField() -> Bool { +// if self.isRequired ?? false { +// return aSwitch.isOn +// } + return aSwitch.isOn } - func formFieldName() -> String { + public func formFieldName() -> String? { return self.fieldKey ?? "" } - func formFieldValue() -> Bool { - return self.isOnState ?? false + public func formFieldValue() -> Any? { + return aSwitch.isOn + } + + public override func needsToBeConstrained() -> Bool { + return true + } + + public override func moleculeAlignment() -> UIStackView.Alignment { + return UIStackView.Alignment.leading } } + From b77ec675e012dbd5d87851d1b751f32b698814ab Mon Sep 17 00:00:00 2001 From: Priya Date: Tue, 14 May 2019 14:34:54 -0400 Subject: [PATCH 03/17] Switch molecule --- MVMCoreUI/Molecules/Switch.swift | 109 ++++++++++++------------------- 1 file changed, 43 insertions(+), 66 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index f3fc775c..162ddebc 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -11,14 +11,15 @@ import UIKit public class Switch: ViewConstrainingView, FormValidationProtocol { var aSwitch = UISwitch() var label = Label() + var mfTextButton = MFTextButton() var isRequired: Bool? = false var state: Bool? = false var onTintColor: UIColor? = .clear var offTintColor: UIColor? = .clear var isOnState: Bool? = false var fieldKey: String? = "" + var delegate: DelegateObject? - // MARK: - Inits public init() { super.init(frame: .zero) } @@ -30,47 +31,50 @@ public class Switch: ViewConstrainingView, FormValidationProtocol { required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } - - // MARK: - MVMCoreUIMoleculeViewProtocol open override func setAsMolecule() { super.setAsMolecule() } - + @objc func switchChanged(mySwitch: UISwitch) { - let value = mySwitch.isOn - let str = value ? "Switch is On" : "Switch is Off" - print("\(str)") - // Do something + let formValidator = (self.delegate as? MVMCoreUIDelegateObject)?.formValidationProtocol?.formValidatorModel?() + formValidator?.enableByValidation() } - - + open override func setupView() { super.setupView() - aSwitch.onTintColor = self.onTintColor - aSwitch.addTarget(self, action: #selector(switchChanged), for: UIControl.Event.valueChanged) - self.addSubview(aSwitch) - self.addSubview(label) + aSwitch.onTintColor = onTintColor + + aSwitch.addTarget(self, action: #selector(Switch.switchChanged(mySwitch:)), for: .valueChanged) + mfTextButton = MFTextButton(nil, constrainHeight: true, forWidth: CGFloat.leastNormalMagnitude) + + addSubview(aSwitch) + addSubview(label) + addSubview(mfTextButton) + label.translatesAutoresizingMaskIntoConstraints = false aSwitch.translatesAutoresizingMaskIntoConstraints = false + mfTextButton.translatesAutoresizingMaskIntoConstraints = false; + setupConstraints(forView: self) } - public override func updateView(_ size: CGFloat) { super.updateView(size) - self.setupConstraints(forView: self) + label.updateView(size) + mfTextButton.updateView(size) } - - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - self.isRequired = json?[KeyRequired] as? Bool - self.state = json?["state"] as? Bool + isRequired = json?[KeyRequired] as? Bool + state = json?["state"] as? Bool + + self.delegate = delegateObject if let dict = json?.optionalDictionaryForKey("label") { - label.text = dict["text"] as? String - if let textColor = json?.optionalStringForKey("textColor") { - label.textColor = .mfGet(forHex: textColor) - } + label.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) + } + + if let dict = json?.optionalDictionaryForKey("textButton") { + mfTextButton.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) } if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { @@ -78,63 +82,36 @@ public class Switch: ViewConstrainingView, FormValidationProtocol { } if let onColorString = json?.optionalStringForKey("onTintColor") { - self.onTintColor = .mfGet(forHex: onColorString) + onTintColor = .mfGet(forHex: onColorString) } if let offColorString = json?.optionalStringForKey("offTintColor") { - self.offTintColor = .mfGet(forHex: offColorString) + offTintColor = .mfGet(forHex: offColorString) } - self.fieldKey = json?[KeyFieldKey] as? String - aSwitch.onTintColor = self.onTintColor + + aSwitch.onTintColor = onTintColor + aSwitch.isOn = state ?? false } func setupConstraints(forView view: UIView) { - label.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 0).isActive = true - label.trailingAnchor.constraint(equalTo: aSwitch.leadingAnchor, constant: 20).isActive = true - label.topAnchor.constraint(equalTo: view.topAnchor).isActive = true - label.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true + NSLayoutConstraint.constraintPinRightSubview(aSwitch, rightConstant: 0) + NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0) - aSwitch.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: PaddingOne).isActive = true - //aSwitch.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -50).isActive = true - + NSLayoutConstraint.constraintPinSubview(aSwitch, pinTop: true, topConstant: 0, topRelation: .equal, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: false, rightConstant: 0, rightRelation: .equal) - view.trailingAnchor.constraint(equalTo: aSwitch.trailingAnchor, constant: 0).isActive = true - - - aSwitch.topAnchor.constraint(equalTo: view.topAnchor).isActive = true - aSwitch.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true - // aSwitch.widthAnchor.constraint(equalToConstant: 60.0).isActive = true + NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0) + NSLayoutConstraint(pinFirstView: label, toSecondView: aSwitch, withConstant: PaddingOne, directionVertical: false)?.isActive = true + NSLayoutConstraint(pinFirstView: label, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true)?.isActive = true + NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0) + NSLayoutConstraint.constraintPinBottomSubview(mfTextButton, bottomConstant: 0) } - - // MARK: - FormValidationProtocol - - -// { -// "moleculeName":"switch", -// "fieldName": "switchOption", -// "fieldKey": "switchImei1", -// "onTintColor": "#ffff00", -// "offTintColor": "#ffffff", -// "state": true, -// "label": { -// "moleculeName": "label", -// "text": "This is a switch", -// "textColor": "#000000", -// "backgroundColor": "#FFFFFF" -// }, -// "required": false, -// -// } public func isValidField() -> Bool { -// if self.isRequired ?? false { -// return aSwitch.isOn -// } - return aSwitch.isOn + return (isRequired == false) ? true : aSwitch.isOn } public func formFieldName() -> String? { - return self.fieldKey ?? "" + return json?.optionalStringForKey(KeyFieldKey) } public func formFieldValue() -> Any? { From 8ef420e3a4500c65c90c0eb3573f587c6c4ab60a Mon Sep 17 00:00:00 2001 From: Priya Date: Wed, 15 May 2019 12:01:30 -0400 Subject: [PATCH 04/17] switch modification --- MVMCoreUI/Molecules/Switch.swift | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index 162ddebc..50f9aae0 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -13,11 +13,8 @@ public class Switch: ViewConstrainingView, FormValidationProtocol { var label = Label() var mfTextButton = MFTextButton() var isRequired: Bool? = false - var state: Bool? = false var onTintColor: UIColor? = .clear var offTintColor: UIColor? = .clear - var isOnState: Bool? = false - var fieldKey: String? = "" var delegate: DelegateObject? public init() { @@ -66,8 +63,6 @@ public class Switch: ViewConstrainingView, FormValidationProtocol { open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) isRequired = json?[KeyRequired] as? Bool - state = json?["state"] as? Bool - self.delegate = delegateObject if let dict = json?.optionalDictionaryForKey("label") { label.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) @@ -87,21 +82,17 @@ public class Switch: ViewConstrainingView, FormValidationProtocol { if let offColorString = json?.optionalStringForKey("offTintColor") { offTintColor = .mfGet(forHex: offColorString) } - aSwitch.onTintColor = onTintColor - aSwitch.isOn = state ?? false + aSwitch.isOn = json?.optionalBoolForKey("state") ?? false } func setupConstraints(forView view: UIView) { NSLayoutConstraint.constraintPinRightSubview(aSwitch, rightConstant: 0) NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0) - NSLayoutConstraint.constraintPinSubview(aSwitch, pinTop: true, topConstant: 0, topRelation: .equal, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: false, rightConstant: 0, rightRelation: .equal) - NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0) NSLayoutConstraint(pinFirstView: label, toSecondView: aSwitch, withConstant: PaddingOne, directionVertical: false)?.isActive = true NSLayoutConstraint(pinFirstView: label, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true)?.isActive = true - NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0) NSLayoutConstraint.constraintPinBottomSubview(mfTextButton, bottomConstant: 0) } From 97b7fbebad7e06198b442663ba7b18f7c04656e9 Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 16 May 2019 10:20:13 -0400 Subject: [PATCH 05/17] switch modification --- MVMCoreUI/Molecules/Switch.swift | 75 ++++++++++++-------------------- 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index 50f9aae0..b01ef73e 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -8,48 +8,31 @@ import UIKit -public class Switch: ViewConstrainingView, FormValidationProtocol { - var aSwitch = UISwitch() +@objcMembers public class Switch: ViewConstrainingView, FormValidationProtocol{ + public var mvmSwitch = UISwitch() var label = Label() var mfTextButton = MFTextButton() - var isRequired: Bool? = false - var onTintColor: UIColor? = .clear - var offTintColor: UIColor? = .clear - var delegate: DelegateObject? - - public init() { - super.init(frame: .zero) - } - - public override init(frame: CGRect) { - super.init(frame: frame) - } - - required public init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) - } - open override func setAsMolecule() { - super.setAsMolecule() - } + var isRequired: Bool! = false - @objc func switchChanged(mySwitch: UISwitch) { - let formValidator = (self.delegate as? MVMCoreUIDelegateObject)?.formValidationProtocol?.formValidatorModel?() - formValidator?.enableByValidation() + var delegateObject: DelegateObject? + + + @objc func switchChanged() { + let delegate = delegateObject as? MVMCoreUIDelegateObject + if let delegate = delegate { + let formValidator = delegate.formValidationProtocol?.formValidatorModel?() + formValidator?.enableByValidation() + } } open override func setupView() { super.setupView() - aSwitch.onTintColor = onTintColor - - aSwitch.addTarget(self, action: #selector(Switch.switchChanged(mySwitch:)), for: .valueChanged) - mfTextButton = MFTextButton(nil, constrainHeight: true, forWidth: CGFloat.leastNormalMagnitude) - - addSubview(aSwitch) + mvmSwitch.addTarget(self, action: #selector(Switch.switchChanged), for: .valueChanged) + addSubview(mvmSwitch) addSubview(label) addSubview(mfTextButton) - - label.translatesAutoresizingMaskIntoConstraints = false - aSwitch.translatesAutoresizingMaskIntoConstraints = false + // label.translatesAutoresizingMaskIntoConstraints = false + mvmSwitch.translatesAutoresizingMaskIntoConstraints = false mfTextButton.translatesAutoresizingMaskIntoConstraints = false; setupConstraints(forView: self) } @@ -63,7 +46,7 @@ public class Switch: ViewConstrainingView, FormValidationProtocol { open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) isRequired = json?[KeyRequired] as? Bool - self.delegate = delegateObject + self.delegateObject = delegateObject if let dict = json?.optionalDictionaryForKey("label") { label.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) } @@ -77,28 +60,28 @@ public class Switch: ViewConstrainingView, FormValidationProtocol { } if let onColorString = json?.optionalStringForKey("onTintColor") { - onTintColor = .mfGet(forHex: onColorString) + mvmSwitch.onTintColor = .mfGet(forHex: onColorString) } - if let offColorString = json?.optionalStringForKey("offTintColor") { - offTintColor = .mfGet(forHex: offColorString) - } - aSwitch.onTintColor = onTintColor - aSwitch.isOn = json?.optionalBoolForKey("state") ?? false + mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false } func setupConstraints(forView view: UIView) { - NSLayoutConstraint.constraintPinRightSubview(aSwitch, rightConstant: 0) NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0) - NSLayoutConstraint.constraintPinSubview(aSwitch, pinTop: true, topConstant: 0, topRelation: .equal, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: false, rightConstant: 0, rightRelation: .equal) + NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .equal, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .equal) NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0) - NSLayoutConstraint(pinFirstView: label, toSecondView: aSwitch, withConstant: PaddingOne, directionVertical: false)?.isActive = true - NSLayoutConstraint(pinFirstView: label, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true)?.isActive = true + _ = NSLayoutConstraint(pinFirstView: label, toSecondView: mvmSwitch, withConstant: PaddingOne, directionVertical: false) + _ = NSLayoutConstraint(pinFirstView: label, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0) NSLayoutConstraint.constraintPinBottomSubview(mfTextButton, bottomConstant: 0) + NSLayoutConstraint.constraintPinRightSubview(mfTextButton, rightConstant: 0) + if label.text?.isEmpty ?? false == false { + _ = NSLayoutConstraint(pinFirstView: mvmSwitch, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) + } + } public func isValidField() -> Bool { - return (isRequired == false) ? true : aSwitch.isOn + return (isRequired == false) ? true : mvmSwitch.isOn } public func formFieldName() -> String? { @@ -106,7 +89,7 @@ public class Switch: ViewConstrainingView, FormValidationProtocol { } public func formFieldValue() -> Any? { - return aSwitch.isOn + return mvmSwitch.isOn } public override func needsToBeConstrained() -> Bool { From 9ecc7f21a6f10a25a250f9f65beb4bb9e8cb09ae Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 16 May 2019 11:54:57 -0400 Subject: [PATCH 06/17] switch modification --- MVMCoreUI/Molecules/Switch.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index b01ef73e..4f87c8a3 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -13,11 +13,9 @@ import UIKit var label = Label() var mfTextButton = MFTextButton() var isRequired: Bool! = false - var delegateObject: DelegateObject? - - @objc func switchChanged() { +@objc func switchChanged() { let delegate = delegateObject as? MVMCoreUIDelegateObject if let delegate = delegate { let formValidator = delegate.formValidationProtocol?.formValidatorModel?() From 85e9c56dcf6a442863ff020a7b8bcbc4c8eec3c8 Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 16 May 2019 15:05:05 -0400 Subject: [PATCH 07/17] switch modification --- MVMCoreUI/Molecules/Switch.swift | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index 4f87c8a3..658a375c 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -9,7 +9,7 @@ import UIKit @objcMembers public class Switch: ViewConstrainingView, FormValidationProtocol{ - public var mvmSwitch = UISwitch() + public var mvmSwitch = MVMCoreUISwitch() var label = Label() var mfTextButton = MFTextButton() var isRequired: Bool! = false @@ -38,6 +38,7 @@ import UIKit public override func updateView(_ size: CGFloat) { super.updateView(size) label.updateView(size) + mvmSwitch.updateView(size) mfTextButton.updateView(size) } @@ -48,19 +49,26 @@ import UIKit if let dict = json?.optionalDictionaryForKey("label") { label.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) } - if let dict = json?.optionalDictionaryForKey("textButton") { mfTextButton.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) } - if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) } - if let onColorString = json?.optionalStringForKey("onTintColor") { mvmSwitch.onTintColor = .mfGet(forHex: onColorString) } - mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false + if let offColorString = json?.optionalStringForKey("offTintColor") { + mvmSwitch.offTintColor = .mfGet(forHex: offColorString) + } + if let onKnobColorString = json?.optionalStringForKey("onKnobTintColor") { + mvmSwitch.onKnobTintColor = .mfGet(forHex: onKnobColorString) + } + if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") { + mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString) + } +// mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false + mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) } func setupConstraints(forView view: UIView) { From 281a10f7e1478f3b249da973c079f4d25e8140fd Mon Sep 17 00:00:00 2001 From: Priya Date: Fri, 17 May 2019 14:36:18 -0400 Subject: [PATCH 08/17] Switch molecule --- MVMCoreUI/Molecules/Switch.swift | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index 658a375c..f756e9d9 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -10,9 +10,11 @@ import UIKit @objcMembers public class Switch: ViewConstrainingView, FormValidationProtocol{ public var mvmSwitch = MVMCoreUISwitch() - var label = Label() - var mfTextButton = MFTextButton() - var isRequired: Bool! = false + public var label = Label() + public var mfTextButton = MFTextButton() + var topConstraint_Switch: NSLayoutConstraint? + var bottomConstraint_textBtn: NSLayoutConstraint? + var isRequired = false var delegateObject: DelegateObject? @objc func switchChanged() { @@ -44,7 +46,7 @@ import UIKit open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - isRequired = json?[KeyRequired] as? Bool + isRequired = json?[KeyRequired] as? Bool ?? false self.delegateObject = delegateObject if let dict = json?.optionalDictionaryForKey("label") { label.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) @@ -67,19 +69,30 @@ import UIKit if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") { mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString) } -// mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false + // mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) + //updateContraints() + } + + func updateContraints() { + if let isEmptyText = label.text?.isEmpty,isEmptyText == false{ + topConstraint_Switch?.priority = UILayoutPriority(rawValue:249) + NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true) + } + layoutIfNeeded() } func setupConstraints(forView view: UIView) { NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0) - NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .equal, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .equal) + let dict = NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .greaterThanOrEqual, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .equal) + topConstraint_Switch = dict?[ConstraintTop] as? NSLayoutConstraint NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0) _ = NSLayoutConstraint(pinFirstView: label, toSecondView: mvmSwitch, withConstant: PaddingOne, directionVertical: false) _ = NSLayoutConstraint(pinFirstView: label, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0) NSLayoutConstraint.constraintPinBottomSubview(mfTextButton, bottomConstant: 0) - NSLayoutConstraint.constraintPinRightSubview(mfTextButton, rightConstant: 0) + // NSLayoutConstraint.constraintPinRightSubview(mfTextButton, rightConstant: 0) + if label.text?.isEmpty ?? false == false { _ = NSLayoutConstraint(pinFirstView: mvmSwitch, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) } @@ -108,3 +121,4 @@ import UIKit } + From aac9db9ca5894efacb8018dd88d0564c29a252e2 Mon Sep 17 00:00:00 2001 From: Priya Date: Fri, 17 May 2019 15:22:12 -0400 Subject: [PATCH 09/17] Switch molecule --- MVMCoreUI/Molecules/Switch.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index f756e9d9..fee44c09 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -17,7 +17,7 @@ import UIKit var isRequired = false var delegateObject: DelegateObject? -@objc func switchChanged() { + @objc func switchChanged() { let delegate = delegateObject as? MVMCoreUIDelegateObject if let delegate = delegate { let formValidator = delegate.formValidationProtocol?.formValidatorModel?() From ddd8eb9d453a5eb8d443835a91687c1a02d58f3e Mon Sep 17 00:00:00 2001 From: Priya Date: Mon, 20 May 2019 09:35:35 -0400 Subject: [PATCH 10/17] Switch molecule --- MVMCoreUI/Molecules/Switch.swift | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index fee44c09..1c58d5e5 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -17,14 +17,14 @@ import UIKit var isRequired = false var delegateObject: DelegateObject? - @objc func switchChanged() { + @objc func switchChanged() { let delegate = delegateObject as? MVMCoreUIDelegateObject if let delegate = delegate { let formValidator = delegate.formValidationProtocol?.formValidatorModel?() formValidator?.enableByValidation() } } - + open override func setupView() { super.setupView() mvmSwitch.addTarget(self, action: #selector(Switch.switchChanged), for: .valueChanged) @@ -34,7 +34,7 @@ import UIKit // label.translatesAutoresizingMaskIntoConstraints = false mvmSwitch.translatesAutoresizingMaskIntoConstraints = false mfTextButton.translatesAutoresizingMaskIntoConstraints = false; - setupConstraints(forView: self) + setupConstraints() } public override func updateView(_ size: CGFloat) { @@ -54,7 +54,7 @@ import UIKit if let dict = json?.optionalDictionaryForKey("textButton") { mfTextButton.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) } - if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { + if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) } if let onColorString = json?.optionalStringForKey("onTintColor") { @@ -71,32 +71,27 @@ import UIKit } // mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) - //updateContraints() + updateContraints() } func updateContraints() { - if let isEmptyText = label.text?.isEmpty,isEmptyText == false{ + if let isEmptyText = label.text?.isEmpty,isEmptyText == false { topConstraint_Switch?.priority = UILayoutPriority(rawValue:249) NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true) + _ = NSLayoutConstraint(pinFirstView: mvmSwitch, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) } layoutIfNeeded() } - func setupConstraints(forView view: UIView) { + func setupConstraints() { NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0) - let dict = NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .greaterThanOrEqual, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .equal) + let dict = NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .greaterThanOrEqual, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .greaterThanOrEqual) topConstraint_Switch = dict?[ConstraintTop] as? NSLayoutConstraint NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0) _ = NSLayoutConstraint(pinFirstView: label, toSecondView: mvmSwitch, withConstant: PaddingOne, directionVertical: false) _ = NSLayoutConstraint(pinFirstView: label, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0) NSLayoutConstraint.constraintPinBottomSubview(mfTextButton, bottomConstant: 0) - // NSLayoutConstraint.constraintPinRightSubview(mfTextButton, rightConstant: 0) - - if label.text?.isEmpty ?? false == false { - _ = NSLayoutConstraint(pinFirstView: mvmSwitch, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) - } - } public func isValidField() -> Bool { From 9f5600a0f30cd47834351afdc371ae2b5e516205 Mon Sep 17 00:00:00 2001 From: Priya Date: Mon, 20 May 2019 15:51:07 -0400 Subject: [PATCH 11/17] switch modification --- MVMCoreUI/Molecules/Switch.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index 1c58d5e5..4f410366 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -84,7 +84,8 @@ import UIKit } func setupConstraints() { - NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0) + NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0) + NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true) let dict = NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .greaterThanOrEqual, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .greaterThanOrEqual) topConstraint_Switch = dict?[ConstraintTop] as? NSLayoutConstraint NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0) From 9fd2d2cbda0ab1928e4ae4efee3ba9077fd0a774 Mon Sep 17 00:00:00 2001 From: Priya Date: Tue, 21 May 2019 14:04:46 -0400 Subject: [PATCH 12/17] Switch molecule --- MVMCoreUI/Molecules/Switch.swift | 55 ++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index 4f410366..2c4fe19a 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -11,6 +11,7 @@ import UIKit @objcMembers public class Switch: ViewConstrainingView, FormValidationProtocol{ public var mvmSwitch = MVMCoreUISwitch() public var label = Label() + public var leftContainerView = UIView() public var mfTextButton = MFTextButton() var topConstraint_Switch: NSLayoutConstraint? var bottomConstraint_textBtn: NSLayoutConstraint? @@ -28,9 +29,11 @@ import UIKit open override func setupView() { super.setupView() mvmSwitch.addTarget(self, action: #selector(Switch.switchChanged), for: .valueChanged) + //leftContainerView.addSubview(mvmSwitch) + leftContainerView.addSubview(label) + leftContainerView.addSubview(mfTextButton) + addSubview(leftContainerView) addSubview(mvmSwitch) - addSubview(label) - addSubview(mfTextButton) // label.translatesAutoresizingMaskIntoConstraints = false mvmSwitch.translatesAutoresizingMaskIntoConstraints = false mfTextButton.translatesAutoresizingMaskIntoConstraints = false; @@ -71,28 +74,40 @@ import UIKit } // mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) - updateContraints() - } - - func updateContraints() { - if let isEmptyText = label.text?.isEmpty,isEmptyText == false { - topConstraint_Switch?.priority = UILayoutPriority(rawValue:249) - NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true) - _ = NSLayoutConstraint(pinFirstView: mvmSwitch, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) - } - layoutIfNeeded() +// updateContraints(json?.optionalDictionaryForKey("textButton")) + leftContainerView.backgroundColor = .red } func setupConstraints() { - NSLayoutConstraint.constraintPinLeftSubview(label, leftConstant: 0) - NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true) - let dict = NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .greaterThanOrEqual, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .greaterThanOrEqual) - topConstraint_Switch = dict?[ConstraintTop] as? NSLayoutConstraint + var constraint = label.topAnchor.constraint(equalTo: topAnchor) + constraint.priority = UILayoutPriority(rawValue: 249) + constraint.isActive = true + label.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true + label.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true + NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true) + let _ = NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .greaterThanOrEqual, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .equal) + // NSLayoutConstraint.constraintPinRightSubview(mvmSwitch, rightConstant: 0) + constraint = mvmSwitch.topAnchor.constraint(equalTo: topAnchor) + constraint.priority = UILayoutPriority(rawValue: 249) + constraint.isActive = true + constraint = bottomAnchor.constraint(equalTo: mvmSwitch.bottomAnchor) + constraint.priority = UILayoutPriority(rawValue: 249) + constraint.isActive = true + //topConstraint_Switch = dict?[ConstraintTop] as? NSLayoutConstraint NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0) - _ = NSLayoutConstraint(pinFirstView: label, toSecondView: mvmSwitch, withConstant: PaddingOne, directionVertical: false) - _ = NSLayoutConstraint(pinFirstView: label, toSecondView: mfTextButton, withConstant: PaddingOne, directionVertical: true) - NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0) - NSLayoutConstraint.constraintPinBottomSubview(mfTextButton, bottomConstant: 0) + +// mvmSwitch.setContentHuggingPriority(UILayoutPriority(rawValue: 800), for: NSLayoutConstraint.Axis.horizontal) + + mvmSwitch.leadingAnchor.constraint(greaterThanOrEqualTo: label.trailingAnchor).isActive = true + mvmSwitch.leadingAnchor.constraint(greaterThanOrEqualTo: mfTextButton.trailingAnchor).isActive = true + NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0) + constraint = bottomAnchor.constraint(equalTo: mfTextButton.bottomAnchor) + constraint.priority = UILayoutPriority(249) + constraint.isActive = true + bottomAnchor.constraint(greaterThanOrEqualTo: mfTextButton.bottomAnchor).isActive = true + label.bottomAnchor.constraint(equalTo: mfTextButton.topAnchor, constant: 0).isActive = true + leftContainerView.setContentHuggingPriority(UILayoutPriority(rawValue: 900), for: NSLayoutConstraint.Axis.horizontal) + } public func isValidField() -> Bool { From 89b1c9a21b26cc194978ed0ada5c45020720eece Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 23 May 2019 11:40:21 -0400 Subject: [PATCH 13/17] Switch molecule --- MVMCoreUI.xcodeproj/project.pbxproj | 18 +-- MVMCoreUI/Atoms/Buttons/MFTextButton.m | 6 + .../{Switch.swift => SwitchLineItem.swift} | 107 +++++++++++------- 3 files changed, 79 insertions(+), 52 deletions(-) rename MVMCoreUI/Molecules/{Switch.swift => SwitchLineItem.swift} (52%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 45a09419..ec95f4d8 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -10,7 +10,7 @@ 0105618D224BBE7700E1557D /* FormValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618A224BBE7700E1557D /* FormValidator.swift */; }; 0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */; }; 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */; }; - 016A1071228122180009D605 /* Switch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016A1070228122180009D605 /* Switch.swift */; }; + 016A1071228122180009D605 /* SwitchLineItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016A1070228122180009D605 /* SwitchLineItem.swift */; }; 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 */; }; @@ -171,7 +171,7 @@ 0105618A224BBE7700E1557D /* FormValidator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidator.swift; sourceTree = ""; }; 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+TextFields.swift"; sourceTree = ""; }; 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+FormParams.swift"; sourceTree = ""; }; - 016A1070228122180009D605 /* Switch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Switch.swift; sourceTree = ""; }; + 016A1070228122180009D605 /* SwitchLineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchLineItem.swift; sourceTree = ""; }; 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 = ""; }; @@ -444,7 +444,7 @@ D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */, D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */, D282AACA2243C61700C46919 /* ButtonView.swift */, - 016A1070228122180009D605 /* Switch.swift */, + 016A1070228122180009D605 /* SwitchLineItem.swift */, D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */, D2A514662213885800345BFB /* StandardHeaderView.swift */, D2A5145C2211D22A00345BFB /* MVMCoreUIMoleculeViewProtocol.h */, @@ -920,7 +920,7 @@ D2A5146B2214905000345BFB /* ThreeLayerViewController.swift in Sources */, D29DF2C921E7BFC6003B2FB9 /* MFSizeObject.m in Sources */, D29DF2C721E7BF57003B2FB9 /* MFTabBarInteractor.m in Sources */, - 016A1071228122180009D605 /* Switch.swift in Sources */, + 016A1071228122180009D605 /* SwitchLineItem.swift in Sources */, D29DF29521E7ADB8003B2FB9 /* ProgrammaticScrollViewController.m in Sources */, D29DF16121E69996003B2FB9 /* MFViewController.m in Sources */, D2E1FAE12268E81D00AEFD8C /* MoleculeListTemplate.swift in Sources */, @@ -1102,9 +1102,9 @@ BITCODE_GENERATION_MODE = bitcode; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; - CODE_SIGN_STYLE = Automatic; + CODE_SIGN_STYLE = Manual; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = FCMA4QKS77; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -1119,6 +1119,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.vzw.MVMCoreUI; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; @@ -1132,9 +1133,9 @@ BITCODE_GENERATION_MODE = bitcode; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; - CODE_SIGN_STYLE = Automatic; + CODE_SIGN_STYLE = Manual; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = FCMA4QKS77; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -1149,6 +1150,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.vzw.MVMCoreUI; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/MVMCoreUI/Atoms/Buttons/MFTextButton.m b/MVMCoreUI/Atoms/Buttons/MFTextButton.m index d78df33d..aa176923 100644 --- a/MVMCoreUI/Atoms/Buttons/MFTextButton.m +++ b/MVMCoreUI/Atoms/Buttons/MFTextButton.m @@ -18,6 +18,9 @@ @interface MFTextButton () + +@property (nullable, nonatomic, strong) NSLayoutConstraint *widthConstraint; + @end @implementation MFTextButton @@ -122,6 +125,7 @@ } else { [theButton setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical]; } + theButton.widthConstraint = [theButton.widthAnchor constraintEqualToConstant:0]; [theButton updateView:width]; return theButton; } @@ -136,8 +140,10 @@ [self setWithActionMap:json delegateObject:delegateObject additionalData:additionalData]; if ([self titleForState:UIControlStateNormal].length == 0) { self.heightConstraint.constant = 0; + self.widthConstraint.active = YES; } else { self.heightConstraint.constant = self.sizeObject.standardSize; + self.widthConstraint.active = NO; } } diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/SwitchLineItem.swift similarity index 52% rename from MVMCoreUI/Molecules/Switch.swift rename to MVMCoreUI/Molecules/SwitchLineItem.swift index 2c4fe19a..cc4d076f 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/SwitchLineItem.swift @@ -1,5 +1,5 @@ // -// Switch.swift +// SwitchLineItem.swift // MVMCoreUI // // Created by Priya on 5/6/19. @@ -12,9 +12,7 @@ import UIKit public var mvmSwitch = MVMCoreUISwitch() public var label = Label() public var leftContainerView = UIView() - public var mfTextButton = MFTextButton() - var topConstraint_Switch: NSLayoutConstraint? - var bottomConstraint_textBtn: NSLayoutConstraint? + public var mfTextButton = MFTextButton(nil, constrainHeight: true, forWidth: 0) var isRequired = false var delegateObject: DelegateObject? @@ -29,15 +27,16 @@ import UIKit open override func setupView() { super.setupView() mvmSwitch.addTarget(self, action: #selector(Switch.switchChanged), for: .valueChanged) - //leftContainerView.addSubview(mvmSwitch) leftContainerView.addSubview(label) leftContainerView.addSubview(mfTextButton) addSubview(leftContainerView) addSubview(mvmSwitch) - // label.translatesAutoresizingMaskIntoConstraints = false + + leftContainerView.translatesAutoresizingMaskIntoConstraints = false mvmSwitch.translatesAutoresizingMaskIntoConstraints = false - mfTextButton.translatesAutoresizingMaskIntoConstraints = false; - setupConstraints() + mfTextButton.translatesAutoresizingMaskIntoConstraints = false + label.translatesAutoresizingMaskIntoConstraints = false + setupContainerConstraints() } public override func updateView(_ size: CGFloat) { @@ -51,12 +50,8 @@ import UIKit super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) isRequired = json?[KeyRequired] as? Bool ?? false self.delegateObject = delegateObject - if let dict = json?.optionalDictionaryForKey("label") { - label.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) - } - if let dict = json?.optionalDictionaryForKey("textButton") { - mfTextButton.setWithJSON(dict, delegateObject: delegateObject, additionalData: additionalData) - } + label.setWithJSON(json?.optionalDictionaryForKey("label"), delegateObject: delegateObject, additionalData: additionalData) + mfTextButton.setWithJSON(json?.optionalDictionaryForKey("textButton"), delegateObject: delegateObject, additionalData: additionalData) if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) } @@ -72,42 +67,66 @@ import UIKit if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") { mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString) } - // mvmSwitch.isOn = json?.optionalBoolForKey("state") ?? false mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) -// updateContraints(json?.optionalDictionaryForKey("textButton")) - leftContainerView.backgroundColor = .red + // if left container no width + if (label.text?.count ?? 0) <= 0 && (mfTextButton.titleLabel?.text?.count ?? 0) <= 0 { + mvmSwitch.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0).isActive = true + } } - - func setupConstraints() { - var constraint = label.topAnchor.constraint(equalTo: topAnchor) - constraint.priority = UILayoutPriority(rawValue: 249) - constraint.isActive = true - label.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true - label.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true - NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true) - let _ = NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinTop: true, topConstant: 0, topRelation: .greaterThanOrEqual, pinBottom: true, bottomConstant: 0, bottomRelation: .greaterThanOrEqual, pinLeft: false, leftConstant: 0, leftRelation: .equal, pinRight: true, rightConstant: 0, rightRelation: .equal) - // NSLayoutConstraint.constraintPinRightSubview(mvmSwitch, rightConstant: 0) - constraint = mvmSwitch.topAnchor.constraint(equalTo: topAnchor) - constraint.priority = UILayoutPriority(rawValue: 249) - constraint.isActive = true - constraint = bottomAnchor.constraint(equalTo: mvmSwitch.bottomAnchor) - constraint.priority = UILayoutPriority(rawValue: 249) - constraint.isActive = true - //topConstraint_Switch = dict?[ConstraintTop] as? NSLayoutConstraint - NSLayoutConstraint.constraintPinTopSubview(label, topConstant: 0) + + func setupContainerConstraints() { + leftContainerView.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true -// mvmSwitch.setContentHuggingPriority(UILayoutPriority(rawValue: 800), for: NSLayoutConstraint.Axis.horizontal) - - mvmSwitch.leadingAnchor.constraint(greaterThanOrEqualTo: label.trailingAnchor).isActive = true - mvmSwitch.leadingAnchor.constraint(greaterThanOrEqualTo: mfTextButton.trailingAnchor).isActive = true - NSLayoutConstraint.constraintPinLeftSubview(mfTextButton, leftConstant: 0) - constraint = bottomAnchor.constraint(equalTo: mfTextButton.bottomAnchor) + var constraint = leftContainerView.topAnchor.constraint(equalTo: topAnchor) constraint.priority = UILayoutPriority(249) constraint.isActive = true - bottomAnchor.constraint(greaterThanOrEqualTo: mfTextButton.bottomAnchor).isActive = true - label.bottomAnchor.constraint(equalTo: mfTextButton.topAnchor, constant: 0).isActive = true - leftContainerView.setContentHuggingPriority(UILayoutPriority(rawValue: 900), for: NSLayoutConstraint.Axis.horizontal) + + mvmSwitch.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true + + constraint = mvmSwitch.topAnchor.constraint(equalTo: topAnchor) + constraint.priority = UILayoutPriority(249) + constraint.isActive = true + + trailingAnchor.constraint(equalTo: mvmSwitch.trailingAnchor).isActive = true + + constraint = bottomAnchor.constraint(equalTo: mvmSwitch.bottomAnchor) + constraint.priority = UILayoutPriority(249) + constraint.isActive = true + + bottomAnchor.constraint(greaterThanOrEqualTo: mvmSwitch.bottomAnchor).isActive = true + constraint = bottomAnchor.constraint(equalTo: leftContainerView.bottomAnchor) + constraint.isActive = true + + bottomAnchor.constraint(greaterThanOrEqualTo: leftContainerView.bottomAnchor).isActive = true + leftContainerView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true + + NSLayoutConstraint.constraintPinSubview(leftContainerView, pinCenterX: false, pinCenterY: true) + constraint = mvmSwitch.leadingAnchor.constraint(greaterThanOrEqualTo: leftContainerView.trailingAnchor) + constraint.priority = UILayoutPriority(999) + constraint.isActive = true + NSLayoutConstraint.constraintPinSubview(mvmSwitch, pinCenterX: false, pinCenterY: true) + + leftContainerView.topAnchor.constraint(equalTo: label.topAnchor).isActive = true + leftContainerView.trailingAnchor.constraint(greaterThanOrEqualTo: label.trailingAnchor).isActive = true + + constraint = leftContainerView.trailingAnchor.constraint(equalTo: label.trailingAnchor) + constraint.priority = UILayoutPriority(249) + constraint.isActive = true + + leftContainerView.trailingAnchor.constraint(greaterThanOrEqualTo: mfTextButton.trailingAnchor).isActive = true + + constraint = leftContainerView.trailingAnchor.constraint(equalTo: mfTextButton.trailingAnchor) + constraint.priority = UILayoutPriority(249) + constraint.isActive = true + + leftContainerView.bottomAnchor.constraint(equalTo: mfTextButton.bottomAnchor).isActive = true + mfTextButton.leadingAnchor.constraint(equalTo: leftContainerView.leadingAnchor).isActive = true + label.leadingAnchor.constraint(equalTo: leftContainerView.leadingAnchor).isActive = true + mfTextButton.topAnchor.constraint(equalTo: label.bottomAnchor).isActive = true + leftContainerView.setContentHuggingPriority(.defaultHigh, for: .horizontal) + mvmSwitch.setContentHuggingPriority(.defaultLow, for: .horizontal) + } public func isValidField() -> Bool { From 2e99c7baff9fd43f15cda3ef09f93f1bd402adb6 Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 23 May 2019 12:31:36 -0400 Subject: [PATCH 14/17] Switch molecule --- MVMCoreUI.xcodeproj/project.pbxproj | 8 ++++---- MVMCoreUI/Atoms/Buttons/MFTextButton.m | 6 ------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index ec95f4d8..3d7bdc49 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -1101,8 +1101,8 @@ buildSettings = { BITCODE_GENERATION_MODE = bitcode; CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = ""; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; @@ -1132,8 +1132,8 @@ buildSettings = { BITCODE_GENERATION_MODE = bitcode; CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = ""; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; diff --git a/MVMCoreUI/Atoms/Buttons/MFTextButton.m b/MVMCoreUI/Atoms/Buttons/MFTextButton.m index aa176923..d78df33d 100644 --- a/MVMCoreUI/Atoms/Buttons/MFTextButton.m +++ b/MVMCoreUI/Atoms/Buttons/MFTextButton.m @@ -18,9 +18,6 @@ @interface MFTextButton () - -@property (nullable, nonatomic, strong) NSLayoutConstraint *widthConstraint; - @end @implementation MFTextButton @@ -125,7 +122,6 @@ } else { [theButton setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical]; } - theButton.widthConstraint = [theButton.widthAnchor constraintEqualToConstant:0]; [theButton updateView:width]; return theButton; } @@ -140,10 +136,8 @@ [self setWithActionMap:json delegateObject:delegateObject additionalData:additionalData]; if ([self titleForState:UIControlStateNormal].length == 0) { self.heightConstraint.constant = 0; - self.widthConstraint.active = YES; } else { self.heightConstraint.constant = self.sizeObject.standardSize; - self.widthConstraint.active = NO; } } From 344163de4965e8912754f6de65307a126cb49e6b Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 23 May 2019 16:22:32 -0400 Subject: [PATCH 15/17] Switch molecule --- MVMCoreUI.xcodeproj/project.pbxproj | 14 +-- MVMCoreUI/Molecules/Switch.swift | 87 +++++++++++++++++++ MVMCoreUI/Molecules/SwitchLineItem.swift | 53 +++++------ .../MVMCoreUIMoleculeMappingObject.m | 1 + 4 files changed, 123 insertions(+), 32 deletions(-) create mode 100644 MVMCoreUI/Molecules/Switch.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 3d7bdc49..bed0e280 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 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 */; }; + 01CA51B5229716F60071A6EE /* Switch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01CA51B4229716F60071A6EE /* Switch.swift */; }; 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, ); }; }; @@ -175,6 +176,7 @@ 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 = ""; }; + 01CA51B4229716F60071A6EE /* Switch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Switch.swift; 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 = ""; }; D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUINavigationController.h; sourceTree = ""; }; @@ -445,6 +447,7 @@ D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */, D282AACA2243C61700C46919 /* ButtonView.swift */, 016A1070228122180009D605 /* SwitchLineItem.swift */, + 01CA51B4229716F60071A6EE /* Switch.swift */, D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */, D2A514662213885800345BFB /* StandardHeaderView.swift */, D2A5145C2211D22A00345BFB /* MVMCoreUIMoleculeViewProtocol.h */, @@ -940,6 +943,7 @@ D29770FC21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m in Sources */, D29DF25121E6A177003B2FB9 /* MFDigitTextBox.m in Sources */, DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */, + 01CA51B5229716F60071A6EE /* Switch.swift in Sources */, 0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */, D29DF13221E6851E003B2FB9 /* MVMCoreUITopAlertBaseView.m in Sources */, D29DF29C21E7ADB9003B2FB9 /* MFProgrammaticTableViewController.m in Sources */, @@ -1101,10 +1105,10 @@ buildSettings = { BITCODE_GENERATION_MODE = bitcode; CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Automatic; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = FCMA4QKS77; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -1119,7 +1123,6 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.vzw.MVMCoreUI; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; @@ -1132,10 +1135,10 @@ buildSettings = { BITCODE_GENERATION_MODE = bitcode; CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Automatic; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = FCMA4QKS77; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -1150,7 +1153,6 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.vzw.MVMCoreUI; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift new file mode 100644 index 00000000..81818ee3 --- /dev/null +++ b/MVMCoreUI/Molecules/Switch.swift @@ -0,0 +1,87 @@ +// +// Switch.swift +// MVMCoreUI +// +// Created by Priya on 5/23/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers public class Switch: ViewConstrainingView, FormValidationProtocol{ + public var mvmSwitch = MVMCoreUISwitch() + var isRequired = false + var delegateObject: DelegateObject? + + @objc func switchChanged() { + let delegate = delegateObject as? MVMCoreUIDelegateObject + if let delegate = delegate { + let formValidator = delegate.formValidationProtocol?.formValidatorModel?() + formValidator?.enableByValidation() + } + } + + open override func setupView() { + super.setupView() + mvmSwitch.addTarget(self, action: #selector(Switch.switchChanged), for: .valueChanged) + self.clipsToBounds = true + addSubview(mvmSwitch) + mvmSwitch.translatesAutoresizingMaskIntoConstraints = false + setupContainerConstraints() + } + + public override func updateView(_ size: CGFloat) { + super.updateView(size) + mvmSwitch.updateView(size) + } + + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + isRequired = json?[KeyRequired] as? Bool ?? false + self.delegateObject = delegateObject + if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { + FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) + } + if let onColorString = json?.optionalStringForKey("onTintColor") { + mvmSwitch.onTintColor = .mfGet(forHex: onColorString) + } + if let offColorString = json?.optionalStringForKey("offTintColor") { + mvmSwitch.offTintColor = .mfGet(forHex: offColorString) + } + if let onKnobColorString = json?.optionalStringForKey("onKnobTintColor") { + mvmSwitch.onKnobTintColor = .mfGet(forHex: onKnobColorString) + } + if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") { + mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString) + } + mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) + } + + func setupContainerConstraints() { + mvmSwitch.topAnchor.constraint(equalTo: topAnchor).isActive = true + mvmSwitch.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true + mvmSwitch.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true + mvmSwitch.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true + } + + public func isValidField() -> Bool { + return (isRequired == false) ? true : mvmSwitch.isOn + } + + public func formFieldName() -> String? { + return json?.optionalStringForKey(KeyFieldKey) + } + + public func formFieldValue() -> Any? { + return mvmSwitch.isOn + } + + public override func needsToBeConstrained() -> Bool { + return true + } + + public override func moleculeAlignment() -> UIStackView.Alignment { + return UIStackView.Alignment.leading + } +} + diff --git a/MVMCoreUI/Molecules/SwitchLineItem.swift b/MVMCoreUI/Molecules/SwitchLineItem.swift index cc4d076f..703f5878 100644 --- a/MVMCoreUI/Molecules/SwitchLineItem.swift +++ b/MVMCoreUI/Molecules/SwitchLineItem.swift @@ -8,8 +8,8 @@ import UIKit -@objcMembers public class Switch: ViewConstrainingView, FormValidationProtocol{ - public var mvmSwitch = MVMCoreUISwitch() +@objcMembers public class SwitchLineItem: ViewConstrainingView, FormValidationProtocol{ + public var mvmSwitch = Switch() public var label = Label() public var leftContainerView = UIView() public var mfTextButton = MFTextButton(nil, constrainHeight: true, forWidth: 0) @@ -26,7 +26,7 @@ import UIKit open override func setupView() { super.setupView() - mvmSwitch.addTarget(self, action: #selector(Switch.switchChanged), for: .valueChanged) + // mvmSwitch.addTarget(self, action: #selector(SwitchLineItem.switchChanged), for: .valueChanged) leftContainerView.addSubview(label) leftContainerView.addSubview(mfTextButton) addSubview(leftContainerView) @@ -50,24 +50,25 @@ import UIKit super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) isRequired = json?[KeyRequired] as? Bool ?? false self.delegateObject = delegateObject + mvmSwitch.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) label.setWithJSON(json?.optionalDictionaryForKey("label"), delegateObject: delegateObject, additionalData: additionalData) mfTextButton.setWithJSON(json?.optionalDictionaryForKey("textButton"), delegateObject: delegateObject, additionalData: additionalData) - if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { - FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) - } - if let onColorString = json?.optionalStringForKey("onTintColor") { - mvmSwitch.onTintColor = .mfGet(forHex: onColorString) - } - if let offColorString = json?.optionalStringForKey("offTintColor") { - mvmSwitch.offTintColor = .mfGet(forHex: offColorString) - } - if let onKnobColorString = json?.optionalStringForKey("onKnobTintColor") { - mvmSwitch.onKnobTintColor = .mfGet(forHex: onKnobColorString) - } - if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") { - mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString) - } - mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) +// if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { +// FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) +// } +// if let onColorString = json?.optionalStringForKey("onTintColor") { +// mvmSwitch.onTintColor = .mfGet(forHex: onColorString) +// } +// if let offColorString = json?.optionalStringForKey("offTintColor") { +// mvmSwitch.offTintColor = .mfGet(forHex: offColorString) +// } +// if let onKnobColorString = json?.optionalStringForKey("onKnobTintColor") { +// mvmSwitch.onKnobTintColor = .mfGet(forHex: onKnobColorString) +// } +// if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") { +// mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString) +// } +// mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) // if left container no width if (label.text?.count ?? 0) <= 0 && (mfTextButton.titleLabel?.text?.count ?? 0) <= 0 { mvmSwitch.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0).isActive = true @@ -129,17 +130,17 @@ import UIKit } - public func isValidField() -> Bool { - return (isRequired == false) ? true : mvmSwitch.isOn - } +// public func isValidField() -> Bool { +// return (isRequired == false) ? true : mvmSwitch.isOn +// } public func formFieldName() -> String? { return json?.optionalStringForKey(KeyFieldKey) } - - public func formFieldValue() -> Any? { - return mvmSwitch.isOn - } +// +// public func formFieldValue() -> Any? { +// return mvmSwitch.isOn +// } public override func needsToBeConstrained() -> Bool { return true diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 391dd561..0cc21b30 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -34,6 +34,7 @@ @"caretButton": CaretButton.class, @"textField" : MFTextField.class, @"checkbox" : MVMCoreUICheckBox.class, + @"switchLineItem" : SwitchLineItem.class, @"switch" : Switch.class } mutableCopy]; }); From b73c91619275683a1a2cf2dce6b80df331648174 Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 23 May 2019 16:32:14 -0400 Subject: [PATCH 16/17] Switch molecule --- MVMCoreUI/Molecules/SwitchLineItem.swift | 28 ------------------------ 1 file changed, 28 deletions(-) diff --git a/MVMCoreUI/Molecules/SwitchLineItem.swift b/MVMCoreUI/Molecules/SwitchLineItem.swift index 703f5878..4eeae278 100644 --- a/MVMCoreUI/Molecules/SwitchLineItem.swift +++ b/MVMCoreUI/Molecules/SwitchLineItem.swift @@ -26,7 +26,6 @@ import UIKit open override func setupView() { super.setupView() - // mvmSwitch.addTarget(self, action: #selector(SwitchLineItem.switchChanged), for: .valueChanged) leftContainerView.addSubview(label) leftContainerView.addSubview(mfTextButton) addSubview(leftContainerView) @@ -53,23 +52,6 @@ import UIKit mvmSwitch.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) label.setWithJSON(json?.optionalDictionaryForKey("label"), delegateObject: delegateObject, additionalData: additionalData) mfTextButton.setWithJSON(json?.optionalDictionaryForKey("textButton"), delegateObject: delegateObject, additionalData: additionalData) -// if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { -// FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) -// } -// if let onColorString = json?.optionalStringForKey("onTintColor") { -// mvmSwitch.onTintColor = .mfGet(forHex: onColorString) -// } -// if let offColorString = json?.optionalStringForKey("offTintColor") { -// mvmSwitch.offTintColor = .mfGet(forHex: offColorString) -// } -// if let onKnobColorString = json?.optionalStringForKey("onKnobTintColor") { -// mvmSwitch.onKnobTintColor = .mfGet(forHex: onKnobColorString) -// } -// if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") { -// mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString) -// } -// mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) - // if left container no width if (label.text?.count ?? 0) <= 0 && (mfTextButton.titleLabel?.text?.count ?? 0) <= 0 { mvmSwitch.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0).isActive = true } @@ -127,20 +109,11 @@ import UIKit mfTextButton.topAnchor.constraint(equalTo: label.bottomAnchor).isActive = true leftContainerView.setContentHuggingPriority(.defaultHigh, for: .horizontal) mvmSwitch.setContentHuggingPriority(.defaultLow, for: .horizontal) - } - -// public func isValidField() -> Bool { -// return (isRequired == false) ? true : mvmSwitch.isOn -// } public func formFieldName() -> String? { return json?.optionalStringForKey(KeyFieldKey) } -// -// public func formFieldValue() -> Any? { -// return mvmSwitch.isOn -// } public override func needsToBeConstrained() -> Bool { return true @@ -149,7 +122,6 @@ import UIKit public override func moleculeAlignment() -> UIStackView.Alignment { return UIStackView.Alignment.leading } - } From f53bd03212a326e827a2c25b9c0e1332f2cbafa7 Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 23 May 2019 17:02:30 -0400 Subject: [PATCH 17/17] Switch molecule --- MVMCoreUI/Molecules/SwitchLineItem.swift | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/MVMCoreUI/Molecules/SwitchLineItem.swift b/MVMCoreUI/Molecules/SwitchLineItem.swift index 4eeae278..9a40c482 100644 --- a/MVMCoreUI/Molecules/SwitchLineItem.swift +++ b/MVMCoreUI/Molecules/SwitchLineItem.swift @@ -17,13 +17,13 @@ import UIKit var delegateObject: DelegateObject? @objc func switchChanged() { - let delegate = delegateObject as? MVMCoreUIDelegateObject + let delegate = delegateObject as? MVMCoreUIDelegateObject if let delegate = delegate { let formValidator = delegate.formValidationProtocol?.formValidatorModel?() formValidator?.enableByValidation() } } - + open override func setupView() { super.setupView() leftContainerView.addSubview(label) @@ -47,8 +47,6 @@ import UIKit open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - isRequired = json?[KeyRequired] as? Bool ?? false - self.delegateObject = delegateObject mvmSwitch.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) label.setWithJSON(json?.optionalDictionaryForKey("label"), delegateObject: delegateObject, additionalData: additionalData) mfTextButton.setWithJSON(json?.optionalDictionaryForKey("textButton"), delegateObject: delegateObject, additionalData: additionalData) @@ -56,14 +54,14 @@ import UIKit mvmSwitch.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0).isActive = true } } - + func setupContainerConstraints() { leftContainerView.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true var constraint = leftContainerView.topAnchor.constraint(equalTo: topAnchor) constraint.priority = UILayoutPriority(249) constraint.isActive = true - + mvmSwitch.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true constraint = mvmSwitch.topAnchor.constraint(equalTo: topAnchor) @@ -77,7 +75,7 @@ import UIKit constraint.isActive = true bottomAnchor.constraint(greaterThanOrEqualTo: mvmSwitch.bottomAnchor).isActive = true - + constraint = bottomAnchor.constraint(equalTo: leftContainerView.bottomAnchor) constraint.isActive = true @@ -92,7 +90,7 @@ import UIKit leftContainerView.topAnchor.constraint(equalTo: label.topAnchor).isActive = true leftContainerView.trailingAnchor.constraint(greaterThanOrEqualTo: label.trailingAnchor).isActive = true - + constraint = leftContainerView.trailingAnchor.constraint(equalTo: label.trailingAnchor) constraint.priority = UILayoutPriority(249) constraint.isActive = true @@ -111,10 +109,6 @@ import UIKit mvmSwitch.setContentHuggingPriority(.defaultLow, for: .horizontal) } - public func formFieldName() -> String? { - return json?.optionalStringForKey(KeyFieldKey) - } - public override func needsToBeConstrained() -> Bool { return true }