From 78461d0557c0d7cdf25ab3d952bc74e3bb3a8f37 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jan 2020 13:48:35 -0500 Subject: [PATCH] CaretLink --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++++ MVMCoreUI/Atoms/Buttons/CaretButton.swift | 16 ++++++++++++- MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift | 12 +++++----- .../Buttons/MFCustomButton+ActionModel.swift | 23 +++++++++++++++++++ .../MVMCoreUIMoleculeMappingObject.m | 2 +- .../OtherHandlers/MoleculeObjectMapping.swift | 1 + 6 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 8363aad1..80ff4c39 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -122,6 +122,7 @@ D282AAB4223FDDAE00C46919 /* MFLoadImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB3223FDDAE00C46919 /* MFLoadImageView.swift */; }; D282AABA224131D100C46919 /* MFTransparentGIFView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB9224131D100C46919 /* MFTransparentGIFView.swift */; }; D282AACB2243C61700C46919 /* ButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AACA2243C61700C46919 /* ButtonView.swift */; }; + D28A837723C79FC600DFE4FC /* MFCustomButton+ActionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A837623C79FC600DFE4FC /* MFCustomButton+ActionModel.swift */; }; D296E13C229598BF0051EBE7 /* MoleculeListCellProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D296E13B2295969C0051EBE7 /* MoleculeListCellProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; D296E1412295EBBA0051EBE7 /* MoleculeDelegateProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D296E1402295EBBA0051EBE7 /* MoleculeDelegateProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; D296E14722A5984C0051EBE7 /* MVMCoreUIViewConstrainingProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D296E14622A597490051EBE7 /* MVMCoreUIViewConstrainingProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -381,6 +382,7 @@ D282AAB3223FDDAE00C46919 /* MFLoadImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFLoadImageView.swift; sourceTree = ""; }; D282AAB9224131D100C46919 /* MFTransparentGIFView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFTransparentGIFView.swift; sourceTree = ""; }; D282AACA2243C61700C46919 /* ButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonView.swift; sourceTree = ""; }; + D28A837623C79FC600DFE4FC /* MFCustomButton+ActionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFCustomButton+ActionModel.swift"; sourceTree = ""; }; D296E13B2295969C0051EBE7 /* MoleculeListCellProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MoleculeListCellProtocol.h; sourceTree = ""; }; D296E1402295EBBA0051EBE7 /* MoleculeDelegateProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MoleculeDelegateProtocol.h; sourceTree = ""; }; D296E14622A597490051EBE7 /* MVMCoreUIViewConstrainingProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIViewConstrainingProtocol.h; sourceTree = ""; }; @@ -988,6 +990,7 @@ D29DF16B21E69E1F003B2FB9 /* ButtonDelegateProtocol.h */, D29DF16A21E69E1F003B2FB9 /* MFCustomButton.h */, D29DF17021E69E1F003B2FB9 /* MFCustomButton.m */, + D28A837623C79FC600DFE4FC /* MFCustomButton+ActionModel.swift */, D29DF16C21E69E1F003B2FB9 /* PrimaryButton.h */, D29DF17121E69E1F003B2FB9 /* PrimaryButton.m */, D282AACA2243C61700C46919 /* ButtonView.swift */, @@ -1395,6 +1398,7 @@ D282AABA224131D100C46919 /* MFTransparentGIFView.swift in Sources */, 944589232385DA9600DE9FD4 /* ImageViewModel.swift in Sources */, D213347723843825008E41B3 /* Line.swift in Sources */, + D28A837723C79FC600DFE4FC /* MFCustomButton+ActionModel.swift in Sources */, 012A88EC238F084D00FE3DA1 /* FooterModel.swift in Sources */, D2A514672213885800345BFB /* StandardHeaderView.swift in Sources */, 01EB369023609801006832FA /* ListItemModel.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Buttons/CaretButton.swift b/MVMCoreUI/Atoms/Buttons/CaretButton.swift index 6c9de088..b3ff5409 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButton.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretButton.swift @@ -8,7 +8,7 @@ // -open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewConstrainingProtocol { +open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewConstrainingProtocol, ModelMoleculeViewProtocol { //------------------------------------------------------ // MARK: - Constants @@ -132,6 +132,20 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUI } } + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + guard let caretLinkModel = model as? CaretLinkModel else { return } + if let color = caretLinkModel.backgroundColor { + backgroundColor = color.uiColor + } + enabledColor = caretLinkModel.enabledColor.uiColor + if let color = caretLinkModel.disabledColor { + disabledColor = color.uiColor + } + isEnabled = caretLinkModel.enabled + set(with: caretLinkModel.action, delegateObject: delegateObject, additionalData: additionalData) + setTitle(caretLinkModel.label.text, for: .normal) + } + public func needsToBeConstrained() -> Bool { return true } diff --git a/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift b/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift index 4d3c6223..3cc77a54 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift @@ -14,8 +14,8 @@ public class CaretLinkModel: MoleculeProtocol { public var backgroundColor: Color? public var label: LabelModel public var action: ActionProtocol - public var enabledColor: UIColor = .black - public var disabledColor: UIColor = .mfSilver() + public var enabledColor: Color = Color(uiColor: .black) + public var disabledColor: Color? = Color(uiColor: .mfSilver()) public var enabled: Bool = true public init(label: LabelModel, action: ActionProtocol) { @@ -36,10 +36,10 @@ public class CaretLinkModel: MoleculeProtocol { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) label = try typeContainer.decode(LabelModel.self, forKey: .label) - if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor)?.uiColor { + if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor) { enabledColor = color } - if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor)?.uiColor { + if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) { disabledColor = color } if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { @@ -53,8 +53,8 @@ public class CaretLinkModel: MoleculeProtocol { try container.encode(label, forKey: .label) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeModel(action, forKey: .action) - try container.encode(Color(uiColor: enabledColor), forKey: .enabledColor) - try container.encode(Color(uiColor: disabledColor), forKey: .disabledColor) + try container.encode(enabled, forKey: .enabledColor) + try container.encodeIfPresent(disabledColor, forKey: .disabledColor) try container.encode(enabled, forKey: .enabled) } } diff --git a/MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift b/MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift new file mode 100644 index 00000000..b967db48 --- /dev/null +++ b/MVMCoreUI/Atoms/Buttons/MFCustomButton+ActionModel.swift @@ -0,0 +1,23 @@ +// +// MFCustomButton+ActionModel.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 1/9/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +public extension MFCustomButton { + func set(with action: ActionProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + buttonDelegate = delegateObject?.buttonDelegate + add({ [weak self] sender in + guard let self = self else { return } + if let data = try? action.encode(using: JSONEncoder()), + let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any], + delegateObject?.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true { + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + } + }, for: .touchUpInside) + } +} diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index c656ab2f..3a8b7622 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -35,7 +35,7 @@ @"twoButtonView": TwoButtonView.class, @"footer": StandardFooterView.class, @"caretView": CaretView.class, - @"caretButton": CaretButton.class, + @"caretLink": CaretButton.class, @"textField": MFTextField.class, @"dropDown": DropDown.class, @"digitTextField": MFDigitTextField.class, diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 2b9b78a5..4eb9e4a8 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -34,5 +34,6 @@ import Foundation //ModelRegistry.register(ModuleMoleculeModel.self) ModelRegistry.register(LeftRightLabelModel.self) ModelRegistry.register(CaretViewModel.self) + ModelRegistry.register(CaretLinkModel.self) } }