This commit is contained in:
Suresh, Kamlesh 2019-12-03 09:19:55 -05:00
parent 0648ec0191
commit d00a04831d
2 changed files with 40 additions and 17 deletions

View File

@ -11,28 +11,38 @@ import Foundation
@objcMembers public class HeadlineBodyModel: MoleculeProtocol { @objcMembers public class HeadlineBodyModel: MoleculeProtocol {
public static var identifier: String = "headlineBody" public static var identifier: String = "headlineBody"
public var moleculeName: String? public var moleculeName: String?
public var headline: LabelModel? public var style: String?
public var headline: LabelModel
public var body: LabelModel
public init(headline: LabelModel?) { public init(style: String?, headline: LabelModel, body: LabelModel) {
self.headline = headline
self.moleculeName = Self.identifier self.moleculeName = Self.identifier
self.style = style
self.headline = headline
self.body = body
} }
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
case style
case headline case headline
case body
} }
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName) self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName)
self.headline = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .headline) self.headline = try typeContainer.decode(LabelModel.self, forKey: .headline)
self.body = try typeContainer.decode(LabelModel.self, forKey: .body)
self.style = try typeContainer.decodeIfPresent(String.self, forKey: .style)
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(self.headline, forKey: .headline) try container.encode(headline, forKey: .headline)
try container.encode(body, forKey: .body)
try container.encodeIfPresent(self.style, forKey: .style)
} }
} }

View File

@ -8,7 +8,7 @@
import UIKit import UIKit
open class HeadlineBody: ViewConstrainingView { open class HeadlineBody: ViewConstrainingView, ModelMoleculeViewProtocol {
let headlineLabel = Label.commonLabelH2(true) let headlineLabel = Label.commonLabelH2(true)
let messageLabel = Label.commonLabelB2(true) let messageLabel = Label.commonLabelB2(true)
var spaceBetweenLabelsConstant = PaddingTwo var spaceBetweenLabelsConstant = PaddingTwo
@ -118,18 +118,31 @@ open class HeadlineBody: ViewConstrainingView {
spaceBetweenLabels?.constant = 0 spaceBetweenLabels?.constant = 0
} }
} }
// MARK: - MVMCoreUIMoleculeViewProtocol public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) {
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) setUpWithModel(model, delegateObject, additionalData)
guard let headlineBodyModel = model as? HeadlineBodyModel else {
style(with: json?.optionalStringForKey("style")) return
}
let headlineJSON = json?.optionalDictionaryForKey("headline")
headlineLabel.setWithJSON(headlineJSON, delegateObject: delegateObject, additionalData: additionalData) style(with: headlineBodyModel.style)
let bodyJSON = json?.optionalDictionaryForKey("body")
messageLabel.setWithJSON(bodyJSON, delegateObject: delegateObject, additionalData: additionalData) headlineLabel.setWithModel(headlineBodyModel.headline, delegateObject, additionalData)
messageLabel.setWithModel(headlineBodyModel.body, delegateObject, additionalData)
} }
// // MARK: - MVMCoreUIMoleculeViewProtocol
// open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
// super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
//
// style(with: json?.optionalStringForKey("style"))
//
// let headlineJSON = json?.optionalDictionaryForKey("headline")
// headlineLabel.setWithJSON(headlineJSON, delegateObject: delegateObject, additionalData: additionalData)
//
// let bodyJSON = json?.optionalDictionaryForKey("body")
// messageLabel.setWithJSON(bodyJSON, delegateObject: delegateObject, additionalData: additionalData)
// }
open override func reset() { open override func reset() {
super.reset() super.reset()