From 3fce526c90c556d72a6c8e391894e1ac899d7d8b Mon Sep 17 00:00:00 2001 From: Lekshmi S Date: Wed, 13 May 2020 15:52:50 +0530 Subject: [PATCH] Code changes for aligning rightlabel with leftheadline. --- .../List/ListProgressBarThin.swift | 30 +++++++++++++++---- .../List/ListProgressBarThinModel.swift | 3 ++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListProgressBarThin.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListProgressBarThin.swift index 69e26ea2..73561ec1 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListProgressBarThin.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListProgressBarThin.swift @@ -17,6 +17,8 @@ import Foundation let leftBody2 = Label.commonLabelB2(true) let bar = Line() let rightLabel = Label.commonLabelB2(true) + private let barStackItem: StackItem + private let rightLabelStackItem: StackItem public var horizontalStack: Stack public var verticalStack: Stack public var stack: Stack @@ -25,14 +27,25 @@ import Foundation // MARK: - Initializers //------------------------------------------------------ public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { - verticalStack = Stack.createStack(with: [(view: leftHeadline, model: StackItemModel(horizontalAlignment: .leading)), - (view: leftBody, model: StackItemModel(horizontalAlignment: .leading)), - (view: leftBody2, model: StackItemModel(horizontalAlignment: .leading))], + //vertical stack with leftHeadline, leftBody, leftBody2 + let verticalStackModel = StackModel(molecules: [StackItemModel(horizontalAlignment: .leading, verticalAlignment: .leading), StackItemModel(horizontalAlignment: .leading), StackItemModel(horizontalAlignment: .leading)], axis: .vertical, spacing: 0) - horizontalStack = Stack.createStack(with: [(view: verticalStack, model: StackItemModel(horizontalAlignment: .leading, verticalAlignment: .leading)), - (view: bar, model: StackItemModel(horizontalAlignment: .fill)), (view: rightLabel, model: StackItemModel(spacing: 5, horizontalAlignment: .fill))], + let verticalStackItems = [StackItem(andContain: leftHeadline), StackItem(andContain: leftBody), StackItem(andContain: leftBody2)] + verticalStack = Stack(with: verticalStackModel, stackItems: verticalStackItems) + + //horizontal stack with leftHeadline, leftBody, leftBody2, bar, rightLabel + let horizontalStackModel = StackModel(molecules: [StackItemModel(horizontalAlignment: .leading), StackItemModel(horizontalAlignment: .fill), StackItemModel(spacing: 5, horizontalAlignment: .fill)], axis: .horizontal) - stack = Stack.createStack(with: [(view: horizontalStack, model: StackItemModel(horizontalAlignment: .fill)), (view: progressBar, model: StackItemModel(spacing: 20, horizontalAlignment: .fill))], axis: .vertical) + barStackItem = StackItem(andContain: bar) + rightLabelStackItem = StackItem(andContain: rightLabel) + let horizontalStackItems = [StackItem(andContain: verticalStack), barStackItem, rightLabelStackItem] + horizontalStack = Stack(with: horizontalStackModel, stackItems: horizontalStackItems) + + //stack with all components + let stackModel = StackModel(molecules: [StackItemModel(horizontalAlignment: .fill), + StackItemModel(spacing: 20, horizontalAlignment: .fill)], axis: .vertical) + let stackItems = [StackItem(andContain: horizontalStack), StackItem(andContain: progressBar)] + stack = Stack(with: stackModel, stackItems: stackItems) super.init(style: style, reuseIdentifier: reuseIdentifier) } @@ -42,6 +55,11 @@ import Foundation open override func alignAccessoryToHero() -> CGPoint? { let heroCenter = super.alignAccessoryToHero() + if let heroCenter = heroCenter { + let convertedPoint = horizontalStack.convert(heroCenter, from: self) + barStackItem.containerHelper.alignCenterVerticalConstraint?.constant = convertedPoint.y - horizontalStack.bounds.midY + rightLabelStackItem.containerHelper.alignCenterVerticalConstraint?.constant = convertedPoint.y - horizontalStack.bounds.midY + } return heroCenter } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListProgressBarThinModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListProgressBarThinModel.swift index 2e0b7cdb..7bed74b1 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListProgressBarThinModel.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListProgressBarThinModel.swift @@ -32,6 +32,9 @@ public class ListProgressBarThinModel: ListItemModel, MoleculeModelProtocol { if bar.backgroundColor == nil { bar.backgroundColor = Color(uiColor: .gray) } + if let leftHeadline = leftHeadline { + leftHeadline.hero = 0 + } } private enum CodingKeys: String, CodingKey {