From e3b0b43272c38917d2abc15f68d74e872c5bb211 Mon Sep 17 00:00:00 2001 From: "Xinlei(Ryan) Pan" Date: Thu, 16 Jan 2020 10:30:20 -0500 Subject: [PATCH] update link method --- MVMCoreUI/Atoms/Buttons/Link.swift | 12 ++++++++++++ MVMCoreUI/BaseClasses/Button.swift | 12 ++++++++++++ .../OtherHandlers/MVMCoreUIMoleculeMappingObject.m | 1 - 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 3b6cabb8..39187ac8 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -109,6 +109,18 @@ extension Link { } } +extension Link: ModelMoleculeViewProtocol { + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + guard let model = model as? LinkModel else { return } + setTitle(model.title, for: .normal) + setTitleColor(model.textColor.uiColor, for: .normal) + isEnabled = model.enabled + backgroundColor = model.backgroundColor?.uiColor + set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) + } +} + + // MARK: - MVMCoreUIMoleculeViewProtocol extension Link { diff --git a/MVMCoreUI/BaseClasses/Button.swift b/MVMCoreUI/BaseClasses/Button.swift index 356ef59d..816063f4 100644 --- a/MVMCoreUI/BaseClasses/Button.swift +++ b/MVMCoreUI/BaseClasses/Button.swift @@ -84,6 +84,18 @@ public typealias ButtonAction = (Button) -> () } } } + + public func set(with action: ActionProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + buttonDelegate = delegateObject?.buttonDelegate + addActionBlock(event: .touchUpInside) { [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) + } + } + } } // MARK: - MVMCoreUIMoleculeViewProtocol diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 19c4d9ef..5a4bfd5b 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -30,7 +30,6 @@ @"line": Line.class, @"link": Link.class, @"button": PrimaryButton.class, - @"link": MFTextButton.class, @"header": StandardHeaderView.class, @"stack": MoleculeStackView.class, @"twoButtonView": TwoButtonView.class,