Removed container and added stackmodel code changes.

This commit is contained in:
Lekshmi S 2020-02-14 10:17:54 +05:30
parent cadf70ce70
commit 5b1b29c10d
2 changed files with 31 additions and 40 deletions

View File

@ -16,17 +16,7 @@ import Foundation
let checkbox = Checkbox(frame: .zero)
let eyebrowHeadlineBodyLink = EyebrowHeadlineBodyLink(frame: .zero)
let containerView = Container()
//------------------------------------------------------
// MARK: - Properties
//------------------------------------------------------
let cellHeight: CGFloat = 125.0
let leftPadding: CGFloat = 35.0
let rightPadding: CGFloat = 35.0
let spaceBetweenCheckBoxAndEyebrowHedline: CGFloat = 16.0
let checkBoxSize: CGFloat = 18.0
let stack = Stack<StackModel>(frame: .zero)
//-----------------------------------------------------
// MARK: - View Lifecycle
@ -34,9 +24,7 @@ import Foundation
open override func updateView(_ size: CGFloat) {
super.updateView(size)
containerView.updateView(size)
checkbox.updateView(size)
eyebrowHeadlineBodyLink.updateView(size)
stack.updateView(size)
}
override open func setupView() {
@ -44,28 +32,10 @@ import Foundation
guard checkbox.superview == nil else {
return
}
containerView.translatesAutoresizingMaskIntoConstraints = false
contentView.heightAnchor.constraint(equalToConstant: cellHeight).isActive = true
contentView.addSubview(containerView)
//containerView constraints
containerView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
containerView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
containerView.topAnchor.constraint(equalTo: topAnchor).isActive = true
containerView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
containerView.addSubview(checkbox)
containerView.addSubview(eyebrowHeadlineBodyLink)
//checkBox constraints
checkbox.centerYAnchor.constraint(equalTo: eyebrowHeadlineBodyLink.centerYAnchor).isActive = true
checkbox.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: leftPadding).isActive = true
//eyebrowHeadlineBodyLink constraints
eyebrowHeadlineBodyLink.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
eyebrowHeadlineBodyLink.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true
eyebrowHeadlineBodyLink.leadingAnchor.constraint(equalTo: checkbox.trailingAnchor, constant: spaceBetweenCheckBoxAndEyebrowHedline).isActive = true
eyebrowHeadlineBodyLink.trailingAnchor.constraint(equalTo: containerView.trailingAnchor).isActive = true
stack.translatesAutoresizingMaskIntoConstraints = false
stack.stackItems = [StackItem(andContain: checkbox),StackItem(andContain: eyebrowHeadlineBodyLink)]
contentView.addSubview(stack)
containerHelper.constrainView(stack)
}
//----------------------------------------------------
@ -74,8 +44,7 @@ import Foundation
override open func reset() {
super.reset()
checkbox.reset()
eyebrowHeadlineBodyLink.reset()
stack.reset()
}
public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
@ -83,5 +52,16 @@ import Foundation
guard let model = model as? ListLeftVariableCheckboxWithRightCaretAllTextAndLinksModel else { return}
checkbox.setWithModel(model.checkbox, delegateObject, additionalData)
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()
checkbox.horizontalAlignment = .leading
let eyebrowHeadlineBodyLink = StackItemModel()
eyebrowHeadlineBodyLink.horizontalAlignment = .leading
eyebrowHeadlineBodyLink.spacing = 20
let stackModel = StackModel(molecules: [checkbox,eyebrowHeadlineBodyLink])
stackModel.axis = .horizontal
stack.model = stackModel
stack.restack()
}
}

View File

@ -11,10 +11,13 @@ import Foundation
public class ListLeftVariableCheckboxWithRightCaretAllTextAndLinksModel: ContainerModel, ListItemModelProtocol {
public var line: LineModel?
public var hideArrow: Bool?
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() {
@ -43,6 +46,8 @@ public class ListLeftVariableCheckboxWithRightCaretAllTextAndLinksModel: Contain
case backgroundColor
case eyebrowHeadlineBodyLink
case checkbox
case action
case spacing
}
required public init(from decoder: Decoder) throws {
@ -50,6 +55,10 @@ public class ListLeftVariableCheckboxWithRightCaretAllTextAndLinksModel: Contain
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()
}
@ -57,10 +66,12 @@ public class ListLeftVariableCheckboxWithRightCaretAllTextAndLinksModel: Contain
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(ListLeftVariableCheckboxWithRightCaretAllTextAndLinksModel.identifier, forKey: .moleculeName)
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)
}
}