update link method

This commit is contained in:
Xinlei(Ryan) Pan 2020-01-16 10:30:20 -05:00
parent 56b37255c2
commit e3b0b43272
3 changed files with 24 additions and 1 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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,