Removed container and added stackmodel

This commit is contained in:
Lekshmi S 2020-02-13 09:00:37 +05:30
parent 8ca1ebc6ad
commit c953981406
3 changed files with 35 additions and 39 deletions

View File

@ -781,6 +781,15 @@
name = "Recovered References";
sourceTree = "<group>";
};
AA4FC2A323F4F69600E251DB /* RightVariable */ = {
isa = PBXGroup;
children = (
AA11A41E23F15D3100D7962F /* ListRightVariablePayments.swift */,
AA11A42023F15D7000D7962F /* ListRightVariablePaymentsModel.swift */,
);
path = RightVariable;
sourceTree = "<group>";
};
D213347423842FE3008E41B3 /* Controllers */ = {
isa = PBXGroup;
children = (
@ -909,8 +918,6 @@
D28A839023CD4FD400DFE4FC /* CornerLabelsModel.swift */,
01509D902327ECE600EF99AA /* CornerLabels.swift */,
D224798823142BF2003FCCF9 /* ToggleMolecules */,
AA11A41E23F15D3100D7962F /* ListRightVariablePayments.swift */,
AA11A42023F15D7000D7962F /* ListRightVariablePaymentsModel.swift */,
);
path = LeftRightViews;
sourceTree = "<group>";
@ -964,6 +971,7 @@
D22B38EA23F4E08B00490EF6 /* List */ = {
isa = PBXGroup;
children = (
AA4FC2A323F4F69600E251DB /* RightVariable */,
D22B38EB23F4E0AE00490EF6 /* LeftVariable */,
);
path = List;

View File

@ -16,7 +16,7 @@ import Foundation
let leftLabel = Label.commonLabelB2(true)
let rightImage = MFLoadImageView()
let containerView = Container()
let stack = Stack<StackModel>(frame: .zero)
//------------------------------------------------------
// MARK: - Properties
@ -35,9 +35,7 @@ import Foundation
open override func updateView(_ size: CGFloat) {
super.updateView(size)
containerView.updateView(size)
leftLabel.updateView(size)
rightImage.updateView(size)
stack.updateView(size)
}
override open func setupView() {
@ -45,30 +43,12 @@ import Foundation
guard leftLabel.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(leftLabel)
containerView.addSubview(rightImage)
//leftLabel constraints
leftLabel.leadingAnchor.constraint(equalTo: containerView.leadingAnchor,constant: leftPadding).isActive = true
leftLabel.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
leftLabel.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true
//rightImage constraints
rightImage.leadingAnchor.constraint(greaterThanOrEqualTo: leftLabel.trailingAnchor,constant: spaceBetweenLabelAndImage).isActive = true
rightImage.centerYAnchor.constraint(equalTo: leftLabel.centerYAnchor).isActive = true
rightImage.widthAnchor.constraint(equalToConstant: imageWidth).isActive = true
rightImage.heightAnchor.constraint(equalToConstant: imageHeight).isActive = true
containerView.trailingAnchor.constraint(equalTo: rightImage.trailingAnchor,constant: rightPadding).isActive = true
stack.translatesAutoresizingMaskIntoConstraints = false
stack.stackItems = [StackItem(andContain: leftLabel),StackItem(andContain: rightImage)]
contentView.addSubview(stack)
containerHelper.constrainView(stack)
leftLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 901), for: .horizontal)
rightImage.setContentHuggingPriority(UILayoutPriority(rawValue: 902), for: .horizontal)
}
//----------------------------------------------------
@ -77,8 +57,7 @@ import Foundation
override open func reset() {
super.reset()
leftLabel.reset()
rightImage.reset()
stack.reset()
}
public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
@ -86,5 +65,15 @@ import Foundation
guard let model = model as? ListRightVariablePaymentsModel else { return}
leftLabel.setWithModel(model.leftLabel, delegateObject, additionalData)
rightImage.setWithModel(model.image, delegateObject, additionalData)
// Create a stack model to use for the internal stack and set the alignment of label and image
let leftLabel = StackItemModel()
leftLabel.horizontalAlignment = .fill
let rightImage = StackItemModel()
rightImage.horizontalAlignment = .trailing
let stackModel = StackModel(molecules: [leftLabel,rightLabel])
stackModel.axis = .horizontal
stack.model = stackModel
stack.restack()
}
}

View File

@ -11,7 +11,8 @@ import Foundation
public class ListRightVariablePaymentsModel: 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 = "listRVImg"
@ -25,11 +26,8 @@ public class ListRightVariablePaymentsModel: ContainerModel, ListItemModelProtoc
if useVerticalMargins == nil {
useVerticalMargins = true
}
if topMarginPadding == nil {
topMarginPadding = 24
}
if bottomMarginPadding == nil {
bottomMarginPadding = 0
if image.height == nil {
image.height = 16.0
}
}
@ -37,6 +35,7 @@ public class ListRightVariablePaymentsModel: ContainerModel, ListItemModelProtoc
self.image = image
self.leftLabel = leftLabel
super.init()
setDefaults()
}
private enum CodingKeys: String, CodingKey {
@ -58,7 +57,7 @@ public class ListRightVariablePaymentsModel: ContainerModel, ListItemModelProtoc
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(ListRightVariablePaymentsModel.identifier, forKey: .moleculeName)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(leftLabel, forKey: .leftLabel)
try container.encode(image, forKey: .image)
try container.encodeModelIfPresent(action, forKey: .action)