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

View File

@ -16,7 +16,7 @@ import Foundation
let leftLabel = Label.commonLabelB2(true) let leftLabel = Label.commonLabelB2(true)
let rightImage = MFLoadImageView() let rightImage = MFLoadImageView()
let containerView = Container() let stack = Stack<StackModel>(frame: .zero)
//------------------------------------------------------ //------------------------------------------------------
// MARK: - Properties // MARK: - Properties
@ -35,9 +35,7 @@ import Foundation
open override func updateView(_ size: CGFloat) { open override func updateView(_ size: CGFloat) {
super.updateView(size) super.updateView(size)
containerView.updateView(size) stack.updateView(size)
leftLabel.updateView(size)
rightImage.updateView(size)
} }
override open func setupView() { override open func setupView() {
@ -45,30 +43,12 @@ import Foundation
guard leftLabel.superview == nil else { guard leftLabel.superview == nil else {
return return
} }
containerView.translatesAutoresizingMaskIntoConstraints = false stack.translatesAutoresizingMaskIntoConstraints = false
contentView.heightAnchor.constraint(equalToConstant: cellHeight).isActive = true stack.stackItems = [StackItem(andContain: leftLabel),StackItem(andContain: rightImage)]
contentView.addSubview(containerView) contentView.addSubview(stack)
containerHelper.constrainView(stack)
//containerView constraints leftLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 901), for: .horizontal)
containerView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true rightImage.setContentHuggingPriority(UILayoutPriority(rawValue: 902), for: .horizontal)
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
} }
//---------------------------------------------------- //----------------------------------------------------
@ -77,8 +57,7 @@ import Foundation
override open func reset() { override open func reset() {
super.reset() super.reset()
leftLabel.reset() stack.reset()
rightImage.reset()
} }
public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { 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} guard let model = model as? ListRightVariablePaymentsModel else { return}
leftLabel.setWithModel(model.leftLabel, delegateObject, additionalData) leftLabel.setWithModel(model.leftLabel, delegateObject, additionalData)
rightImage.setWithModel(model.image, 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 class ListRightVariablePaymentsModel: ContainerModel, ListItemModelProtocol {
public var line: LineModel? public var line: LineModel?
public var hideArrow: Bool? public var style: String? = "standard"
public var hideArrow: Bool? = false
public var backgroundColor: Color? public var backgroundColor: Color?
public var action: ActionModelProtocol? public var action: ActionModelProtocol?
public static var identifier: String = "listRVImg" public static var identifier: String = "listRVImg"
@ -25,11 +26,8 @@ public class ListRightVariablePaymentsModel: ContainerModel, ListItemModelProtoc
if useVerticalMargins == nil { if useVerticalMargins == nil {
useVerticalMargins = true useVerticalMargins = true
} }
if topMarginPadding == nil { if image.height == nil {
topMarginPadding = 24 image.height = 16.0
}
if bottomMarginPadding == nil {
bottomMarginPadding = 0
} }
} }
@ -37,6 +35,7 @@ public class ListRightVariablePaymentsModel: ContainerModel, ListItemModelProtoc
self.image = image self.image = image
self.leftLabel = leftLabel self.leftLabel = leftLabel
super.init() super.init()
setDefaults()
} }
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
@ -58,7 +57,7 @@ public class ListRightVariablePaymentsModel: ContainerModel, ListItemModelProtoc
public override func encode(to encoder: Encoder) throws { public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder) try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self) 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(leftLabel, forKey: .leftLabel)
try container.encode(image, forKey: .image) try container.encode(image, forKey: .image)
try container.encodeModelIfPresent(action, forKey: .action) try container.encodeModelIfPresent(action, forKey: .action)