From 78461d0557c0d7cdf25ab3d952bc74e3bb3a8f37 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jan 2020 13:48:35 -0500 Subject: [PATCH 1/2] 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) } } From f6c3a02f0e1a730de2e0e3bfc9154e0a45ff4966 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jan 2020 14:20:58 -0500 Subject: [PATCH 2/2] remove old extension --- MVMCoreUI.xcodeproj/project.pbxproj | 4 - .../MFTextField+ModelExtension.swift | 2 +- .../ViewConstrainingView+ModelExtension.swift | 89 ------------------- MVMCoreUI/Molecules/Scroller.swift | 3 +- MVMCoreUI/Organisms/Carousel.swift | 2 +- 5 files changed, 3 insertions(+), 97 deletions(-) delete mode 100644 MVMCoreUI/Atoms/Views/ViewConstrainingView+ModelExtension.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 80ff4c39..25fd66ea 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -28,7 +28,6 @@ 012A88EE239858E300FE3DA1 /* ContainerMoleculeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88ED239858E300FE3DA1 /* ContainerMoleculeProtocol.swift */; }; 012A88F123985E0100FE3DA1 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88F023985E0100FE3DA1 /* Color.swift */; }; 012CA99A2384A687003F810F /* MFTextField+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA9992384A687003F810F /* MFTextField+ModelExtension.swift */; }; - 012CA99C23859FDC003F810F /* ViewConstrainingView+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA99B23859FDC003F810F /* ViewConstrainingView+ModelExtension.swift */; }; 012CA99E2385A2D3003F810F /* MFView+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */; }; 012CA9DE2388723E003F810F /* (null) in Sources */ = {isa = PBXBuildFile; }; 012CA9E223888AED003F810F /* (null) in Sources */ = {isa = PBXBuildFile; }; @@ -292,7 +291,6 @@ 012A88ED239858E300FE3DA1 /* ContainerMoleculeProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerMoleculeProtocol.swift; sourceTree = ""; }; 012A88F023985E0100FE3DA1 /* Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = ""; }; 012CA9992384A687003F810F /* MFTextField+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFTextField+ModelExtension.swift"; sourceTree = ""; }; - 012CA99B23859FDC003F810F /* ViewConstrainingView+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ViewConstrainingView+ModelExtension.swift"; sourceTree = ""; }; 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFView+ModelExtension.swift"; sourceTree = ""; }; 014AA72123C501E2006F3E93 /* MoleculeContainerModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoleculeContainerModel.swift; sourceTree = ""; }; 014AA72223C501E2006F3E93 /* ContainerModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContainerModel.swift; sourceTree = ""; }; @@ -1019,7 +1017,6 @@ 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */, D29DF28721E7AC2B003B2FB9 /* ViewConstrainingView.h */, D29DF28821E7AC2B003B2FB9 /* ViewConstrainingView.m */, - 012CA99B23859FDC003F810F /* ViewConstrainingView+ModelExtension.swift */, D282AAB9224131D100C46919 /* MFTransparentGIFView.swift */, D282AAB3223FDDAE00C46919 /* MFLoadImageView.swift */, 944589222385DA9500DE9FD4 /* ImageViewModel.swift */, @@ -1497,7 +1494,6 @@ D29DF13221E6851E003B2FB9 /* MVMCoreUITopAlertBaseView.m in Sources */, D29DF29C21E7ADB9003B2FB9 /* MFProgrammaticTableViewController.m in Sources */, 0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */, - 012CA99C23859FDC003F810F /* ViewConstrainingView+ModelExtension.swift in Sources */, 0A1214A022C11A18007C7030 /* ActionDetailWithImage.swift in Sources */, D2B18B922361E65A00A9AEDC /* CoreUIObject.swift in Sources */, D29DF2BE21E7BEA4003B2FB9 /* TopTabbar.m in Sources */, diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift b/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift index 79ff851e..9944e22d 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift +++ b/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift @@ -20,7 +20,7 @@ extension MFTextField: ModelMoleculeViewProtocol { //TODO: Need to create setWithModel in ViewConstraining View #warning("This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView.") //TODO: This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView. - setUpWithModel(model, delegateObject, additionalData) + setUpDefaultWithModel(model, delegateObject, additionalData) guard let textFieldModel = model as? TextFieldModel, let delegateObject = delegateObject else { diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView+ModelExtension.swift b/MVMCoreUI/Atoms/Views/ViewConstrainingView+ModelExtension.swift deleted file mode 100644 index bd6312f2..00000000 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView+ModelExtension.swift +++ /dev/null @@ -1,89 +0,0 @@ -// -// ViewConstrainingView+ModelExtension.swift -// MVMCoreUI -// -// Created by Suresh, Kamlesh on 11/20/19. -// Copyright © 2019 Verizon Wireless. All rights reserved. -// - -import Foundation - -extension ViewConstrainingView { - public func setUpWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) { - if self.constrainedView == nil { - setUpDefaultWithModel(model, delegateObject, additionalData) - } - - if shouldSetupMoleculeFromJSON, - let moleculeObject = (model as? ContainerMoleculeProtocol)?.molecule { - if molecule != nil { - (molecule as? ModelMoleculeViewProtocol)?.setWithModel(moleculeObject, delegateObject, additionalData) - } else { - if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeObject, delegateObject, true) { - addMolecule(molecule) - self.molecule = molecule - setMoleculeAccessibility() - } - } - } else { - (molecule as? ModelMoleculeViewProtocol)?.setWithModel(model, delegateObject, additionalData) - } - - if let containerMoleculeModel = model as? ContainerModelProtocol { - if let useHorizontalMargins = containerMoleculeModel.useHorizontalMargins { - updateViewHorizontalDefaults = useHorizontalMargins - } - if let useVerticalMargins = containerMoleculeModel.useVerticalMargins { - updateViewVerticalDefaults = useVerticalMargins - } - - if let horizontalAlignment = containerMoleculeModel.horizontalAlignment { - alignHorizontal(horizontalAlignment) - } - if let verticalAlignment = containerMoleculeModel.verticalAlignment { - alignVertical(verticalAlignment) - } - } - - #warning("work on the below") - // let copyBackgroundColor = self.copyBackgroundColor?() - // if copyBackgroundColor { - // - // } - } -} - -extension ModelMoleculeViewProtocol where Self: ViewConstrainingView { - public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) { - setUpWithModel(model, delegateObject, additionalData) - } -} - -/* -- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { - // Only treated as a container if we are constraining a molecule. - - NSNumber *useHorizontalMargins = [json optionalNumberForKey:@"useHorizontalMargins"]; - if (useHorizontalMargins) { - self.updateViewHorizontalDefaults = [useHorizontalMargins boolValue]; - } - NSNumber *useVerticalMargins = [json optionalNumberForKey:@"useVerticalMargins"]; - if (useVerticalMargins) { - self.updateViewVerticalDefaults = [useVerticalMargins boolValue]; - } - - // Set the alignment for the stack in the containing view. The json driven value is for the axis direction alignment. - NSString *alignment = [json string:@"horizontalAlignment"]; - if (alignment) { - [self alignHorizontal:[ViewConstrainingView getAlignmentForString:alignment defaultAlignment:UIStackViewAlignmentFill]]; - } - alignment = [json string:@"verticalAlignment"]; - if (alignment) { - [self alignVertical:[ViewConstrainingView getAlignmentForString:alignment defaultAlignment:UIStackViewAlignmentFill]]; - } - - if ([self.molecule respondsToSelector:@selector(copyBackgroundColor)] && [self.molecule performSelector:@selector(copyBackgroundColor)]) { - self.backgroundColor = self.molecule.backgroundColor; - } -} -*/ diff --git a/MVMCoreUI/Molecules/Scroller.swift b/MVMCoreUI/Molecules/Scroller.swift index 1ce3ceb2..01477158 100644 --- a/MVMCoreUI/Molecules/Scroller.swift +++ b/MVMCoreUI/Molecules/Scroller.swift @@ -29,10 +29,9 @@ import UIKit } public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { - //super.setWithModel(model, delegateObject, additionalData) #warning("This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView.") //TODO: This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView. - setUpWithModel(model, delegateObject, additionalData) + setUpDefaultWithModel(model, delegateObject, additionalData) guard let model = model, let moleculeModel = (model as? ContainerMoleculeProtocol)?.molecule else { diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index 50ca800a..ef19f1a3 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -88,7 +88,7 @@ open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol { #warning("This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView.") //TODO: This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView. - setUpWithModel(caroselModel, delegateObject, additionalData) + setUpDefaultWithModel(model, delegateObject, additionalData) collectionView.backgroundColor = backgroundColor collectionView.layer.borderColor = backgroundColor?.cgColor