From 34256698c07e1c75e212b6581adad44e616e6e84 Mon Sep 17 00:00:00 2001 From: Damodaram Date: Tue, 15 Sep 2020 16:39:41 +0530 Subject: [PATCH 01/11] added action support for selectors --- .../Atomic/Atoms/Selectors/Checkbox.swift | 22 ++++++++++++++----- .../Atoms/Selectors/CheckboxModel.swift | 4 ++++ .../Atomic/Atoms/Selectors/RadioBox.swift | 8 ++++++- .../Atoms/Selectors/RadioBoxModel.swift | 4 ++++ .../Atomic/Atoms/Selectors/RadioSwatch.swift | 8 ++++++- .../Atoms/Selectors/RadioSwatchModel.swift | 4 ++++ 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift index f23fd337..fc6607b1 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift @@ -381,7 +381,7 @@ import MVMCore checkWidth = 2 checkAndBypassAnimations(selected: false) } - + public override func updateView(_ size: CGFloat) { super.updateView(size) @@ -391,6 +391,12 @@ import MVMCore } } + private func performCheckboxAction(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + if let actionMap = actionModel.toJSON() { + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + } + } + public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) self.delegateObject = delegateObject @@ -422,10 +428,16 @@ import MVMCore isEnabled = model.enabled - if let action = model.action { - actionBlock = { - if let actionMap = action.toJSON() { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + if (model.action != nil || model.offAction != nil) { + actionBlock = { [weak self] in + guard let self = self else { return } + + if let offAction = model.offAction, !self.isSelected { + self.performCheckboxAction(with: offAction, delegateObject: delegateObject, additionalData: additionalData) + return + } + if let action = model.action { + self.performCheckboxAction(with: action, delegateObject: delegateObject, additionalData: additionalData) } } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/CheckboxModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/CheckboxModel.swift index 43a08aa6..bb21da1b 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/CheckboxModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/CheckboxModel.swift @@ -32,6 +32,7 @@ import Foundation public var invertedColor: Color = Color(uiColor: .mvmWhite) public var invertedBackgroundColor: Color = Color(uiColor: .mvmBlack) public var action: ActionModelProtocol? + public var offAction: ActionModelProtocol? public var fieldKey: String? public var groupName: String = FormValidator.defaultGroupName @@ -61,6 +62,7 @@ import Foundation case action case fieldKey case groupName + case offAction } //-------------------------------------------------- @@ -155,6 +157,7 @@ import Foundation if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) { self.groupName = groupName } + offAction = try typeContainer.decodeModelIfPresent(codingKey: .offAction) } public func encode(to encoder: Encoder) throws { @@ -179,5 +182,6 @@ import Foundation try container.encodeIfPresent(enabled, forKey: .enabled) try container.encodeModelIfPresent(action, forKey: .action) try container.encodeIfPresent(groupName, forKey: .groupName) + try container.encodeModelIfPresent(offAction, forKey: .offAction) } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift index 70c1a6ef..7b8b5703 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift @@ -8,7 +8,7 @@ import Foundation -open class RadioBox: Control { +open class RadioBox: Control, MFButtonProtocol { public let label = Label(fontStyle: .RegularBodySmall) public let subTextLabel = Label(fontStyle: .RegularMicro) public var isOutOfStock = false @@ -22,6 +22,8 @@ open class RadioBox: Control { public var subTextLabelHeightConstraint: NSLayoutConstraint? + private var delegateObject: MVMCoreUIDelegateObject? + public var radioBoxModel: RadioBoxModel? { return model as? RadioBoxModel } @@ -77,6 +79,7 @@ open class RadioBox: Control { open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) guard let model = model as? RadioBoxModel else { return } + self.delegateObject = delegateObject label.text = model.text subTextLabel.text = model.subText isOutOfStock = model.strikethrough @@ -135,6 +138,9 @@ open class RadioBox: Control { guard isEnabled else { return } isSelected = true radioBoxModel?.selected = isSelected + if let actionModel = radioBoxModel?.action { + Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: nil) + } layer.setNeedsDisplay() } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxModel.swift index 986eefac..923a65e0 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxModel.swift @@ -17,6 +17,7 @@ import Foundation public var enabled: Bool = true public var strikethrough: Bool = false public var fieldValue: String? + public var action: ActionModelProtocol? private enum CodingKeys: String, CodingKey { case moleculeName @@ -28,6 +29,7 @@ import Foundation case enabled case strikethrough case fieldValue + case action } required public init(from decoder: Decoder) throws { @@ -47,6 +49,7 @@ import Foundation } fieldValue = try typeContainer.decodeIfPresent(String.self, forKey: .fieldValue) + action = try typeContainer.decodeModelIfPresent(codingKey: .action) } public func encode(to encoder: Encoder) throws { @@ -60,5 +63,6 @@ import Foundation try container.encode(enabled, forKey: .enabled) try container.encode(strikethrough, forKey: .strikethrough) try container.encodeIfPresent(fieldValue, forKey: .fieldValue) + try container.encodeModelIfPresent(action, forKey: .action) } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift index 36dcde69..3184feb4 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift @@ -9,7 +9,7 @@ import UIKit -open class RadioSwatch: Control { +open class RadioSwatch: Control, MFButtonProtocol { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -20,6 +20,8 @@ open class RadioSwatch: Control { private var strikeLayer: CALayer? private var maskLayer: CALayer? + private var delegateObject: MVMCoreUIDelegateObject? + public var radioSwatchModel: RadioSwatchModel? { return model as? RadioSwatchModel } @@ -57,6 +59,7 @@ open class RadioSwatch: Control { open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) guard let model = model as? RadioSwatchModel else { return } + self.delegateObject = delegateObject bottomText.text = model.text isSelected = model.selected isEnabled = model.enabled @@ -117,6 +120,9 @@ open class RadioSwatch: Control { guard isEnabled else { return } isSelected = true radioSwatchModel?.selected = isSelected + if let actionModel = radioSwatchModel?.action { + Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: nil) + } layer.setNeedsDisplay() } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatchModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatchModel.swift index 3aadd467..7acb3999 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatchModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatchModel.swift @@ -17,6 +17,7 @@ import Foundation public var enabled: Bool = true public var strikethrough: Bool = false public var fieldValue: String? + public var action: ActionModelProtocol? private enum CodingKeys: String, CodingKey { case moleculeName @@ -27,6 +28,7 @@ import Foundation case enabled case strikethrough case fieldValue + case action } required public init(from decoder: Decoder) throws { @@ -46,6 +48,7 @@ import Foundation self.strikethrough = strikethrough } fieldValue = try typeContainer.decodeIfPresent(String.self, forKey: .fieldValue) + action = try typeContainer.decodeModelIfPresent(codingKey: .action) } public func encode(to encoder: Encoder) throws { @@ -58,6 +61,7 @@ import Foundation try container.encode(enabled, forKey: .enabled) try container.encode(strikethrough, forKey: .strikethrough) try container.encodeIfPresent(fieldValue, forKey: .fieldValue) + try container.encodeModelIfPresent(action, forKey: .action) } } From 483a50dd98383744650eb1fac6d202d7fb732ff0 Mon Sep 17 00:00:00 2001 From: Damodaram Date: Wed, 16 Sep 2020 15:45:56 +0530 Subject: [PATCH 02/11] tagging changes implemented --- .../TextFields/BaseDropdownEntryField.swift | 23 +++++++++++++++++++ .../BaseDropdownEntryFieldModel.swift | 4 ++++ .../TextFields/DateDropdownEntryField.swift | 1 + .../TextFields/ItemDropdownEntryField.swift | 1 + MVMCoreUI/Utility/MVMCoreUIConstants.h | 2 ++ MVMCoreUI/Utility/MVMCoreUIConstants.m | 2 ++ 6 files changed, 33 insertions(+) diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift index ee697a3e..815fe2d2 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift @@ -27,6 +27,10 @@ import UIKit return caret }() + public var baseDropdownEntryFieldModel: BaseDropdownEntryFieldModel? { + return model as? BaseDropdownEntryFieldModel + } + //-------------------------------------------------- // MARK: - Property Observers //-------------------------------------------------- @@ -39,6 +43,14 @@ import UIKit } } + public var isTextChanged: Bool = false { + didSet { + if(isTextChanged) { + performDropdownAction() + } + } + } + //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @@ -80,4 +92,15 @@ import UIKit dropDownCaretView.setOptional(with: model.caretView, delegateObject, additionalData) } + + private func performDropdownAction() { + if let actionModel = baseDropdownEntryFieldModel?.action, var actionMap = actionModel.toJSON() { + if var analyticsData = actionMap[KeyAnalyticsData] as? JSONDictionary { + let taggedValue = (analyticsData[KeyAdobeTrackerLinkName] as? String ?? "") + (text ?? "") + analyticsData[KeyAdobeTrackerLinkName] = taggedValue + actionMap[KeyAnalyticsData] = analyticsData + } + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: nil, delegateObject: delegateObject) + } + } } diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryFieldModel.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryFieldModel.swift index e34183de..0bb17284 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryFieldModel.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryFieldModel.swift @@ -12,6 +12,7 @@ //-------------------------------------------------- public var caretView: CaretViewModel? + public var action: ActionModelProtocol? public override class var identifier: String { return "" @@ -24,6 +25,7 @@ private enum CodingKeys: String, CodingKey { case moleculeName case caretView + case action } //-------------------------------------------------- @@ -34,6 +36,7 @@ try super.init(from: decoder) let typeContainer = try decoder.container(keyedBy: CodingKeys.self) caretView = try typeContainer.decodeIfPresent(CaretViewModel.self, forKey: .caretView) + action = try typeContainer.decodeModelIfPresent(codingKey: .action) } public override func encode(to encoder: Encoder) throws { @@ -41,5 +44,6 @@ var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encode(caretView, forKey: .caretView) + try container.encodeModelIfPresent(action, forKey: .action) } } diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DateDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DateDropdownEntryField.swift index 6ff950f6..edf1423f 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DateDropdownEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DateDropdownEntryField.swift @@ -101,6 +101,7 @@ import UIKit } else { text = dateDropdownModel?.dateFormatter.string(from: date) } + isTextChanged = true } @objc public override func dismissFieldInput(_ sender: Any?) { diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift index cc8a4c71..735628bb 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift @@ -138,6 +138,7 @@ extension ItemDropdownEntryField: UIPickerViewDelegate, UIPickerViewDataSource { observeDropdownChange?(text ?? "", pickerData[row]) text = pickerData[row] itemDropdownEntryFieldModel?.selectedIndex = row + isTextChanged = true } } diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.h b/MVMCoreUI/Utility/MVMCoreUIConstants.h index 4c0a3553..a76bbc97 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.h +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.h @@ -42,6 +42,8 @@ extern NSString * const KeyIsOpaque; extern NSString * const KeyFieldKey; extern NSString * const KeyRequired; +extern NSString * const KeyAnalyticsData; +extern NSString * const KeyAdobeTrackerLinkName; #pragma mark - Values diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.m b/MVMCoreUI/Utility/MVMCoreUIConstants.m index 5f5a9a45..3e6ac813 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.m +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.m @@ -40,6 +40,8 @@ NSString * const KeyTextColor = @"textColor"; NSString * const KeyIsHidden = @"isHidden"; NSString * const KeyIsOpaque = @"isOpaque"; +NSString * const KeyAnalyticsData = @"analyticsData"; +NSString * const KeyAdobeTrackerLinkName = @"vzwi.mvmapp.LinkName"; #pragma mark - Values From 88a6421a7ee4e4fb69f9ddfd06f8bb728d8f5b0c Mon Sep 17 00:00:00 2001 From: Damodaram Date: Wed, 16 Sep 2020 20:28:55 +0530 Subject: [PATCH 03/11] updated based on review comments --- .../FormFields/TextFields/BaseDropdownEntryField.swift | 9 ++------- MVMCoreUI/Utility/MVMCoreUIConstants.h | 2 -- MVMCoreUI/Utility/MVMCoreUIConstants.m | 2 -- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift index 815fe2d2..f50ee379 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift @@ -94,13 +94,8 @@ import UIKit } private func performDropdownAction() { - if let actionModel = baseDropdownEntryFieldModel?.action, var actionMap = actionModel.toJSON() { - if var analyticsData = actionMap[KeyAnalyticsData] as? JSONDictionary { - let taggedValue = (analyticsData[KeyAdobeTrackerLinkName] as? String ?? "") + (text ?? "") - analyticsData[KeyAdobeTrackerLinkName] = taggedValue - actionMap[KeyAnalyticsData] = analyticsData - } - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: nil, delegateObject: delegateObject) + if let actionModel = baseDropdownEntryFieldModel?.action, let actionMap = actionModel.toJSON() { + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: baseDropdownEntryFieldModel?.toJSON(), delegateObject: delegateObject) } } } diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.h b/MVMCoreUI/Utility/MVMCoreUIConstants.h index a76bbc97..4c0a3553 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.h +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.h @@ -42,8 +42,6 @@ extern NSString * const KeyIsOpaque; extern NSString * const KeyFieldKey; extern NSString * const KeyRequired; -extern NSString * const KeyAnalyticsData; -extern NSString * const KeyAdobeTrackerLinkName; #pragma mark - Values diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.m b/MVMCoreUI/Utility/MVMCoreUIConstants.m index 3e6ac813..5f5a9a45 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.m +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.m @@ -40,8 +40,6 @@ NSString * const KeyTextColor = @"textColor"; NSString * const KeyIsHidden = @"isHidden"; NSString * const KeyIsOpaque = @"isOpaque"; -NSString * const KeyAnalyticsData = @"analyticsData"; -NSString * const KeyAdobeTrackerLinkName = @"vzwi.mvmapp.LinkName"; #pragma mark - Values From 4254e63993aea373ad5e06ad2072f81697126f1e Mon Sep 17 00:00:00 2001 From: Damodaram Date: Thu, 17 Sep 2020 19:52:33 +0530 Subject: [PATCH 04/11] sending model json --- MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift | 6 +++++- MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift | 2 +- MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift | 2 +- MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift index fc6607b1..6e52e735 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift @@ -24,6 +24,10 @@ import MVMCore var groupName: String? var delegateObject: MVMCoreUIDelegateObject? + public var checkboxModel: CheckboxModel? { + return model as? CheckboxModel + } + public static let defaultHeightWidth: CGFloat = 18.0 /// If true the border of this checkbox will be circular. @@ -393,7 +397,7 @@ import MVMCore private func performCheckboxAction(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { if let actionMap = actionModel.toJSON() { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: checkboxModel?.toJSON(), delegateObject: delegateObject) } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift index 7b8b5703..793348c9 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift @@ -139,7 +139,7 @@ open class RadioBox: Control, MFButtonProtocol { isSelected = true radioBoxModel?.selected = isSelected if let actionModel = radioBoxModel?.action { - Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: nil) + Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: radioBoxModel?.toJSON()) } layer.setNeedsDisplay() } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift index e1f3ab93..30cc4bb8 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift @@ -100,7 +100,7 @@ import UIKit isSelected = !isSelected } if let actionModel = radioModel?.action, isSelected { - Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: nil) + Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: radioModel?.toJSON()) } _ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) setNeedsDisplay() diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift index 3184feb4..f921616f 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift @@ -121,7 +121,7 @@ open class RadioSwatch: Control, MFButtonProtocol { isSelected = true radioSwatchModel?.selected = isSelected if let actionModel = radioSwatchModel?.action { - Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: nil) + Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: radioSwatchModel?.toJSON()) } layer.setNeedsDisplay() } From 81aa0da7cbb88305d9686b7eecfa4dfac7c05f00 Mon Sep 17 00:00:00 2001 From: Damodaram Date: Fri, 18 Sep 2020 12:34:57 +0530 Subject: [PATCH 05/11] sending source model to action --- .../FormFields/TextFields/BaseDropdownEntryField.swift | 7 +++++-- MVMCoreUI/Utility/MVMCoreUIConstants.h | 1 + MVMCoreUI/Utility/MVMCoreUIConstants.m | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift index f50ee379..9a0b6923 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift @@ -30,6 +30,7 @@ import UIKit public var baseDropdownEntryFieldModel: BaseDropdownEntryFieldModel? { return model as? BaseDropdownEntryFieldModel } + var additionalData: [AnyHashable: Any]? //-------------------------------------------------- // MARK: - Property Observers @@ -87,7 +88,7 @@ import UIKit public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) - + self.additionalData = additionalData guard let model = model as? BaseDropdownEntryFieldModel else { return } dropDownCaretView.setOptional(with: model.caretView, delegateObject, additionalData) @@ -95,7 +96,9 @@ import UIKit private func performDropdownAction() { if let actionModel = baseDropdownEntryFieldModel?.action, let actionMap = actionModel.toJSON() { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: baseDropdownEntryFieldModel?.toJSON(), delegateObject: delegateObject) + var additionalData = self.additionalData ?? [:] + additionalData[KeySourceModel] = baseDropdownEntryFieldModel + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } } } diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.h b/MVMCoreUI/Utility/MVMCoreUIConstants.h index 4c0a3553..684d6044 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.h +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.h @@ -42,6 +42,7 @@ extern NSString * const KeyIsOpaque; extern NSString * const KeyFieldKey; extern NSString * const KeyRequired; +extern NSString * const KeySourceModel; #pragma mark - Values diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.m b/MVMCoreUI/Utility/MVMCoreUIConstants.m index 5f5a9a45..e4954b01 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.m +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.m @@ -40,6 +40,7 @@ NSString * const KeyTextColor = @"textColor"; NSString * const KeyIsHidden = @"isHidden"; NSString * const KeyIsOpaque = @"isOpaque"; +NSString * const KeySourceModel = @"sourceModel"; #pragma mark - Values From b1fb3f075f9d28e6e22b1b496ea30200d9b0f2f8 Mon Sep 17 00:00:00 2001 From: Damodaram Date: Fri, 18 Sep 2020 12:54:31 +0530 Subject: [PATCH 06/11] updated additional data for selectors --- MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift | 4 +++- MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift | 6 +++++- MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift | 6 +++++- MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift | 6 +++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift index 6e52e735..b6a87cd9 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift @@ -397,7 +397,9 @@ import MVMCore private func performCheckboxAction(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { if let actionMap = actionModel.toJSON() { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: checkboxModel?.toJSON(), delegateObject: delegateObject) + var additionalDatatoUpdate = additionalData ?? [:] + additionalDatatoUpdate[KeySourceModel] = checkboxModel + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalDatatoUpdate, delegateObject: delegateObject) } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift index 793348c9..46b4cef5 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift @@ -23,6 +23,7 @@ open class RadioBox: Control, MFButtonProtocol { public var subTextLabelHeightConstraint: NSLayoutConstraint? private var delegateObject: MVMCoreUIDelegateObject? + var additionalData: [AnyHashable: Any]? public var radioBoxModel: RadioBoxModel? { return model as? RadioBoxModel @@ -80,6 +81,7 @@ open class RadioBox: Control, MFButtonProtocol { super.set(with: model, delegateObject, additionalData) guard let model = model as? RadioBoxModel else { return } self.delegateObject = delegateObject + self.additionalData = additionalData label.text = model.text subTextLabel.text = model.subText isOutOfStock = model.strikethrough @@ -139,7 +141,9 @@ open class RadioBox: Control, MFButtonProtocol { isSelected = true radioBoxModel?.selected = isSelected if let actionModel = radioBoxModel?.action { - Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: radioBoxModel?.toJSON()) + var additionalData = self.additionalData ?? [:] + additionalData[KeySourceModel] = radioBoxModel + Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: additionalData) } layer.setNeedsDisplay() } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift index 30cc4bb8..9e18f936 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift @@ -30,6 +30,7 @@ import UIKit public var enabledColor: UIColor = .mvmBlack public var disabledColor: UIColor = .mvmCoolGray3 public var delegateObject: MVMCoreUIDelegateObject? + var additionalData: [AnyHashable: Any]? public var radioModel: RadioButtonModel? { return model as? RadioButtonModel @@ -100,7 +101,9 @@ import UIKit isSelected = !isSelected } if let actionModel = radioModel?.action, isSelected { - Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: radioModel?.toJSON()) + var additionalData = self.additionalData ?? [:] + additionalData[KeySourceModel] = radioModel + Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: additionalData) } _ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) setNeedsDisplay() @@ -158,6 +161,7 @@ import UIKit public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) self.delegateObject = delegateObject + self.additionalData = additionalData guard let model = model as? RadioButtonModel else { return } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift index f921616f..e1502515 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift @@ -21,6 +21,7 @@ open class RadioSwatch: Control, MFButtonProtocol { private var maskLayer: CALayer? private var delegateObject: MVMCoreUIDelegateObject? + var additionalData: [AnyHashable: Any]? public var radioSwatchModel: RadioSwatchModel? { return model as? RadioSwatchModel @@ -60,6 +61,7 @@ open class RadioSwatch: Control, MFButtonProtocol { super.set(with: model, delegateObject, additionalData) guard let model = model as? RadioSwatchModel else { return } self.delegateObject = delegateObject + self.additionalData = additionalData bottomText.text = model.text isSelected = model.selected isEnabled = model.enabled @@ -121,7 +123,9 @@ open class RadioSwatch: Control, MFButtonProtocol { isSelected = true radioSwatchModel?.selected = isSelected if let actionModel = radioSwatchModel?.action { - Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: radioSwatchModel?.toJSON()) + var additionalData = self.additionalData ?? [:] + additionalData[KeySourceModel] = radioSwatchModel + Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: additionalData) } layer.setNeedsDisplay() } From 44dad679616c479450a9a925cf0587d49c84524e Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 18 Sep 2020 12:39:58 -0400 Subject: [PATCH 07/11] push latest iteration for perform action --- .../FormFields/TextFields/BaseDropdownEntryField.swift | 10 +--------- .../FormFields/TextFields/DateDropdownEntryField.swift | 2 +- .../FormFields/TextFields/ItemDropdownEntryField.swift | 2 +- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift index 9a0b6923..2076d0fc 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift @@ -44,14 +44,6 @@ import UIKit } } - public var isTextChanged: Bool = false { - didSet { - if(isTextChanged) { - performDropdownAction() - } - } - } - //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @@ -94,7 +86,7 @@ import UIKit dropDownCaretView.setOptional(with: model.caretView, delegateObject, additionalData) } - private func performDropdownAction() { + func performDropdownAction() { if let actionModel = baseDropdownEntryFieldModel?.action, let actionMap = actionModel.toJSON() { var additionalData = self.additionalData ?? [:] additionalData[KeySourceModel] = baseDropdownEntryFieldModel diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DateDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DateDropdownEntryField.swift index edf1423f..b8fba094 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DateDropdownEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DateDropdownEntryField.swift @@ -101,12 +101,12 @@ import UIKit } else { text = dateDropdownModel?.dateFormatter.string(from: date) } - isTextChanged = true } @objc public override func dismissFieldInput(_ sender: Any?) { setTextWith(date: datePicker?.date) + performDropdownAction() super.dismissFieldInput(sender) } diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift index 735628bb..ea82a922 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift @@ -138,7 +138,7 @@ extension ItemDropdownEntryField: UIPickerViewDelegate, UIPickerViewDataSource { observeDropdownChange?(text ?? "", pickerData[row]) text = pickerData[row] itemDropdownEntryFieldModel?.selectedIndex = row - isTextChanged = true + performDropdownAction() } } From 68274505fbdce0ab49c91c055823179f9ff02b1b Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 18 Sep 2020 13:08:08 -0400 Subject: [PATCH 08/11] some checks for analytics change --- .../TextFields/ItemDropdownEntryField.swift | 12 +++++++++--- .../TextFields/ItemDropdownEntryFieldModel.swift | 16 +++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift index ea82a922..6c2a0f4e 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift @@ -32,6 +32,8 @@ open class ItemDropdownEntryField: BaseDropdownEntryField { return model as? ItemDropdownEntryFieldModel } + private var systemWillSetItem = false + //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @@ -109,8 +111,10 @@ open class ItemDropdownEntryField: BaseDropdownEntryField { pickerData = model.options setPickerDelegates(delegate: self) - if let pickerView = pickerView { - self.pickerView(pickerView, didSelectRow: model.selectedIndex, inComponent: 0) + if let pickerView = pickerView, let index = model.selectedIndex { + systemWillSetItem = true + self.pickerView(pickerView, didSelectRow: index, inComponent: 0) + systemWillSetItem = false } } } @@ -138,7 +142,9 @@ extension ItemDropdownEntryField: UIPickerViewDelegate, UIPickerViewDataSource { observeDropdownChange?(text ?? "", pickerData[row]) text = pickerData[row] itemDropdownEntryFieldModel?.selectedIndex = row - performDropdownAction() + if !systemWillSetItem { + performDropdownAction() + } } } diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryFieldModel.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryFieldModel.swift index d89f5e16..0bc1ee0a 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryFieldModel.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryFieldModel.swift @@ -16,11 +16,14 @@ } public var options: [String] = [] - public var selectedIndex: Int = 0 + public var selectedIndex: Int? public override func formFieldValue() -> AnyHashable? { - guard !options.isEmpty else { return nil } - return options[selectedIndex] + guard !options.isEmpty, + let index = selectedIndex + else { return nil } + + return options[index] } //-------------------------------------------------- @@ -45,13 +48,16 @@ if let selectedIndex = try typeContainer.decodeIfPresent(Int.self, forKey: .selectedIndex) { self.selectedIndex = selectedIndex } - baseValue = options.indices.contains(selectedIndex) ? options[selectedIndex] : nil + + if let index = selectedIndex { + baseValue = options.indices.contains(index) ? options[index] : nil + } } public override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(options, forKey: .options) - try container.encode(options, forKey: .selectedIndex) + try container.encodeIfPresent(options, forKey: .selectedIndex) } } From 84cb19805724a53e60a2ee012995f0ec861049ab Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Fri, 18 Sep 2020 15:25:48 -0400 Subject: [PATCH 09/11] move the drop down action to field input dismissal. --- .../FormFields/TextFields/BaseDropdownEntryField.swift | 5 +++++ .../FormFields/TextFields/DateDropdownEntryField.swift | 1 - .../FormFields/TextFields/ItemDropdownEntryField.swift | 7 ------- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift index 2076d0fc..38da2bdb 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/BaseDropdownEntryField.swift @@ -86,6 +86,11 @@ import UIKit dropDownCaretView.setOptional(with: model.caretView, delegateObject, additionalData) } + public override func dismissFieldInput(_ sender: Any?) { + performDropdownAction() + super.dismissFieldInput(sender) + } + func performDropdownAction() { if let actionModel = baseDropdownEntryFieldModel?.action, let actionMap = actionModel.toJSON() { var additionalData = self.additionalData ?? [:] diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DateDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DateDropdownEntryField.swift index b8fba094..6ff950f6 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DateDropdownEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/DateDropdownEntryField.swift @@ -106,7 +106,6 @@ import UIKit @objc public override func dismissFieldInput(_ sender: Any?) { setTextWith(date: datePicker?.date) - performDropdownAction() super.dismissFieldInput(sender) } diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift index 6c2a0f4e..ddc459c3 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/ItemDropdownEntryField.swift @@ -32,8 +32,6 @@ open class ItemDropdownEntryField: BaseDropdownEntryField { return model as? ItemDropdownEntryFieldModel } - private var systemWillSetItem = false - //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @@ -112,9 +110,7 @@ open class ItemDropdownEntryField: BaseDropdownEntryField { setPickerDelegates(delegate: self) if let pickerView = pickerView, let index = model.selectedIndex { - systemWillSetItem = true self.pickerView(pickerView, didSelectRow: index, inComponent: 0) - systemWillSetItem = false } } } @@ -142,9 +138,6 @@ extension ItemDropdownEntryField: UIPickerViewDelegate, UIPickerViewDataSource { observeDropdownChange?(text ?? "", pickerData[row]) text = pickerData[row] itemDropdownEntryFieldModel?.selectedIndex = row - if !systemWillSetItem { - performDropdownAction() - } } } From c9726652b19626efd78b87c53bc5473b0059a357 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Fri, 18 Sep 2020 16:58:36 -0400 Subject: [PATCH 10/11] Add toggle model source. --- MVMCoreUI/Atomic/Atoms/Views/Toggle.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift b/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift index dfffcded..dd7dc9f0 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift @@ -395,17 +395,19 @@ public typealias ActionBlockConfirmation = () -> (Bool) let actionMap = model.action?.toJSON() let alternateActionMap = model.alternateAction?.toJSON() if actionMap != nil || alternateActionMap != nil { + var additionalDatatoUpdate = additionalData ?? [:] + additionalDatatoUpdate[KeySourceModel] = model didToggleAction = { [weak self] in guard let self = self else { return } if self.isOn { if actionMap != nil { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalDatatoUpdate, delegateObject: delegateObject) } } else { if alternateActionMap != nil { - MVMCoreActionHandler.shared()?.handleAction(with: alternateActionMap, additionalData: additionalData, delegateObject: delegateObject) + MVMCoreActionHandler.shared()?.handleAction(with: alternateActionMap, additionalData: additionalDatatoUpdate, delegateObject: delegateObject) } else if actionMap != nil { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalDatatoUpdate, delegateObject: delegateObject) } } } From bf0fe53bc66c1b2abdd27a3cca5633a236ee631c Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Fri, 18 Sep 2020 17:39:16 -0400 Subject: [PATCH 11/11] else if for clarity --- MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift index b6a87cd9..edc37628 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift @@ -440,9 +440,8 @@ import MVMCore if let offAction = model.offAction, !self.isSelected { self.performCheckboxAction(with: offAction, delegateObject: delegateObject, additionalData: additionalData) - return - } - if let action = model.action { + + } else if let action = model.action { self.performCheckboxAction(with: action, delegateObject: delegateObject, additionalData: additionalData) } }