Added percent for stack items.

Removed conformance to ContainerModel and ListItemModelProtocol.
This commit is contained in:
Lekshmi S 2020-02-14 14:05:54 +05:30
parent 194c004f17
commit 69919f5beb
2 changed files with 4 additions and 38 deletions

View File

@ -54,11 +54,10 @@ import Foundation
eyebrowHeadlineBodyLink.setWithModel(model.eyebrowHeadlineBodyLink, delegateObject, additionalData)
// Create a stack model to use for the internal stack and set the alignment of labels
let checkbox = StackItemModel()
let checkbox = StackItemModel(percent: 10)
checkbox.horizontalAlignment = .leading
let eyebrowHeadlineBodyLink = StackItemModel()
eyebrowHeadlineBodyLink.horizontalAlignment = .leading
eyebrowHeadlineBodyLink.spacing = 20
let eyebrowHeadlineBodyLink = StackItemModel(percent: 90)
eyebrowHeadlineBodyLink.horizontalAlignment = .fill
let stackModel = StackModel(molecules: [checkbox,eyebrowHeadlineBodyLink])
stackModel.axis = .horizontal
stack.model = stackModel

View File

@ -8,33 +8,12 @@
import Foundation
public class ListLeftVariableCheckboxWithRightCaretAllTextAndLinksModel: ContainerModel, ListItemModelProtocol {
public class ListLeftVariableCheckboxWithRightCaretAllTextAndLinksModel: ListItemModel, MoleculeModelProtocol {
public var line: LineModel?
public var style: String? = "standard"
public var hideArrow: Bool? = false
public var backgroundColor: Color?
public var action: ActionModelProtocol?
public static var identifier: String = "listLVCB"
public var checkbox: CheckboxModel
public var spacing: CGFloat = 16.0
var eyebrowHeadlineBodyLink: EyebrowHeadlineBodyLinkModel
func setDefaults() {
if useHorizontalMargins == nil {
useHorizontalMargins = true
}
if useVerticalMargins == nil {
useVerticalMargins = true
}
if topMarginPadding == nil {
topMarginPadding = 24
}
if bottomMarginPadding == nil {
bottomMarginPadding = 0
}
}
init(checkbox: CheckboxModel, eyebrowHeadlineBodyLink: EyebrowHeadlineBodyLinkModel) {
self.checkbox = checkbox
self.eyebrowHeadlineBodyLink = eyebrowHeadlineBodyLink
@ -43,35 +22,23 @@ public class ListLeftVariableCheckboxWithRightCaretAllTextAndLinksModel: Contain
private enum CodingKeys: String, CodingKey {
case moleculeName
case backgroundColor
case eyebrowHeadlineBodyLink
case checkbox
case action
case spacing
}
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
eyebrowHeadlineBodyLink = try typeContainer.decode(EyebrowHeadlineBodyLinkModel.self, forKey: .eyebrowHeadlineBodyLink)
checkbox = try typeContainer.decode(CheckboxModel.self, forKey: .checkbox)
action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
if let spacing = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .spacing) {
self.spacing = spacing
}
try super.init(from: decoder)
setDefaults()
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encode(eyebrowHeadlineBodyLink, forKey: .eyebrowHeadlineBodyLink)
try container.encode(checkbox, forKey: .checkbox)
try container.encodeModelIfPresent(action, forKey: .action)
try container.encodeIfPresent(spacing, forKey: .spacing)
}
}