merge from feature/coding
This commit is contained in:
commit
17983b51f5
@ -8,10 +8,11 @@
|
||||
|
||||
public typealias ButtonAction = (Button) -> ()
|
||||
|
||||
@objcMembers open class Button: UIButton, MFButtonProtocol {
|
||||
@objcMembers open class Button: UIButton, MFButtonProtocol, ModelMoleculeViewProtocol {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
public var model: MoleculeModelProtocol?
|
||||
public var actionModel: ActionModelProtocol?
|
||||
|
||||
private var initialSetupPerformed = false
|
||||
@ -82,17 +83,25 @@ 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:- ModelMoleculeViewProtocol
|
||||
public func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
self.model = model
|
||||
if let backgroundColor = model?.backgroundColor {
|
||||
self.backgroundColor = backgroundColor.uiColor
|
||||
}
|
||||
}
|
||||
|
||||
public class func nameForReuse(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||
return model?.moleculeName
|
||||
}
|
||||
|
||||
public class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||
return nil
|
||||
}
|
||||
|
||||
public class func requiredModules(_ molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -110,9 +119,15 @@ extension Button: MVMCoreViewProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||
extension Button: MVMCoreUIMoleculeViewProtocol {
|
||||
public func reset() {
|
||||
backgroundColor = .clear
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: AppleGuidelinesProtocol
|
||||
extension Button: AppleGuidelinesProtocol {
|
||||
|
||||
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
||||
return Self.acceptablyOutsideBounds(point: point, bounds: bounds)
|
||||
}
|
||||
|
||||
@ -12,8 +12,7 @@ import UIKit
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
|
||||
public var json: [AnyHashable: Any]?
|
||||
open var json: [AnyHashable: Any]?
|
||||
public var model: MoleculeModelProtocol?
|
||||
|
||||
private var initialSetupPerformed = false
|
||||
@ -42,13 +41,13 @@ import UIKit
|
||||
//--------------------------------------------------
|
||||
|
||||
public func initialSetup() {
|
||||
|
||||
if !initialSetupPerformed {
|
||||
initialSetupPerformed = true
|
||||
setupView()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK:- ModelMoleculeViewProtocol
|
||||
public func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
self.model = model
|
||||
if let backgroundColor = model?.backgroundColor {
|
||||
@ -56,13 +55,22 @@ import UIKit
|
||||
}
|
||||
}
|
||||
|
||||
public class func nameForReuse(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||
return model?.moleculeName
|
||||
}
|
||||
|
||||
public class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||
return nil
|
||||
}
|
||||
|
||||
public class func requiredModules(_ molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - AppleGuidelinesProtocol
|
||||
extension Control: AppleGuidelinesProtocol {
|
||||
|
||||
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
||||
|
||||
return Self.acceptablyOutsideBounds(point: point, bounds: bounds)
|
||||
}
|
||||
}
|
||||
@ -81,15 +89,14 @@ extension Control: MVMCoreViewProtocol {
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||
extension Control: MVMCoreUIMoleculeViewProtocol {
|
||||
open func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||
self.json = json
|
||||
|
||||
if let backgroundColorString = json?.optionalStringForKey(KeyBackgroundColor) {
|
||||
backgroundColor = UIColor.mfGet(forHex: backgroundColorString)
|
||||
}
|
||||
}
|
||||
|
||||
public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||
self.json = json
|
||||
|
||||
if let backgroundColorString = json?.optionalStringForKey(KeyBackgroundColor) {
|
||||
backgroundColor = UIColor.mfGet(forHex: backgroundColorString)
|
||||
}
|
||||
}
|
||||
|
||||
public func reset() {
|
||||
backgroundColor = .clear
|
||||
}
|
||||
|
||||
@ -33,13 +33,13 @@ import UIKit
|
||||
}
|
||||
|
||||
public func initialSetup() {
|
||||
|
||||
if !initialSetupPerformed {
|
||||
initialSetupPerformed = true
|
||||
setupView()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK:- ModelMoleculeViewProtocol
|
||||
open func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
self.model = model
|
||||
if let backgroundColor = model?.backgroundColor {
|
||||
|
||||
@ -9,6 +9,11 @@
|
||||
import Foundation
|
||||
|
||||
public extension MVMCoreUIMoleculeMappingObject {
|
||||
|
||||
func register<M: Model, V: MVMCoreUIMoleculeViewProtocol>(viewClass: V.Type, viewModelClass: M.Type) {
|
||||
ModelRegistry.register(viewModelClass)
|
||||
MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(viewClass, forKey: viewModelClass.identifier as NSString)
|
||||
}
|
||||
|
||||
func getMoleculeClass(_ model: MoleculeModelProtocol) -> AnyClass? {
|
||||
if let moleculeName = model.moleculeName {
|
||||
|
||||
@ -10,24 +10,17 @@ import Foundation
|
||||
|
||||
@objcMembers public class MoleculeObjectMapping: NSObject {
|
||||
public static func registerObjects() {
|
||||
let mapping = MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping
|
||||
ModelRegistry.register(MoleculeStackModel.self)
|
||||
mapping?.setObject(MoleculeStackView.self, forKey: MoleculeStackModel.identifier as NSString)
|
||||
ModelRegistry.register(StackModel.self)
|
||||
mapping?.setObject(Stack<StackModel>.self, forKey: StackModel.identifier as NSString)
|
||||
ModelRegistry.register(StackItemModel.self)
|
||||
mapping?.setObject(StackItem.self, forKey: StackItemModel.identifier as NSString)
|
||||
ModelRegistry.register(StringAndMoleculeModel.self)
|
||||
mapping?.setObject(StringAndMoleculeView.self, forKey: StringAndMoleculeModel.identifier as NSString)
|
||||
ModelRegistry.register(UnOrderedListModel.self)
|
||||
mapping?.setObject(UnOrderedList.self, forKey: UnOrderedListModel.identifier as NSString)
|
||||
ModelRegistry.register(NumberedListModel.self)
|
||||
mapping?.setObject(NumberedList.self, forKey: NumberedListModel.identifier as NSString)
|
||||
|
||||
ModelRegistry.register(LabelModel.self)
|
||||
ModelRegistry.register(HeaderModel.self)
|
||||
ModelRegistry.register(FooterModel.self)
|
||||
ModelRegistry.register(HeadlineBodyModel.self)
|
||||
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: MoleculeStackView.self, viewModelClass: MoleculeStackModel.self)
|
||||
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Stack<StackModel>.self, viewModelClass: StackModel.self)
|
||||
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: MoleculeStackItem.self, viewModelClass: MoleculeStackItemModel.self)
|
||||
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: StackItem.self, viewModelClass: StackItemModel.self)
|
||||
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: StringAndMoleculeView.self, viewModelClass: StringAndMoleculeModel.self)
|
||||
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: UnOrderedList.self, viewModelClass: UnOrderedListModel.self)
|
||||
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: NumberedList.self, viewModelClass: NumberedListModel.self)
|
||||
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Label.self, viewModelClass: LabelModel.self)
|
||||
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: HeaderView.self, viewModelClass: HeaderModel.self)
|
||||
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: FooterView.self, viewModelClass: FooterModel.self)
|
||||
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: HeadlineBody.self, viewModelClass: HeadlineBodyModel.self)
|
||||
ModelRegistry.register(MoleculeStackItemModel.self)
|
||||
ModelRegistry.register(TextFieldModel.self)
|
||||
ModelRegistry.register(ProgressBarModel.self)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user