button size
This commit is contained in:
parent
7255c0c354
commit
fc2326e9a8
@ -13,12 +13,18 @@ public enum ButtonStyle: String, Codable {
|
||||
case secondary
|
||||
}
|
||||
|
||||
public enum ButtonSize: String, Codable {
|
||||
case standard
|
||||
case tiny
|
||||
}
|
||||
|
||||
public class ButtonModel: MoleculeProtocol {
|
||||
public static var identifier: String = "button"
|
||||
public var backgroundColor: Color?
|
||||
public var title: String
|
||||
public var action: ActionProtocol
|
||||
public var style: ButtonStyle?
|
||||
public var style: ButtonStyle? = .primary
|
||||
public var size: ButtonSize? = .standard
|
||||
|
||||
init(with title: String, action: ActionProtocol) {
|
||||
self.title = title
|
||||
@ -30,6 +36,7 @@ public class ButtonModel: MoleculeProtocol {
|
||||
case title
|
||||
case action
|
||||
case style
|
||||
case size
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
@ -37,7 +44,12 @@ public class ButtonModel: MoleculeProtocol {
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
title = try typeContainer.decode(String.self, forKey: .title)
|
||||
action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
|
||||
style = try typeContainer.decodeIfPresent(ButtonStyle.self, forKey: .style)
|
||||
if let style = try typeContainer.decodeIfPresent(ButtonStyle.self, forKey: .style) {
|
||||
self.style = style
|
||||
}
|
||||
if let size = try typeContainer.decodeIfPresent(ButtonSize.self, forKey: .size) {
|
||||
self.size = size
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
@ -46,5 +58,6 @@ public class ButtonModel: MoleculeProtocol {
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encodeModel(action, forKey: .action)
|
||||
try container.encodeIfPresent(style, forKey: .style)
|
||||
try container.encodeIfPresent(size, forKey: .size)
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,14 @@ extension PrimaryButton: ModelMoleculeViewProtocol {
|
||||
setAsSecondaryCustom()
|
||||
}
|
||||
}
|
||||
if let size = model.size {
|
||||
switch size {
|
||||
case .standard:
|
||||
setAsTiny(false)
|
||||
case .tiny:
|
||||
setAsTiny(true)
|
||||
}
|
||||
}
|
||||
set(with: model.action, delegateObject: delegateObject, additionalData: additionalData)
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,6 +46,18 @@ import UIKit
|
||||
self.backgroundColor = backgroundColor.uiColor
|
||||
}
|
||||
}
|
||||
|
||||
public class func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||
return model?.moleculeName
|
||||
}
|
||||
|
||||
public class func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||
return nil
|
||||
}
|
||||
|
||||
public class func requiredModules(_ molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// MARK:- MVMCoreViewProtocol
|
||||
|
||||
@ -27,7 +27,6 @@ import MVMCore
|
||||
|
||||
/// Defaults to set
|
||||
func setDefaults() {
|
||||
style = "standard"
|
||||
if useHorizontalMargins == nil {
|
||||
useHorizontalMargins = true
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ import UIKit
|
||||
super.setWithModel(model, delegateObject, additionalData)
|
||||
}
|
||||
|
||||
public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||
public class override func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||
return 30
|
||||
}
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ open class ModuleMolecule: Container {
|
||||
}
|
||||
}
|
||||
|
||||
public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||
public override class func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||
|
||||
guard let moduleMolecule = molecule as? ModuleMoleculeModel,
|
||||
let moduleModel = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMolecule.moduleName),
|
||||
@ -58,7 +58,7 @@ open class ModuleMolecule: Container {
|
||||
return height
|
||||
}
|
||||
|
||||
public class func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||
public override class func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||
guard let moduleMolecule = model as? ModuleMoleculeModel,
|
||||
let moduleModel = delegateObject?.moleculeDelegate?.getModuleWithName(moduleMolecule.moduleName),
|
||||
let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moduleModel) as? ModelMoleculeViewProtocol.Type,
|
||||
@ -69,7 +69,7 @@ open class ModuleMolecule: Container {
|
||||
return name
|
||||
}
|
||||
|
||||
public static func requiredModules(_ molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
|
||||
public override class func requiredModules(_ molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
|
||||
|
||||
guard let moduleName = (molecule as? ModuleMoleculeModel)?.moduleName,
|
||||
let _ = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else {
|
||||
|
||||
@ -85,7 +85,7 @@ struct EyebrowHeadlineBodyLinkModel: MoleculeProtocol {
|
||||
body.styleB2(true)
|
||||
}
|
||||
|
||||
public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||
public override class func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||
return 65
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,7 +111,18 @@ open class MoleculeStackView: Container {
|
||||
stackModel?.useVerticalMargins = moleculesShouldSetVerticalMargins
|
||||
}
|
||||
|
||||
public class func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||
if model == nil {
|
||||
let data = try! JSONSerialization.data(withJSONObject: json!)
|
||||
let decoder = JSONDecoder()
|
||||
let model = try! decoder.decode(MoleculeStackModel.self, from: data)
|
||||
setWithModel(model, delegateObject, additionalData)
|
||||
} else {
|
||||
setWithModel(model, delegateObject, additionalData)
|
||||
}
|
||||
}
|
||||
|
||||
public override class func nameForReuse(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||
// This will aggregate names of molecules to make an id.
|
||||
guard let model = model as? MoleculeStackModel else {
|
||||
return "stack<>"
|
||||
@ -131,17 +142,6 @@ open class MoleculeStackView: Container {
|
||||
return name
|
||||
}
|
||||
|
||||
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||
if model == nil {
|
||||
let data = try! JSONSerialization.data(withJSONObject: json!)
|
||||
let decoder = JSONDecoder()
|
||||
let model = try! decoder.decode(MoleculeStackModel.self, from: data)
|
||||
setWithModel(model, delegateObject, additionalData)
|
||||
} else {
|
||||
setWithModel(model, delegateObject, additionalData)
|
||||
}
|
||||
}
|
||||
|
||||
public class func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||
// This will aggregate names of molecules to make an id.
|
||||
guard let molecules = molecule?.optionalArrayForKey(KeyMolecules) else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user