diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 79fb28b4..b209d013 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -781,6 +781,15 @@ name = "Recovered References"; sourceTree = ""; }; + AA4FC2A323F4F69600E251DB /* RightVariable */ = { + isa = PBXGroup; + children = ( + AA11A41E23F15D3100D7962F /* ListRightVariablePayments.swift */, + AA11A42023F15D7000D7962F /* ListRightVariablePaymentsModel.swift */, + ); + path = RightVariable; + sourceTree = ""; + }; 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 = ""; @@ -964,6 +971,7 @@ D22B38EA23F4E08B00490EF6 /* List */ = { isa = PBXGroup; children = ( + AA4FC2A323F4F69600E251DB /* RightVariable */, D22B38EB23F4E0AE00490EF6 /* LeftVariable */, ); path = List; diff --git a/MVMCoreUI/Molecules/LeftRightViews/ListRightVariablePayments.swift b/MVMCoreUI/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePayments.swift similarity index 52% rename from MVMCoreUI/Molecules/LeftRightViews/ListRightVariablePayments.swift rename to MVMCoreUI/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePayments.swift index 5eebb1e1..851a2137 100644 --- a/MVMCoreUI/Molecules/LeftRightViews/ListRightVariablePayments.swift +++ b/MVMCoreUI/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePayments.swift @@ -16,7 +16,7 @@ import Foundation let leftLabel = Label.commonLabelB2(true) let rightImage = MFLoadImageView() - let containerView = Container() + let stack = Stack(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() } } diff --git a/MVMCoreUI/Molecules/LeftRightViews/ListRightVariablePaymentsModel.swift b/MVMCoreUI/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePaymentsModel.swift similarity index 86% rename from MVMCoreUI/Molecules/LeftRightViews/ListRightVariablePaymentsModel.swift rename to MVMCoreUI/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePaymentsModel.swift index db4dabc4..ef0693d0 100644 --- a/MVMCoreUI/Molecules/LeftRightViews/ListRightVariablePaymentsModel.swift +++ b/MVMCoreUI/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePaymentsModel.swift @@ -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)