From 5534f6ba58226db233c9c6baab9f40407f7b1ca2 Mon Sep 17 00:00:00 2001 From: "Chintakrinda, Arun Kumar (Arun)" Date: Wed, 22 Jan 2020 20:27:14 +0530 Subject: [PATCH 01/16] Checkbox models added Label action attribute issue fixed --- MVMCoreUI.xcodeproj/project.pbxproj | 8 ++ MVMCoreUI/Atoms/Views/Checkbox.swift | 66 +++++++++++++++ MVMCoreUI/Atoms/Views/CheckboxModel.swift | 83 +++++++++++++++++++ .../Atoms/Views/CheckboxWithLabelView.swift | 13 +++ .../Views/CheckboxWithLabelViewModel.swift | 38 +++++++++ MVMCoreUI/Atoms/Views/Label/Label.swift | 2 +- .../OtherHandlers/MoleculeObjectMapping.swift | 4 + 7 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 MVMCoreUI/Atoms/Views/CheckboxModel.swift create mode 100644 MVMCoreUI/Atoms/Views/CheckboxWithLabelViewModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 3371e6ca..09d66304 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -88,6 +88,8 @@ 0ABD136D237CAD1E0081388D /* DateDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */; }; 0ABD1371237DB0450081388D /* ItemDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */; }; 0AE14F64238315D2005417F8 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE14F63238315D2005417F8 /* TextField.swift */; }; + 31BE15CB23D8924D00452370 /* CheckboxWithLabelViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15C923D8924C00452370 /* CheckboxWithLabelViewModel.swift */; }; + 31BE15CC23D8924D00452370 /* CheckboxModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15CA23D8924C00452370 /* CheckboxModel.swift */; }; 943784F5236B77BB006A1E82 /* GraphView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943784F3236B77BB006A1E82 /* GraphView.swift */; }; 943784F6236B77BB006A1E82 /* GraphViewAnimationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943784F4236B77BB006A1E82 /* GraphViewAnimationHandler.swift */; }; 9445890C2385BCE300DE9FD4 /* ProgressBarModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9445890B2385BCE300DE9FD4 /* ProgressBarModel.swift */; }; @@ -382,6 +384,8 @@ 0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateDropdownEntryField.swift; sourceTree = ""; }; 0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemDropdownEntryField.swift; sourceTree = ""; }; 0AE14F63238315D2005417F8 /* TextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = ""; }; + 31BE15C923D8924C00452370 /* CheckboxWithLabelViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxWithLabelViewModel.swift; sourceTree = ""; }; + 31BE15CA23D8924C00452370 /* CheckboxModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxModel.swift; sourceTree = ""; }; 9402C34F23A2CEA3004B974C /* LeftRightLabelModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeftRightLabelModel.swift; sourceTree = ""; }; 943784F3236B77BB006A1E82 /* GraphView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphView.swift; sourceTree = ""; }; 943784F4236B77BB006A1E82 /* GraphViewAnimationHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphViewAnimationHandler.swift; sourceTree = ""; }; @@ -1143,7 +1147,9 @@ DBC4391C2245232D001AB423 /* LabelWithInternalButton.swift */, 94C2D9822386F3E30006CF46 /* Label */, 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */, + 31BE15CA23D8924C00452370 /* CheckboxModel.swift */, 0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */, + 31BE15C923D8924C00452370 /* CheckboxWithLabelViewModel.swift */, 01004F2F22721C3800991ECC /* RadioButton.swift */, D28A838223CCBD3F00DFE4FC /* CircleProgressModel.swift */, 943784F3236B77BB006A1E82 /* GraphView.swift */, @@ -1473,6 +1479,7 @@ files = ( 0A5D59C223AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift in Sources */, 943784F5236B77BB006A1E82 /* GraphView.swift in Sources */, + 31BE15CC23D8924D00452370 /* CheckboxModel.swift in Sources */, 94C661DA23CCF4FB00D9FE5B /* UIColor+Extension.swift in Sources */, D29DF32121ED0CBA003B2FB9 /* LabelView.m in Sources */, D28A838123CCB0D800DFE4FC /* AccordionListItemModel.swift in Sources */, @@ -1555,6 +1562,7 @@ DBEFFA04225A829700230692 /* Label.swift in Sources */, D2D6CD4022E78C1A00D701B8 /* Scroller.swift in Sources */, 01509D952327ED1900EF99AA /* HeadlineBodyTextButtonSwitch.swift in Sources */, + 31BE15CB23D8924D00452370 /* CheckboxWithLabelViewModel.swift in Sources */, D260105523CEA7DC00764D80 /* MVMCoreUISwitch+Model.swift in Sources */, D29DF13021E6851E003B2FB9 /* MVMCoreUITopAlertShortView.m in Sources */, 0ABD136D237CAD1E0081388D /* DateDropdownEntryField.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index 50571e30..0c7ca537 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -458,6 +458,72 @@ import MVMCore actionBlock = { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } } } + + public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + super.setWithModel(model, delegateObject, additionalData) + guard let checkboxModel = model as? CheckboxModel else { + return + } + self.delegateObject = delegateObject + FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol) + + groupName = checkboxModel.groupName + fieldValue = checkboxModel.value + if let fieldKey = checkboxModel.fieldKey { + self.fieldKey = fieldKey + } + + if let isRequired = checkboxModel.required { + self.isRequired = isRequired + } + + if let borderColorHex = checkboxModel.borderColor { + layer.borderColor = UIColor.mfGet(forHex: borderColorHex).cgColor + } + + if let borderWidth = checkboxModel.borderWidth { + layer.borderWidth = borderWidth + } + + if let isChecked = checkboxModel.isChecked, isChecked { + updateSelectionOnly = true + isSelected = isChecked + updateSelectionOnly = false + } + + if let checkColorHex = checkboxModel.checkColor { + checkColor = UIColor.mfGet(forHex: checkColorHex) + } + + if let unCheckedBackgroundColorHex = checkboxModel.unCheckedBackgroundColor { + unCheckedBackgroundColor = UIColor.mfGet(forHex: unCheckedBackgroundColorHex) + } + + if let checkedBackgroundColorHex = checkboxModel.checkedBackgroundColor { + checkedBackgroundColor = UIColor.mfGet(forHex: checkedBackgroundColorHex) + } + + if let isAnimated = checkboxModel.isAnimated { + self.isAnimated = isAnimated + } + + if let isRound = checkboxModel.isRound { + self.isRound = isRound + } + + if let enabled = checkboxModel.isEnabled { + isEnabled(enabled) + } + + guard let action = checkboxModel.action else { return } + actionBlock = { + if let data = try? action.encode(using: JSONEncoder()), + let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any] { + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + + } + } + } } // MARK:- FormValidationProtocol diff --git a/MVMCoreUI/Atoms/Views/CheckboxModel.swift b/MVMCoreUI/Atoms/Views/CheckboxModel.swift new file mode 100644 index 00000000..4ad1bade --- /dev/null +++ b/MVMCoreUI/Atoms/Views/CheckboxModel.swift @@ -0,0 +1,83 @@ +// +// CheckboxModel.swift +// MVMCoreUI +// +// Created by Chintakrinda, Arun Kumar (Arun) on 21/01/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +@objcMembers public class CheckboxModel: MoleculeModelProtocol { + public static var identifier: String = "checkbox" + public var backgroundColor: Color? + + public var groupName: String? + public var value: String? + public var fieldKey: String? + public var required: Bool? + public var borderColor: String? + public var borderWidth: CGFloat? + public var isChecked: Bool? + public var checkColor: String? + public var unCheckedBackgroundColor: String? + public var checkedBackgroundColor: String? + public var isAnimated: Bool? + public var isRound: Bool? + public var isEnabled: Bool? + public var action: ActionModelProtocol? + + + enum CodingKeys: String, CodingKey { + case groupName + case value + case fieldKey + case required + case borderColor + case borderWidth + case isChecked + case checkColor + case unCheckedBackgroundColor + case checkedBackgroundColor + case isAnimated + case isRound + case isEnabled + case action + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + self.groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) + self.value = try typeContainer.decodeIfPresent(String.self, forKey: .value) + self.fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey) + self.required = try typeContainer.decodeIfPresent(Bool.self, forKey: .required) + self.borderColor = try typeContainer.decodeIfPresent(String.self, forKey: .borderColor) + self.borderWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .borderWidth) + self.isChecked = try typeContainer.decodeIfPresent(Bool.self, forKey: .isChecked) + self.checkColor = try typeContainer.decodeIfPresent(String.self, forKey: .checkColor) + self.unCheckedBackgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .unCheckedBackgroundColor) + self.checkedBackgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .checkedBackgroundColor) + self.isAnimated = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAnimated) + self.isRound = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRound) + self.isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .isEnabled) + self.action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.actionType) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(groupName, forKey: .groupName) + try container.encodeIfPresent(value, forKey: .value) + try container.encodeIfPresent(fieldKey, forKey: .fieldKey) + try container.encodeIfPresent(required, forKey: .required) + try container.encodeIfPresent(borderColor, forKey: .borderColor) + try container.encodeIfPresent(borderColor, forKey: .borderColor) + try container.encodeIfPresent(isChecked, forKey: .isChecked) + try container.encodeIfPresent(checkColor, forKey: .checkColor) + try container.encodeIfPresent(unCheckedBackgroundColor, forKey: .unCheckedBackgroundColor) + try container.encodeIfPresent(checkedBackgroundColor, forKey: .checkedBackgroundColor) + try container.encodeIfPresent(isAnimated, forKey: .isAnimated) + try container.encodeIfPresent(isRound, forKey: .isRound) + try container.encodeIfPresent(isEnabled, forKey: .isEnabled) + try container.encodeModelIfPresent(action, forKey: .action) + } +} diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift index 229efe2a..27256aa3 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift @@ -120,6 +120,19 @@ checkboxCenterYConstraint?.isActive = false } } + + open override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + guard let checkBoxWithLabelModel = model as? CheckboxWithLabelViewModel else { + return + } + + if let checkboxAlignment = checkBoxWithLabelModel.checkboxAlignment, let position = CheckboxPosition(rawValue: checkboxAlignment) { + alignCheckbox(position) + } + + checkbox.setWithModel(checkBoxWithLabelModel.checkbox, delegateObject, additionalData) + label.setWithModel(checkBoxWithLabelModel.label, delegateObject, additionalData) + } } // MARK: - Molecular diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelViewModel.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelViewModel.swift new file mode 100644 index 00000000..81d64361 --- /dev/null +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelViewModel.swift @@ -0,0 +1,38 @@ +// +// CheckboxWithLabelViewModel.swift +// MVMCoreUI +// +// Created by Chintakrinda, Arun Kumar (Arun) on 21/01/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +@objcMembers public class CheckboxWithLabelViewModel: MoleculeModelProtocol { + public static var identifier: String = "checkboxLabel" + public var backgroundColor: Color? + + public var checkboxAlignment: String? + public var checkbox: CheckboxModel + public var label: LabelModel + + enum CodingKeys: String, CodingKey { + case checkboxAlignment + case checkbox + case label + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + self.checkboxAlignment = try typeContainer.decodeIfPresent(String.self, forKey: .checkboxAlignment) + self.checkbox = try typeContainer.decode(CheckboxModel.self, forKey: .checkbox) + self.label = try typeContainer.decode(LabelModel.self, forKey: .label) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(checkboxAlignment, forKey: .checkboxAlignment) + try container.encode(checkbox, forKey: .checkbox) + try container.encode(label, forKey: .label) + } +} diff --git a/MVMCoreUI/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atoms/Views/Label/Label.swift index b2953227..208676df 100644 --- a/MVMCoreUI/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label/Label.swift @@ -315,7 +315,7 @@ public typealias ActionBlock = () -> () } case let actionAtt as LabelAttributeActionModel: addTappableLinkAttribute(range: NSRange(location: range.location, length: range.length)) { - if let data = try? actionAtt.encode(using: JSONEncoder()), let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any] { + if let data = try? actionAtt.action.encode(using: JSONEncoder()), let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any] { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } } diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 2e31a757..76d4ba20 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -71,5 +71,9 @@ import Foundation ModelRegistry.register(NumberedListModel.self) ModelRegistry.register(UnOrderedListModel.self) ModelRegistry.register(HeadlineBodyToggleModel.self) + + //Checkbox + ModelRegistry.register(CheckboxModel.self) + ModelRegistry.register(CheckboxWithLabelViewModel.self) } } From 70c3da70d5fcc7466c93c8368ecba74b686f632c Mon Sep 17 00:00:00 2001 From: "Chintakrinda, Arun Kumar (Arun)" Date: Wed, 22 Jan 2020 21:53:07 +0530 Subject: [PATCH 02/16] Fixing for comments --- MVMCoreUI/Atoms/Views/Checkbox.swift | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index 0c7ca537..ae9b3354 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -515,12 +515,11 @@ import MVMCore isEnabled(enabled) } - guard let action = checkboxModel.action else { return } - actionBlock = { - if let data = try? action.encode(using: JSONEncoder()), - let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any] { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) - + if let action = checkboxModel.action { + actionBlock = { + if let actionMap = action.toJSON() { + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + } } } } From f816081d8e965b9db76095344a5e8bacbfc96e4e Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 22 Jan 2020 13:58:56 -0500 Subject: [PATCH 03/16] check box --- MVMCoreUI.xcodeproj/project.pbxproj | 8 ++++---- MVMCoreUI/Atoms/Views/Checkbox.swift | 8 ++++---- ...xWithLabelViewModel.swift => CheckboxLabelModel.swift} | 2 +- MVMCoreUI/Atoms/Views/CheckboxModel.swift | 8 ++++---- MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift | 2 +- MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) rename MVMCoreUI/Atoms/Views/{CheckboxWithLabelViewModel.swift => CheckboxLabelModel.swift} (94%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 09d66304..314ae317 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -88,7 +88,7 @@ 0ABD136D237CAD1E0081388D /* DateDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */; }; 0ABD1371237DB0450081388D /* ItemDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */; }; 0AE14F64238315D2005417F8 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE14F63238315D2005417F8 /* TextField.swift */; }; - 31BE15CB23D8924D00452370 /* CheckboxWithLabelViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15C923D8924C00452370 /* CheckboxWithLabelViewModel.swift */; }; + 31BE15CB23D8924D00452370 /* CheckboxLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */; }; 31BE15CC23D8924D00452370 /* CheckboxModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15CA23D8924C00452370 /* CheckboxModel.swift */; }; 943784F5236B77BB006A1E82 /* GraphView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943784F3236B77BB006A1E82 /* GraphView.swift */; }; 943784F6236B77BB006A1E82 /* GraphViewAnimationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943784F4236B77BB006A1E82 /* GraphViewAnimationHandler.swift */; }; @@ -384,7 +384,7 @@ 0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateDropdownEntryField.swift; sourceTree = ""; }; 0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemDropdownEntryField.swift; sourceTree = ""; }; 0AE14F63238315D2005417F8 /* TextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = ""; }; - 31BE15C923D8924C00452370 /* CheckboxWithLabelViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxWithLabelViewModel.swift; sourceTree = ""; }; + 31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxLabelModel.swift; sourceTree = ""; }; 31BE15CA23D8924C00452370 /* CheckboxModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxModel.swift; sourceTree = ""; }; 9402C34F23A2CEA3004B974C /* LeftRightLabelModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeftRightLabelModel.swift; sourceTree = ""; }; 943784F3236B77BB006A1E82 /* GraphView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphView.swift; sourceTree = ""; }; @@ -1149,7 +1149,7 @@ 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */, 31BE15CA23D8924C00452370 /* CheckboxModel.swift */, 0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */, - 31BE15C923D8924C00452370 /* CheckboxWithLabelViewModel.swift */, + 31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */, 01004F2F22721C3800991ECC /* RadioButton.swift */, D28A838223CCBD3F00DFE4FC /* CircleProgressModel.swift */, 943784F3236B77BB006A1E82 /* GraphView.swift */, @@ -1562,7 +1562,7 @@ DBEFFA04225A829700230692 /* Label.swift in Sources */, D2D6CD4022E78C1A00D701B8 /* Scroller.swift in Sources */, 01509D952327ED1900EF99AA /* HeadlineBodyTextButtonSwitch.swift in Sources */, - 31BE15CB23D8924D00452370 /* CheckboxWithLabelViewModel.swift in Sources */, + 31BE15CB23D8924D00452370 /* CheckboxLabelModel.swift in Sources */, D260105523CEA7DC00764D80 /* MVMCoreUISwitch+Model.swift in Sources */, D29DF13021E6851E003B2FB9 /* MVMCoreUITopAlertShortView.m in Sources */, 0ABD136D237CAD1E0081388D /* DateDropdownEntryField.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index ae9b3354..fe5add9b 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -485,14 +485,14 @@ import MVMCore layer.borderWidth = borderWidth } - if let isChecked = checkboxModel.isChecked, isChecked { + if checkboxModel.isChecked { updateSelectionOnly = true - isSelected = isChecked + isSelected = checkboxModel.isChecked updateSelectionOnly = false } - if let checkColorHex = checkboxModel.checkColor { - checkColor = UIColor.mfGet(forHex: checkColorHex) + if let uiCheckColor = checkboxModel.checkColor?.uiColor { + checkColor = uiCheckColor } if let unCheckedBackgroundColorHex = checkboxModel.unCheckedBackgroundColor { diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelViewModel.swift b/MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift similarity index 94% rename from MVMCoreUI/Atoms/Views/CheckboxWithLabelViewModel.swift rename to MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift index 81d64361..088f7d9e 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelViewModel.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift @@ -8,7 +8,7 @@ import Foundation -@objcMembers public class CheckboxWithLabelViewModel: MoleculeModelProtocol { +@objcMembers public class CheckboxLabelModel: MoleculeModelProtocol { public static var identifier: String = "checkboxLabel" public var backgroundColor: Color? diff --git a/MVMCoreUI/Atoms/Views/CheckboxModel.swift b/MVMCoreUI/Atoms/Views/CheckboxModel.swift index 4ad1bade..4b854951 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxModel.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxModel.swift @@ -18,8 +18,8 @@ import Foundation public var required: Bool? public var borderColor: String? public var borderWidth: CGFloat? - public var isChecked: Bool? - public var checkColor: String? + public var isChecked: Bool = false + public var checkColor: Color? public var unCheckedBackgroundColor: String? public var checkedBackgroundColor: String? public var isAnimated: Bool? @@ -53,8 +53,8 @@ import Foundation self.required = try typeContainer.decodeIfPresent(Bool.self, forKey: .required) self.borderColor = try typeContainer.decodeIfPresent(String.self, forKey: .borderColor) self.borderWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .borderWidth) - self.isChecked = try typeContainer.decodeIfPresent(Bool.self, forKey: .isChecked) - self.checkColor = try typeContainer.decodeIfPresent(String.self, forKey: .checkColor) + self.isChecked = try typeContainer.decodeIfPresent(Bool.self, forKey: .isChecked) ?? false + self.checkColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkColor) self.unCheckedBackgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .unCheckedBackgroundColor) self.checkedBackgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .checkedBackgroundColor) self.isAnimated = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAnimated) diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift index 27256aa3..69141210 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift @@ -122,7 +122,7 @@ } open override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { - guard let checkBoxWithLabelModel = model as? CheckboxWithLabelViewModel else { + guard let checkBoxWithLabelModel = model as? CheckboxLabelModel else { return } diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 76d4ba20..6c623572 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -74,6 +74,6 @@ import Foundation //Checkbox ModelRegistry.register(CheckboxModel.self) - ModelRegistry.register(CheckboxWithLabelViewModel.self) + ModelRegistry.register(CheckboxLabelModel.self) } } From 5dafbe6a8532b8062c10d4e6642280a172abb68d Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 22 Jan 2020 14:21:48 -0500 Subject: [PATCH 04/16] more color --- MVMCoreUI/Atoms/Views/Checkbox.swift | 6 +++--- MVMCoreUI/Atoms/Views/CheckboxModel.swift | 12 ++++++------ .../OtherHandlers/MVMCoreUIMoleculeMappingObject.m | 2 -- MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift | 11 +++++++---- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index fe5add9b..6b125e82 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -478,7 +478,7 @@ import MVMCore } if let borderColorHex = checkboxModel.borderColor { - layer.borderColor = UIColor.mfGet(forHex: borderColorHex).cgColor + layer.borderColor = borderColorHex.uiColor.cgColor } if let borderWidth = checkboxModel.borderWidth { @@ -496,11 +496,11 @@ import MVMCore } if let unCheckedBackgroundColorHex = checkboxModel.unCheckedBackgroundColor { - unCheckedBackgroundColor = UIColor.mfGet(forHex: unCheckedBackgroundColorHex) + unCheckedBackgroundColor = unCheckedBackgroundColorHex.uiColor } if let checkedBackgroundColorHex = checkboxModel.checkedBackgroundColor { - checkedBackgroundColor = UIColor.mfGet(forHex: checkedBackgroundColorHex) + checkedBackgroundColor = checkedBackgroundColorHex.uiColor } if let isAnimated = checkboxModel.isAnimated { diff --git a/MVMCoreUI/Atoms/Views/CheckboxModel.swift b/MVMCoreUI/Atoms/Views/CheckboxModel.swift index 4b854951..72c6dbfd 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxModel.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxModel.swift @@ -16,12 +16,12 @@ import Foundation public var value: String? public var fieldKey: String? public var required: Bool? - public var borderColor: String? + public var borderColor: Color? public var borderWidth: CGFloat? public var isChecked: Bool = false public var checkColor: Color? - public var unCheckedBackgroundColor: String? - public var checkedBackgroundColor: String? + public var unCheckedBackgroundColor: Color? + public var checkedBackgroundColor: Color? public var isAnimated: Bool? public var isRound: Bool? public var isEnabled: Bool? @@ -51,12 +51,12 @@ import Foundation self.value = try typeContainer.decodeIfPresent(String.self, forKey: .value) self.fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey) self.required = try typeContainer.decodeIfPresent(Bool.self, forKey: .required) - self.borderColor = try typeContainer.decodeIfPresent(String.self, forKey: .borderColor) + self.borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) self.borderWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .borderWidth) self.isChecked = try typeContainer.decodeIfPresent(Bool.self, forKey: .isChecked) ?? false self.checkColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkColor) - self.unCheckedBackgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .unCheckedBackgroundColor) - self.checkedBackgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .checkedBackgroundColor) + self.unCheckedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .unCheckedBackgroundColor) + self.checkedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkedBackgroundColor) self.isAnimated = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAnimated) self.isRound = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRound) self.isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .isEnabled) diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index b5a39119..687f3cd9 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -42,8 +42,6 @@ @"textEntryField": TextEntryField.class, @"itemDropdownEntryField": ItemDropdownEntryField.class, @"dateDropdownEntryField": DateDropdownEntryField.class, - @"checkbox": Checkbox.class, - @"checkboxLabel": CheckboxWithLabelView.class, @"cornerLabels" : CornerLabels.class, @"progressBar": ProgressBar.class, @"circleProgress": GraphView.class, diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 6c623572..0e53282e 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -24,6 +24,13 @@ import Foundation ModelRegistry.register(NumberedListModel.self) mapping?.setObject(NumberedList.self, forKey: NumberedListModel.identifier as NSString) + //Checkbox + ModelRegistry.register(CheckboxModel.self) + mapping?.setObject(Checkbox.self, forKey: CheckboxModel.identifier as NSString) + + ModelRegistry.register(CheckboxLabelModel.self) + mapping?.setObject(CheckboxWithLabelView.self, forKey: CheckboxLabelModel.identifier as NSString) + ModelRegistry.register(LabelModel.self) ModelRegistry.register(HeaderModel.self) ModelRegistry.register(FooterModel.self) @@ -71,9 +78,5 @@ import Foundation ModelRegistry.register(NumberedListModel.self) ModelRegistry.register(UnOrderedListModel.self) ModelRegistry.register(HeadlineBodyToggleModel.self) - - //Checkbox - ModelRegistry.register(CheckboxModel.self) - ModelRegistry.register(CheckboxLabelModel.self) } } From f438e25556a3d22a518a6f6a2d5210432f53d72c Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 22 Jan 2020 14:34:50 -0500 Subject: [PATCH 05/16] new registation --- MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 59e7cdef..cdf64335 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -44,6 +44,8 @@ import Foundation MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Line.self, viewModelClass: LineModel.self) MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: GraphView.self, viewModelClass: CircleProgressModel.self) MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Toggle.self, viewModelClass: ToggleModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Checkbox.self, viewModelClass: CheckboxModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: CheckboxWithLabelView.self, viewModelClass: CheckboxLabelModel.self) // Horizontal Combination Molecules MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: StringAndMoleculeView.self, viewModelClass: StringAndMoleculeModel.self) From 791138c34580c3d563f127124c5a86cf252a945c Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 22 Jan 2020 14:36:12 -0500 Subject: [PATCH 06/16] private --- MVMCoreUI/Atoms/Views/CheckboxModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Views/CheckboxModel.swift b/MVMCoreUI/Atoms/Views/CheckboxModel.swift index 72c6dbfd..6bf9ae1a 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxModel.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxModel.swift @@ -28,7 +28,7 @@ import Foundation public var action: ActionModelProtocol? - enum CodingKeys: String, CodingKey { + private enum CodingKeys: String, CodingKey { case groupName case value case fieldKey From d78bc7aa584005af3e83749e4ddb0997743ca553 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 22 Jan 2020 14:38:54 -0500 Subject: [PATCH 07/16] moving top --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 185e8d09..61b009b2 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -1149,10 +1149,10 @@ D268C711238D6699007F2C1C /* DropDown.swift */, DBC4391C2245232D001AB423 /* LabelWithInternalButton.swift */, 94C2D9822386F3E30006CF46 /* Label */, - 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */, 31BE15CA23D8924C00452370 /* CheckboxModel.swift */, - 0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */, + 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */, 31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */, + 0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */, 01004F2F22721C3800991ECC /* RadioButton.swift */, D28A838223CCBD3F00DFE4FC /* CircleProgressModel.swift */, 943784F3236B77BB006A1E82 /* GraphView.swift */, From 61edfcc747751ab9bd8811dd214f7b437a0759b7 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 22 Jan 2020 14:51:17 -0500 Subject: [PATCH 08/16] fixes --- MVMCoreUI/Atoms/Views/Checkbox.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index 6b125e82..07628416 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -477,8 +477,8 @@ import MVMCore self.isRequired = isRequired } - if let borderColorHex = checkboxModel.borderColor { - layer.borderColor = borderColorHex.uiColor.cgColor + if let borderColor = checkboxModel.borderColor { + layer.borderColor = borderColor.cgColor } if let borderWidth = checkboxModel.borderWidth { @@ -495,12 +495,12 @@ import MVMCore checkColor = uiCheckColor } - if let unCheckedBackgroundColorHex = checkboxModel.unCheckedBackgroundColor { - unCheckedBackgroundColor = unCheckedBackgroundColorHex.uiColor + if let unCheckedBackgroundColor = checkboxModel.unCheckedBackgroundColor { + self.unCheckedBackgroundColor = unCheckedBackgroundColor.uiColor } - if let checkedBackgroundColorHex = checkboxModel.checkedBackgroundColor { - checkedBackgroundColor = checkedBackgroundColorHex.uiColor + if let checkedBackgroundColor = checkboxModel.checkedBackgroundColor { + self.checkedBackgroundColor = checkedBackgroundColor.uiColor } if let isAnimated = checkboxModel.isAnimated { From 50f573688fc7e9f64203fafe63f7638d8e6bffb4 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 22 Jan 2020 15:15:13 -0500 Subject: [PATCH 09/16] position --- MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift | 10 ++++++++-- MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift | 10 ++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift b/MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift index 088f7d9e..79d2ecb3 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift @@ -8,11 +8,17 @@ import Foundation +public enum CheckboxPosition: String, Codable { + case center + case top + case bottom +} + @objcMembers public class CheckboxLabelModel: MoleculeModelProtocol { public static var identifier: String = "checkboxLabel" public var backgroundColor: Color? - public var checkboxAlignment: String? + public var checkboxAlignment: CheckboxPosition? public var checkbox: CheckboxModel public var label: LabelModel @@ -24,7 +30,7 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.checkboxAlignment = try typeContainer.decodeIfPresent(String.self, forKey: .checkboxAlignment) + self.checkboxAlignment = try typeContainer.decodeIfPresent(CheckboxPosition.self, forKey: .checkboxAlignment) self.checkbox = try typeContainer.decode(CheckboxModel.self, forKey: .checkbox) self.label = try typeContainer.decode(LabelModel.self, forKey: .label) } diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift index 69141210..1e0c5590 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift @@ -21,12 +21,6 @@ public var checkboxPosition: CheckboxPosition = .center - public enum CheckboxPosition: String { - case center - case top - case bottom - } - //-------------------------------------------------- // MARK: - Constraints //-------------------------------------------------- @@ -126,8 +120,8 @@ return } - if let checkboxAlignment = checkBoxWithLabelModel.checkboxAlignment, let position = CheckboxPosition(rawValue: checkboxAlignment) { - alignCheckbox(position) + if let checkboxAlignment = checkBoxWithLabelModel.checkboxAlignment { + alignCheckbox(checkboxAlignment) } checkbox.setWithModel(checkBoxWithLabelModel.checkbox, delegateObject, additionalData) From 7c70b0a4a10813fd4e9ed1035935120118cf98c5 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 22 Jan 2020 15:32:31 -0500 Subject: [PATCH 10/16] remove methods --- .../Atoms/Views/CheckboxLabelModel.swift | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift b/MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift index 79d2ecb3..d7ceae36 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift @@ -9,6 +9,7 @@ import Foundation public enum CheckboxPosition: String, Codable { + case left case center case top case bottom @@ -21,24 +22,4 @@ public enum CheckboxPosition: String, Codable { public var checkboxAlignment: CheckboxPosition? public var checkbox: CheckboxModel public var label: LabelModel - - enum CodingKeys: String, CodingKey { - case checkboxAlignment - case checkbox - case label - } - - required public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.checkboxAlignment = try typeContainer.decodeIfPresent(CheckboxPosition.self, forKey: .checkboxAlignment) - self.checkbox = try typeContainer.decode(CheckboxModel.self, forKey: .checkbox) - self.label = try typeContainer.decode(LabelModel.self, forKey: .label) - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(checkboxAlignment, forKey: .checkboxAlignment) - try container.encode(checkbox, forKey: .checkbox) - try container.encode(label, forKey: .label) - } } From 9e7df20877031e81e49aa8558a1a180786b431c9 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 22 Jan 2020 15:37:37 -0500 Subject: [PATCH 11/16] left --- MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift index 1e0c5590..fadf3687 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift @@ -112,6 +112,8 @@ checkboxBottomConstraint?.isActive = true checkboxTopConstraint?.isActive = false checkboxCenterYConstraint?.isActive = false + case .left: break + } } From 822180ec9f8e9247d0843f0777e1bd333ddfcd7e Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 22 Jan 2020 16:09:36 -0500 Subject: [PATCH 12/16] code fixes --- MVMCoreUI/Atoms/Views/Checkbox.swift | 4 ++-- MVMCoreUI/Atoms/Views/CheckboxModel.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index 07628416..af039435 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -478,11 +478,11 @@ import MVMCore } if let borderColor = checkboxModel.borderColor { - layer.borderColor = borderColor.cgColor + self.borderColor = borderColor.uiColor } if let borderWidth = checkboxModel.borderWidth { - layer.borderWidth = borderWidth + self.borderWidth = borderWidth } if checkboxModel.isChecked { diff --git a/MVMCoreUI/Atoms/Views/CheckboxModel.swift b/MVMCoreUI/Atoms/Views/CheckboxModel.swift index 6bf9ae1a..9be83e91 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxModel.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxModel.swift @@ -71,7 +71,7 @@ import Foundation try container.encodeIfPresent(required, forKey: .required) try container.encodeIfPresent(borderColor, forKey: .borderColor) try container.encodeIfPresent(borderColor, forKey: .borderColor) - try container.encodeIfPresent(isChecked, forKey: .isChecked) + try container.encode(isChecked, forKey: .isChecked) try container.encodeIfPresent(checkColor, forKey: .checkColor) try container.encodeIfPresent(unCheckedBackgroundColor, forKey: .unCheckedBackgroundColor) try container.encodeIfPresent(checkedBackgroundColor, forKey: .checkedBackgroundColor) From 611246cb14adb3573aa5cac4c878bc8021da171b Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 22 Jan 2020 17:14:08 -0500 Subject: [PATCH 13/16] remove left --- MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift | 1 - MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift | 1 - 2 files changed, 2 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift b/MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift index d7ceae36..5a9d09f0 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxLabelModel.swift @@ -9,7 +9,6 @@ import Foundation public enum CheckboxPosition: String, Codable { - case left case center case top case bottom diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift index fadf3687..e559069d 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift @@ -112,7 +112,6 @@ checkboxBottomConstraint?.isActive = true checkboxTopConstraint?.isActive = false checkboxCenterYConstraint?.isActive = false - case .left: break } } From 4cc5a15db96c48476867a76901e3ff6ceb343bb0 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 23 Jan 2020 12:12:45 -0500 Subject: [PATCH 14/16] checkbox modeling. Strange issue with EntryFieldContainer. To be observed. --- MVMCoreUI.xcodeproj/project.pbxproj | 8 +- MVMCoreUI/Atoms/Views/Checkbox.swift | 128 +++----- MVMCoreUI/Atoms/Views/CheckboxModel.swift | 48 +-- .../views/EntryFieldContainer.swift | 285 ------------------ 4 files changed, 76 insertions(+), 393 deletions(-) delete mode 100644 MVMCoreUI/Containers/views/EntryFieldContainer.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 61b009b2..f36a6094 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -84,9 +84,9 @@ 0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */; }; 0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */; }; 0AA33B3A2398524F0067DD0F /* Toggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AA33B392398524F0067DD0F /* Toggle.swift */; }; - 0ABD136B237B193A0081388D /* EntryFieldContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD136A237B193A0081388D /* EntryFieldContainer.swift */; }; 0ABD136D237CAD1E0081388D /* DateDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */; }; 0ABD1371237DB0450081388D /* ItemDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */; }; + 0ACDF26B23DA0AC2002044B2 /* EntryFieldContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ACDF26A23DA0AC2002044B2 /* EntryFieldContainer.swift */; }; 0AE14F64238315D2005417F8 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE14F63238315D2005417F8 /* TextField.swift */; }; 31BE15CB23D8924D00452370 /* CheckboxLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */; }; 31BE15CC23D8924D00452370 /* CheckboxModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15CA23D8924C00452370 /* CheckboxModel.swift */; }; @@ -381,9 +381,9 @@ 0A8321AE2355FE9500CB7F00 /* DigitBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DigitBox.swift; sourceTree = ""; }; 0AA33B33239813C50067DD0F /* UIColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extension.swift"; sourceTree = ""; }; 0AA33B392398524F0067DD0F /* Toggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toggle.swift; sourceTree = ""; }; - 0ABD136A237B193A0081388D /* EntryFieldContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntryFieldContainer.swift; sourceTree = ""; }; 0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateDropdownEntryField.swift; sourceTree = ""; }; 0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemDropdownEntryField.swift; sourceTree = ""; }; + 0ACDF26A23DA0AC2002044B2 /* EntryFieldContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EntryFieldContainer.swift; sourceTree = ""; }; 0AE14F63238315D2005417F8 /* TextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = ""; }; 31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxLabelModel.swift; sourceTree = ""; }; 31BE15CA23D8924C00452370 /* CheckboxModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxModel.swift; sourceTree = ""; }; @@ -691,7 +691,7 @@ isa = PBXGroup; children = ( D29E28DE23D740FC00ACEA85 /* Container */, - 0ABD136A237B193A0081388D /* EntryFieldContainer.swift */, + 0ACDF26A23DA0AC2002044B2 /* EntryFieldContainer.swift */, 014AA72123C501E2006F3E93 /* MoleculeContainerModel.swift */, D2FB151A23A2B65B00C20E10 /* MoleculeContainer.swift */, ); @@ -1603,6 +1603,7 @@ 017BEB7F23676E870024EF95 /* MoleculeObjectMapping.swift in Sources */, D274CA332236A78900B01B62 /* FooterView.swift in Sources */, D29DF2BF21E7BEA4003B2FB9 /* MVMCoreUITabBarPageControlViewController.m in Sources */, + 0ACDF26B23DA0AC2002044B2 /* EntryFieldContainer.swift in Sources */, 014AA72423C501E2006F3E93 /* MoleculeContainerModel.swift in Sources */, D29DF28321E7AB24003B2FB9 /* MVMCoreUICommonViewsUtility.m in Sources */, 011B58F223A2AE2C0085F53C /* DropDownListItemModel.swift in Sources */, @@ -1684,7 +1685,6 @@ D2B18B922361E65A00A9AEDC /* CoreUIObject.swift in Sources */, D29DF2BE21E7BEA4003B2FB9 /* TopTabbar.m in Sources */, 014AA72E23C5059B006F3E93 /* StackCenteredPageTemplateModel.swift in Sources */, - 0ABD136B237B193A0081388D /* EntryFieldContainer.swift in Sources */, D2A514632213643100345BFB /* MoleculeStackCenteredTemplate.swift in Sources */, D260105923D0A92900764D80 /* ContainerProtocol.swift in Sources */, C695A69423C9909000BFB94E /* DoughnutChartModel.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index af039435..a5820271 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -76,6 +76,24 @@ import MVMCore } } + open override var isEnabled: Bool { + didSet { + + isUserInteractionEnabled = isEnabled + + if isEnabled { + layer.borderColor = borderColor.cgColor + backgroundColor = isSelected ? checkedBackgroundColor : unCheckedBackgroundColor + setShapeLayerStrokeColor(checkColor) + } else { + layer.borderColor = UIColor.mfSilver().cgColor + backgroundColor = .clear + setShapeLayerStrokeColor(UIColor.mfSilver()) + } + } + } + // public var disabledColor: (check: UIColor?, background: UIColor?, border: UIColor?) + /// Color of the check mark. public var checkColor: UIColor = .black { didSet { @@ -107,7 +125,6 @@ import MVMCore if !updateSelectionOnly { layoutIfNeeded() shapeLayer?.removeAllAnimations() - updateCheckboxUI(isSelected: isSelected, isAnimated: isAnimated) FormValidator.enableByValidationWith(delegate: delegateObject?.formValidationProtocol) updateAccessibilityLabel() @@ -154,16 +171,12 @@ import MVMCore public convenience init(isChecked: Bool) { self.init(frame: .zero) - updateSelectionOnly = true - isSelected = isChecked - updateSelectionOnly = false + checkAndBypassAnimations(selected: isChecked) } public convenience init(checkedBackgroundColor: UIColor, unCheckedBackgroundColor: UIColor, isChecked: Bool = false) { self.init(frame: .zero) - updateSelectionOnly = true - isSelected = isChecked - updateSelectionOnly = false + checkAndBypassAnimations(selected: isChecked) self.checkedBackgroundColor = checkedBackgroundColor self.unCheckedBackgroundColor = unCheckedBackgroundColor } @@ -177,8 +190,6 @@ import MVMCore drawShapeLayer() layer.cornerRadius = isRound ? cornerRadiusValue : 0 - layer.borderWidth = borderWidth - layer.borderColor = borderColor.cgColor } open override func setupView() { @@ -268,9 +279,7 @@ import MVMCore DispatchQueue.main.async { - self.updateSelectionOnly = true - self.isSelected = selected - self.updateSelectionOnly = false + self.checkAndBypassAnimations(selected: selected) self.drawShapeLayer() self.shapeLayer?.removeAllAnimations() self.updateCheckboxUI(isSelected: selected, isAnimated: animated) @@ -313,23 +322,6 @@ import MVMCore } } - func isEnabled(_ enabled: Bool) { - - isUserInteractionEnabled = enabled - - if enabled { - layer.borderColor = borderColor.cgColor - backgroundColor = isSelected ? checkedBackgroundColor : unCheckedBackgroundColor - alpha = 1.0 - setShapeLayerStrokeColor(checkColor) - } else { - layer.borderColor = UIColor.mfSilver().cgColor - backgroundColor = .clear - alpha = DisableOppacity - setShapeLayerStrokeColor(UIColor.mfSilver()) - } - } - private func setShapeLayerStrokeColor(_ color: UIColor) { if let shapeLayer = shapeLayer { @@ -345,13 +337,19 @@ import MVMCore widthConstraint?.isActive = isActive } + private func checkAndBypassAnimations(selected: Bool) { + updateSelectionOnly = true + isSelected = selected + updateSelectionOnly = false + } + //-------------------------------------------------- // MARK: - UITouch //-------------------------------------------------- open override func touchesEnded(_ touches: Set, with event: UIEvent?) { - sendActions(for: .touchUpInside) + sendActions(for: .touchUpInside) } override open func accessibilityActivate() -> Bool { @@ -370,7 +368,7 @@ import MVMCore open override func reset() { super.reset() - isEnabled(true) + isEnabled = true shapeLayer?.removeAllAnimations() shapeLayer?.removeFromSuperlayer() shapeLayer = nil @@ -379,9 +377,7 @@ import MVMCore borderWidth = 1.0 checkColor = .black checkWidth = 2.0 - updateSelectionOnly = true - isSelected = false - updateSelectionOnly = false + checkAndBypassAnimations(selected: false) } open func setAsMolecule() { @@ -425,9 +421,7 @@ import MVMCore } if let isChecked = dictionary["isChecked"] as? Bool, isChecked { - updateSelectionOnly = true - isSelected = isChecked - updateSelectionOnly = false + checkAndBypassAnimations(selected: isChecked) } if let checkColorHex = dictionary["checkColor"] as? String { @@ -451,7 +445,7 @@ import MVMCore } if let enabled = dictionary["isEnabled"] as? Bool { - isEnabled(enabled) + isEnabled = enabled } if let actionMap = dictionary.optionalDictionaryForKey("action") { @@ -459,61 +453,35 @@ import MVMCore } } - public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) - guard let checkboxModel = model as? CheckboxModel else { - return - } + + guard let checkboxModel = model as? CheckboxModel else { return } + self.delegateObject = delegateObject FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol) - + groupName = checkboxModel.groupName fieldValue = checkboxModel.value + isRequired = checkboxModel.required + if let fieldKey = checkboxModel.fieldKey { self.fieldKey = fieldKey } - if let isRequired = checkboxModel.required { - self.isRequired = isRequired - } - - if let borderColor = checkboxModel.borderColor { - self.borderColor = borderColor.uiColor - } - - if let borderWidth = checkboxModel.borderWidth { - self.borderWidth = borderWidth - } + borderColor = checkboxModel.borderColor.uiColor + borderWidth = checkboxModel.borderWidth if checkboxModel.isChecked { - updateSelectionOnly = true - isSelected = checkboxModel.isChecked - updateSelectionOnly = false + checkAndBypassAnimations(selected: checkboxModel.isChecked) } - if let uiCheckColor = checkboxModel.checkColor?.uiColor { - checkColor = uiCheckColor - } - - if let unCheckedBackgroundColor = checkboxModel.unCheckedBackgroundColor { - self.unCheckedBackgroundColor = unCheckedBackgroundColor.uiColor - } - - if let checkedBackgroundColor = checkboxModel.checkedBackgroundColor { - self.checkedBackgroundColor = checkedBackgroundColor.uiColor - } - - if let isAnimated = checkboxModel.isAnimated { - self.isAnimated = isAnimated - } - - if let isRound = checkboxModel.isRound { - self.isRound = isRound - } - - if let enabled = checkboxModel.isEnabled { - isEnabled(enabled) - } + checkColor = checkboxModel.checkColor.uiColor + unCheckedBackgroundColor = checkboxModel.unCheckedBackgroundColor.uiColor + checkedBackgroundColor = checkboxModel.checkedBackgroundColor.uiColor + isAnimated = checkboxModel.isAnimated + isRound = checkboxModel.isRound + isEnabled = checkboxModel.isEnabled if let action = checkboxModel.action { actionBlock = { diff --git a/MVMCoreUI/Atoms/Views/CheckboxModel.swift b/MVMCoreUI/Atoms/Views/CheckboxModel.swift index 9be83e91..91a14a90 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxModel.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxModel.swift @@ -15,16 +15,16 @@ import Foundation public var groupName: String? public var value: String? public var fieldKey: String? - public var required: Bool? - public var borderColor: Color? - public var borderWidth: CGFloat? + public var required: Bool + public var borderColor: Color + public var borderWidth: CGFloat = 1 public var isChecked: Bool = false - public var checkColor: Color? - public var unCheckedBackgroundColor: Color? - public var checkedBackgroundColor: Color? - public var isAnimated: Bool? - public var isRound: Bool? - public var isEnabled: Bool? + public var checkColor: Color + public var unCheckedBackgroundColor: Color + public var checkedBackgroundColor: Color + public var isAnimated: Bool = true + public var isRound: Bool = false + public var isEnabled: Bool = true public var action: ActionModelProtocol? @@ -47,20 +47,20 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) - self.value = try typeContainer.decodeIfPresent(String.self, forKey: .value) - self.fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey) - self.required = try typeContainer.decodeIfPresent(Bool.self, forKey: .required) - self.borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) - self.borderWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .borderWidth) - self.isChecked = try typeContainer.decodeIfPresent(Bool.self, forKey: .isChecked) ?? false - self.checkColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkColor) - self.unCheckedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .unCheckedBackgroundColor) - self.checkedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkedBackgroundColor) - self.isAnimated = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAnimated) - self.isRound = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRound) - self.isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .isEnabled) - self.action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.actionType) + groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) + value = try typeContainer.decodeIfPresent(String.self, forKey: .value) + fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey) + required = try typeContainer.decodeIfPresent(Bool.self, forKey: .required) ?? false + borderWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .borderWidth) ?? 1 + borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) ?? Color(uiColor: .black) + checkColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkColor) ?? Color(uiColor: .black) + unCheckedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .unCheckedBackgroundColor) ?? Color(uiColor: .clear) + checkedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkedBackgroundColor) ?? Color(uiColor: .clear) + isChecked = try typeContainer.decodeIfPresent(Bool.self, forKey: .isChecked) ?? false + isAnimated = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAnimated) ?? true + isRound = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRound) ?? false + isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .isEnabled) ?? true + action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.actionType) } public func encode(to encoder: Encoder) throws { @@ -70,7 +70,7 @@ import Foundation try container.encodeIfPresent(fieldKey, forKey: .fieldKey) try container.encodeIfPresent(required, forKey: .required) try container.encodeIfPresent(borderColor, forKey: .borderColor) - try container.encodeIfPresent(borderColor, forKey: .borderColor) + try container.encode(borderWidth, forKey: .borderWidth) try container.encode(isChecked, forKey: .isChecked) try container.encodeIfPresent(checkColor, forKey: .checkColor) try container.encodeIfPresent(unCheckedBackgroundColor, forKey: .unCheckedBackgroundColor) diff --git a/MVMCoreUI/Containers/views/EntryFieldContainer.swift b/MVMCoreUI/Containers/views/EntryFieldContainer.swift deleted file mode 100644 index 96a51a8f..00000000 --- a/MVMCoreUI/Containers/views/EntryFieldContainer.swift +++ /dev/null @@ -1,285 +0,0 @@ -// -// EntryFieldContainer.swift -// MVMCoreUI -// -// Created by Kevin Christiano on 11/12/19. -// Copyright © 2019 Verizon Wireless. All rights reserved. -// - -import UIKit - - -@objcMembers open class EntryFieldContainer: View { - //-------------------------------------------------- - // MARK: - Drawing Properties - //-------------------------------------------------- - - /// The bottom border line. Height is dynamic based on scenario. - public var bottomBar: CAShapeLayer? = { - let layer = CAShapeLayer() - layer.backgroundColor = UIColor.black.cgColor - layer.drawsAsynchronously = true - layer.anchorPoint = CGPoint(x: 0.5, y: 1.0); - return layer - }() - - /// Total control over the drawn top, bottom, left and right borders. - public var disableAllBorders = false { - didSet { - bottomBar?.isHidden = disableAllBorders - } - } - - private(set) var fieldState: FieldState = .original { - didSet (oldState) { - // Will not update if new state is the same as old. - if fieldState != oldState { - DispatchQueue.main.async { [weak self] in - guard let self = self else { return } - - self.fieldState.setStateUI(for: self) - } - } - } - } - - /// Determines if the top, left, and right borders should be drawn. - private var hideBorders = false - - public var borderStrokeColor: UIColor = .mfSilver() - private var borderPath: UIBezierPath = UIBezierPath() - - //-------------------------------------------------- - // MARK: - Property Observers - //-------------------------------------------------- - - private var _isEnabled: Bool = true - private var _showError: Bool = false - private var _isLocked: Bool = false - private var _isSelected: Bool = false - - public var isEnabled: Bool { - get { return _isEnabled } - set (enabled) { - - _isEnabled = enabled - _isLocked = false - _isSelected = false - _showError = false - - fieldState = enabled ? .original : .disabled - } - } - - public var showError: Bool { - get { return _showError } - set (error) { - - _showError = error - _isEnabled = true - _isLocked = false - _isSelected = false - - fieldState = error ? .error : .original - } - } - - public var isLocked: Bool { - get { return _isLocked } - set (locked) { - - _isLocked = locked - _isEnabled = true - _isSelected = false - _showError = false - - fieldState = locked ? .locked : .original - } - } - - public var isSelected: Bool { - get { return _isSelected } - set (selected) { - - _isSelected = selected - _isLocked = false - _isEnabled = true - - if _showError { - fieldState = selected ? .selectedError : .error - } else { - fieldState = selected ? .selected : .original - } - } - } - - //-------------------------------------------------- - // MARK: - Delegate - //-------------------------------------------------- - - /// Holds reference to delegateObject to inform molecular tableView of an update. - weak var delegateObject: MVMCoreUIDelegateObject? - - //-------------------------------------------------- - // MARK: - Lifecycle - //-------------------------------------------------- - - open override func layoutSubviews() { - super.layoutSubviews() - - refreshUI(bottomBarSize: showError ? 4 : 1) - } - - open override func updateView(_ size: CGFloat) { - super.updateView(size) - - refreshUI() - } - - /// This handles the top, left, and right border lines. - open override func draw(_ rect: CGRect) { - super.draw(rect) - - borderPath.removeAllPoints() - - if !disableAllBorders && !hideBorders { - // Brings the other half of the line inside the view to prevent cropping. - let origin = bounds.origin - let size = frame.size - let insetLean: CGFloat = 0.5 - borderPath.lineWidth = 1 - - borderPath.move(to: CGPoint(x: origin.x + insetLean, y: origin.y + size.height)) - borderPath.addLine(to: CGPoint(x: origin.x + insetLean, y: origin.y + insetLean)) - borderPath.addLine(to: CGPoint(x: origin.x + size.width - insetLean, y: origin.y + insetLean)) - borderPath.addLine(to: CGPoint(x: origin.x + size.width - insetLean, y: origin.y + size.height)) - - borderStrokeColor.setStroke() - borderPath.stroke() - } - } - - override open func setupView() { - super.setupView() - - isAccessibilityElement = false - isOpaque = false - - if let bottomBar = bottomBar { - layer.addSublayer(bottomBar) - } - } - - //-------------------------------------------------- - // MARK: - Draw States - //-------------------------------------------------- - - public enum FieldState { - case original - case error - case selectedError - case selected - case locked - case disabled - - public func setStateUI(for formField: EntryFieldContainer) { - - switch self { - case .original: - formField.originalUI() - - case .error: - formField.errorUI() - - case .selectedError: - formField.selectedErrorUI() - - case .selected: - formField.selectedUI() - - case .locked: - formField.lockedUI() - - case .disabled: - formField.disabledUI() - } - } - } - - open func originalUI() { - - isUserInteractionEnabled = true - hideBorders = false - borderStrokeColor = .mfSilver() - bottomBar?.backgroundColor = UIColor.black.cgColor - refreshUI(bottomBarSize: 1) - } - - open func errorUI() { - - isUserInteractionEnabled = true - hideBorders = false - borderStrokeColor = .mfPumpkin() - bottomBar?.backgroundColor = UIColor.mfPumpkin().cgColor - refreshUI(bottomBarSize: 4) - } - - open func selectedErrorUI() { - - isUserInteractionEnabled = true - hideBorders = false - borderStrokeColor = .black - bottomBar?.backgroundColor = UIColor.mfPumpkin().cgColor - refreshUI(bottomBarSize: 4) - } - - open func selectedUI() { - - isUserInteractionEnabled = true - hideBorders = false - borderStrokeColor = .black - bottomBar?.backgroundColor = UIColor.black.cgColor - refreshUI(bottomBarSize: 1) - } - - open func lockedUI() { - - isUserInteractionEnabled = false - hideBorders = true - borderStrokeColor = .clear - bottomBar?.backgroundColor = UIColor.clear.cgColor - refreshUI(bottomBarSize: 1) - } - - open func disabledUI() { - - isUserInteractionEnabled = false - hideBorders = false - borderStrokeColor = .mfSilver() - bottomBar?.backgroundColor = UIColor.mfSilver().cgColor - refreshUI(bottomBarSize: 1) - } - - open func refreshUI(bottomBarSize: CGFloat? = nil) { - - if !disableAllBorders { - let size: CGFloat = bottomBarSize ?? (showError ? 4 : 1) - bottomBar?.frame = CGRect(x: 0, y: bounds.height - size, width: bounds.width, height: size) - - delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self) - setNeedsDisplay() - layoutIfNeeded() - } - } -} - -// MARK:- MVMCoreUIMoleculeViewProtocol -extension EntryFieldContainer { - - override open func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - self.delegateObject = delegateObject - - guard let dictionary = json, !dictionary.isEmpty else { return } - } -} From 2100468899550ab04fa08fc86cfb9abf6389f8a7 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 23 Jan 2020 12:32:33 -0500 Subject: [PATCH 15/16] disabled colors --- MVMCoreUI/Atoms/Views/Checkbox.swift | 8 ++++--- MVMCoreUI/Atoms/Views/CheckboxModel.swift | 24 +++++++++++++++---- .../Atoms/Views/CheckboxWithLabelView.swift | 7 ++---- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index a5820271..796496c8 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -86,13 +86,15 @@ import MVMCore backgroundColor = isSelected ? checkedBackgroundColor : unCheckedBackgroundColor setShapeLayerStrokeColor(checkColor) } else { - layer.borderColor = UIColor.mfSilver().cgColor - backgroundColor = .clear + layer.borderColor = disabledBorderColor.cgColor + backgroundColor = disabledBackgroundColor setShapeLayerStrokeColor(UIColor.mfSilver()) } } } - // public var disabledColor: (check: UIColor?, background: UIColor?, border: UIColor?) + + public var disabledBackgroundColor: UIColor = .clear + public var disabledBorderColor: UIColor = .mvmCoolGray3 /// Color of the check mark. public var checkColor: UIColor = .black { diff --git a/MVMCoreUI/Atoms/Views/CheckboxModel.swift b/MVMCoreUI/Atoms/Views/CheckboxModel.swift index 91a14a90..6ff55696 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxModel.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxModel.swift @@ -9,24 +9,34 @@ import Foundation @objcMembers public class CheckboxModel: MoleculeModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "checkbox" public var backgroundColor: Color? public var groupName: String? public var value: String? public var fieldKey: String? - public var required: Bool - public var borderColor: Color + public var required: Bool = false + public var borderColor: Color = Color(uiColor: .black) public var borderWidth: CGFloat = 1 public var isChecked: Bool = false - public var checkColor: Color - public var unCheckedBackgroundColor: Color - public var checkedBackgroundColor: Color + public var checkColor: Color = Color(uiColor: .black) + public var unCheckedBackgroundColor: Color = Color(uiColor: .clear) + public var checkedBackgroundColor: Color = Color(uiColor: .clear) public var isAnimated: Bool = true public var isRound: Bool = false public var isEnabled: Bool = true public var action: ActionModelProtocol? + + public var disabledBackgroundColor: Color = Color(uiColor: .black) + public var disabledBorderColor: Color = Color(uiColor: .black) + //-------------------------------------------------- + // MARK: - Keys + //-------------------------------------------------- private enum CodingKeys: String, CodingKey { case groupName @@ -45,6 +55,10 @@ import Foundation case action } + //-------------------------------------------------- + // MARK: - Codec + //-------------------------------------------------- + required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift index e559069d..bc23db73 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift @@ -112,14 +112,11 @@ checkboxBottomConstraint?.isActive = true checkboxTopConstraint?.isActive = false checkboxCenterYConstraint?.isActive = false - } } - open override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { - guard let checkBoxWithLabelModel = model as? CheckboxLabelModel else { - return - } + open override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + guard let checkBoxWithLabelModel = model as? CheckboxLabelModel else { return } if let checkboxAlignment = checkBoxWithLabelModel.checkboxAlignment { alignCheckbox(checkboxAlignment) From ea40da2c90a66284292671a2ad8771669654c5ce Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 23 Jan 2020 12:55:21 -0500 Subject: [PATCH 16/16] diabled functionality --- MVMCoreUI/Atoms/Views/Checkbox.swift | 50 +++++++++++++---------- MVMCoreUI/Atoms/Views/CheckboxModel.swift | 15 +++++-- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index 796496c8..27bed31e 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -88,13 +88,14 @@ import MVMCore } else { layer.borderColor = disabledBorderColor.cgColor backgroundColor = disabledBackgroundColor - setShapeLayerStrokeColor(UIColor.mfSilver()) + setShapeLayerStrokeColor(disabledCheckColor) } } } public var disabledBackgroundColor: UIColor = .clear public var disabledBorderColor: UIColor = .mvmCoolGray3 + public var disabledCheckColor: UIColor = .mvmCoolGray3 /// Color of the check mark. public var checkColor: UIColor = .black { @@ -241,7 +242,7 @@ import MVMCore self.shapeLayer = shapeLayer shapeLayer.frame = bounds layer.addSublayer(shapeLayer) - shapeLayer.strokeColor = checkColor.cgColor + shapeLayer.strokeColor = isEnabled ? checkColor.cgColor : disabledCheckColor.cgColor shapeLayer.fillColor = UIColor.clear.cgColor shapeLayer.path = checkMarkPath() shapeLayer.lineJoin = .miter @@ -422,14 +423,14 @@ import MVMCore layer.borderWidth = borderWidth } - if let isChecked = dictionary["isChecked"] as? Bool, isChecked { - checkAndBypassAnimations(selected: isChecked) - } - if let checkColorHex = dictionary["checkColor"] as? String { checkColor = UIColor.mfGet(forHex: checkColorHex) } + if let isChecked = dictionary["isChecked"] as? Bool, isChecked { + checkAndBypassAnimations(selected: isChecked) + } + if let unCheckedBackgroundColorHex = dictionary["unCheckedBackgroundColor"] as? String { unCheckedBackgroundColor = UIColor.mfGet(forHex: unCheckedBackgroundColorHex) } @@ -458,34 +459,39 @@ import MVMCore public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) - guard let checkboxModel = model as? CheckboxModel else { return } + guard let model = model as? CheckboxModel else { return } self.delegateObject = delegateObject FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol) - groupName = checkboxModel.groupName - fieldValue = checkboxModel.value - isRequired = checkboxModel.required + groupName = model.groupName + fieldValue = model.value + isRequired = model.required - if let fieldKey = checkboxModel.fieldKey { + if let fieldKey = model.fieldKey { self.fieldKey = fieldKey } - borderColor = checkboxModel.borderColor.uiColor - borderWidth = checkboxModel.borderWidth + borderColor = model.borderColor.uiColor + borderWidth = model.borderWidth - if checkboxModel.isChecked { - checkAndBypassAnimations(selected: checkboxModel.isChecked) + checkColor = model.checkColor.uiColor + unCheckedBackgroundColor = model.unCheckedBackgroundColor.uiColor + checkedBackgroundColor = model.checkedBackgroundColor.uiColor + disabledCheckColor = model.disabledCheckColor.uiColor + disabledBorderColor = model.disabledBorderColor.uiColor + disabledBackgroundColor = model.disabledBackgroundColor.uiColor + + isAnimated = model.isAnimated + isRound = model.isRound + + if model.isChecked { + checkAndBypassAnimations(selected: model.isChecked) } - checkColor = checkboxModel.checkColor.uiColor - unCheckedBackgroundColor = checkboxModel.unCheckedBackgroundColor.uiColor - checkedBackgroundColor = checkboxModel.checkedBackgroundColor.uiColor - isAnimated = checkboxModel.isAnimated - isRound = checkboxModel.isRound - isEnabled = checkboxModel.isEnabled + isEnabled = model.isEnabled - if let action = checkboxModel.action { + if let action = model.action { actionBlock = { if let actionMap = action.toJSON() { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) diff --git a/MVMCoreUI/Atoms/Views/CheckboxModel.swift b/MVMCoreUI/Atoms/Views/CheckboxModel.swift index 6ff55696..aa5dedb4 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxModel.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxModel.swift @@ -30,10 +30,10 @@ import Foundation public var isRound: Bool = false public var isEnabled: Bool = true public var action: ActionModelProtocol? + public var disabledBackgroundColor: Color = Color(uiColor: .clear) + public var disabledBorderColor: Color = Color(uiColor: .mvmCoolGray3) + public var disabledCheckColor: Color = Color(uiColor: .mvmCoolGray3) - public var disabledBackgroundColor: Color = Color(uiColor: .black) - public var disabledBorderColor: Color = Color(uiColor: .black) - //-------------------------------------------------- // MARK: - Keys //-------------------------------------------------- @@ -49,6 +49,9 @@ import Foundation case checkColor case unCheckedBackgroundColor case checkedBackgroundColor + case disabledBackgroundColor + case disabledCheckColor + case disabledBorderColor case isAnimated case isRound case isEnabled @@ -70,6 +73,9 @@ import Foundation checkColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkColor) ?? Color(uiColor: .black) unCheckedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .unCheckedBackgroundColor) ?? Color(uiColor: .clear) checkedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkedBackgroundColor) ?? Color(uiColor: .clear) + disabledBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledBackgroundColor) ?? Color(uiColor: .clear) + disabledBorderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledBorderColor) ?? Color(uiColor: .mvmCoolGray3) + disabledCheckColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledCheckColor) ?? Color(uiColor: .mvmCoolGray3) isChecked = try typeContainer.decodeIfPresent(Bool.self, forKey: .isChecked) ?? false isAnimated = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAnimated) ?? true isRound = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRound) ?? false @@ -89,6 +95,9 @@ import Foundation try container.encodeIfPresent(checkColor, forKey: .checkColor) try container.encodeIfPresent(unCheckedBackgroundColor, forKey: .unCheckedBackgroundColor) try container.encodeIfPresent(checkedBackgroundColor, forKey: .checkedBackgroundColor) + try container.encodeIfPresent(disabledBorderColor, forKey: .disabledBorderColor) + try container.encodeIfPresent(disabledBackgroundColor, forKey: .disabledBackgroundColor) + try container.encodeIfPresent(disabledCheckColor, forKey: .disabledCheckColor) try container.encodeIfPresent(isAnimated, forKey: .isAnimated) try container.encodeIfPresent(isRound, forKey: .isRound) try container.encodeIfPresent(isEnabled, forKey: .isEnabled)