From c30a0012394b1b1f855243e62817872532aa643d Mon Sep 17 00:00:00 2001 From: Subhankar Acharya Date: Wed, 12 Feb 2020 23:01:02 +0530 Subject: [PATCH] Code Changes after reimplementing the molecule class. --- .../Molecules/Items/StackItemModel.swift | 2 +- .../ListLeftVariableIconWithRightCaret.swift | 70 ++++++------------- ...tLeftVariableIconWithRightCaretModel.swift | 8 +-- 3 files changed, 25 insertions(+), 55 deletions(-) diff --git a/MVMCoreUI/Molecules/Items/StackItemModel.swift b/MVMCoreUI/Molecules/Items/StackItemModel.swift index f296986e..9d193f17 100644 --- a/MVMCoreUI/Molecules/Items/StackItemModel.swift +++ b/MVMCoreUI/Molecules/Items/StackItemModel.swift @@ -8,7 +8,7 @@ import Foundation -@objcMembers public class StackItemModel: StackItemModelProtocol, MoleculeModelProtocol { +@objcMembers public class StackItemModel: ContainerModel, StackItemModelProtocol, MoleculeModelProtocol { public static var identifier: String = "simpleStackItem" public var backgroundColor: Color? public var spacing: CGFloat? diff --git a/MVMCoreUI/Molecules/LeftRightViews/ListLeftVariableIconWithRightCaret.swift b/MVMCoreUI/Molecules/LeftRightViews/ListLeftVariableIconWithRightCaret.swift index 43a3b5da..9cdf9cee 100644 --- a/MVMCoreUI/Molecules/LeftRightViews/ListLeftVariableIconWithRightCaret.swift +++ b/MVMCoreUI/Molecules/LeftRightViews/ListLeftVariableIconWithRightCaret.swift @@ -14,30 +14,15 @@ import UIKit //----------------------------------------------------- // MARK: - Outlets //------------------------------------------------------- - let leftImage = MFLoadImageView() let leftLabel = Label.commonLabelB2(true) let rightLabel = Label.commonLabelB2(true) - let containerView = Container() - - //------------------------------------------------------ - // MARK: - Properties - //------------------------------------------------------ - - let cellHeight: CGFloat = 79 - let leftPadding: CGFloat = 35 - let spaceBetweenImageAndLeftLabel: CGFloat = 16 - let imageSize: CGFloat = 30 - let spaceBetweenLabels: CGFloat = 40 - let horizontalPadding = MFStyler.defaultHorizontalPaddingForApplicationWidth() - + let stack = Stack(frame: .zero) //----------------------------------------------------- // MARK: - View Lifecycle //------------------------------------------------------- - open override func updateView(_ size: CGFloat) { super.updateView(size) - containerView.updateView(size) leftImage.updateView(size) leftLabel.updateView(size) rightLabel.updateView(size) @@ -48,48 +33,23 @@ import UIKit guard leftImage.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(leftImage) - containerView.addSubview(leftLabel) - containerView.addSubview(rightLabel) - - //leftImage constraints - leftImage.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: horizontalPadding).isActive = true - leftImage.centerYAnchor.constraint(equalTo: leftLabel.centerYAnchor).isActive = true - leftImage.widthAnchor.constraint(equalToConstant: imageSize).isActive = true - leftImage.heightAnchor.constraint(equalToConstant: imageSize).isActive = true - - - //leftLabel constraints - leftLabel.leadingAnchor.constraint(equalTo: leftImage.trailingAnchor, constant: spaceBetweenImageAndLeftLabel).isActive = true - leftLabel.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true - leftLabel.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true - - //rightLabel constraints - rightLabel.leadingAnchor.constraint(greaterThanOrEqualTo: leftLabel.trailingAnchor, constant: spaceBetweenLabels).isActive = true - rightLabel.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true - rightLabel.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true - rightLabel.trailingAnchor.constraint(equalTo: containerView.trailingAnchor,constant: -horizontalPadding - 20).isActive = true + stack.translatesAutoresizingMaskIntoConstraints = false + stack.stackItems = [StackItem(andContain: leftImage),StackItem(andContain: leftLabel),StackItem(andContain: rightLabel)] + contentView.addSubview(stack) + containerHelper.constrainView(stack) + leftLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 901), for: .horizontal) + rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 902), for: .horizontal) + } - //---------------------------------------------------- // MARK: - Molecule //------------------------------------------------------ - override open func reset() { super.reset() leftImage.reset() leftLabel.reset() rightLabel.reset() + stack.reset() } public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { @@ -98,5 +58,17 @@ import UIKit leftImage.setWithModel(model.image, delegateObject, additionalData) leftLabel.setWithModel(model.leftLabel, delegateObject, additionalData) rightLabel.setWithModel(model.rightLabel, delegateObject, additionalData) + + // Create a stack model to use for the internal stack and set the alignment of labels + let leftImage = StackItemModel() + leftImage.horizontalAlignment = .fill + let leftLabel = StackItemModel() + leftLabel.horizontalAlignment = .fill + let rightLabel = StackItemModel() + rightLabel.horizontalAlignment = .trailing + let stackModel = StackModel(molecules: [leftImage,leftLabel,rightLabel]) + stackModel.axis = .horizontal + stack.model = stackModel + stack.restack() } } diff --git a/MVMCoreUI/Molecules/LeftRightViews/ListLeftVariableIconWithRightCaretModel.swift b/MVMCoreUI/Molecules/LeftRightViews/ListLeftVariableIconWithRightCaretModel.swift index b29affb8..1ad7afbc 100644 --- a/MVMCoreUI/Molecules/LeftRightViews/ListLeftVariableIconWithRightCaretModel.swift +++ b/MVMCoreUI/Molecules/LeftRightViews/ListLeftVariableIconWithRightCaretModel.swift @@ -11,6 +11,7 @@ import Foundation public class ListLeftVariableIconWithRightCaretModel: ContainerModel, ListItemModelProtocol { public var line: LineModel? + public var style: String? = "standard" public var hideArrow: Bool? = false public var backgroundColor: Color? public var action: ActionModelProtocol? @@ -26,11 +27,8 @@ public class ListLeftVariableIconWithRightCaretModel: ContainerModel, ListItemMo if useVerticalMargins == nil { useVerticalMargins = true } - if topMarginPadding == nil { - topMarginPadding = 24 - } - if bottomMarginPadding == nil { - bottomMarginPadding = 0 + if image.height == nil { + image.height = 30.0 } }