From 9cff0f15f7bacca7951f0bee3d22f7336cde8b04 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Sat, 18 Apr 2020 19:09:19 -0400 Subject: [PATCH] hero fixes headlineBody update instead of eyebrowheadlinebody --- MVMCoreUI.xcodeproj/project.pbxproj | 4 +-- ...htVariablePriceChangeAllTextAndLinks.swift | 13 ++++----- ...iablePriceChangeAllTextAndLinksModel.swift | 1 - ...ListRightVariablePriceChangeBodyText.swift | 27 ++++++++++++------- ...ightVariablePriceChangeBodyTextModel.swift | 20 +++++++++----- MVMCoreUI/BaseClasses/TableViewCell.swift | 12 +++++---- 6 files changed, 47 insertions(+), 30 deletions(-) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 227863dc..00550bbe 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -1103,8 +1103,6 @@ AA4FC2A323F4F69600E251DB /* RightVariable */ = { isa = PBXGroup; children = ( - BB55B51E244482D2002001AD /* ListRightVariablePriceChangeBodyTextModel.swift */, - BB55B51C244482C0002001AD /* ListRightVariablePriceChangeBodyText.swift */, BB54C51F2434D92F0038326C /* ListRightVariableButtonAllTextAndLinksModel.swift */, BB54C51E2434D92F0038326C /* ListRightVariableButtonAllTextAndLinks.swift */, BB2C968D24330EA7006FF80C /* ListRightVariableTextLinkAllTextAndLinksModel.swift */, @@ -1113,6 +1111,8 @@ AA11A41E23F15D3100D7962F /* ListRightVariablePayments.swift */, 8D070BAF241B56530099AC56 /* ListRightVariableTotalDataModel.swift */, 8D070BB1241B56AD0099AC56 /* ListRightVariableTotalData.swift */, + BB55B51E244482D2002001AD /* ListRightVariablePriceChangeBodyTextModel.swift */, + BB55B51C244482C0002001AD /* ListRightVariablePriceChangeBodyText.swift */, 8D8067D02444472F00203BE8 /* ListRightVariablePriceChangeAllTextAndLinksModel.swift */, 8D8067D22444473A00203BE8 /* ListRightVariablePriceChangeAllTextAndLinks.swift */, C7F8012223E846C300396FBD /* ListRVWheelModel.swift */, diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeAllTextAndLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeAllTextAndLinks.swift index f13d9f4c..7a74de6e 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeAllTextAndLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeAllTextAndLinks.swift @@ -8,7 +8,7 @@ import Foundation -@objcMembers public class ListRightVariablePriceChangeAllTextAndLinks: TableViewCell { +@objcMembers open class ListRightVariablePriceChangeAllTextAndLinks: TableViewCell { //----------------------------------------------------- // MARK: - Outlets @@ -26,7 +26,7 @@ import Foundation public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { let stackModel = StackModel(molecules: [StackItemModel(horizontalAlignment: .leading), StackItemModel(horizontalAlignment: .fill), - StackItemModel(spacing: 8, horizontalAlignment: .fill)], + StackItemModel(spacing: 6, horizontalAlignment: .fill)], axis: .horizontal) arrowStackItem = StackItem(andContain: arrow) rightLabelStackItem = StackItem(andContain: rightLabel) @@ -43,18 +43,19 @@ import Foundation // MARK: - View Lifecycle //----------------------------------------------------- - public override func alignAccessoryToHero() { - super.alignAccessoryToHero() + open override func alignAccessoryToHero() -> CGPoint? { + let heroCenter = super.alignAccessoryToHero() // Aligns the center of the right side items to the headline. - if let heroCenter = heroAccessoryCenter { + if let heroCenter = heroCenter { let convertedPoint = stack.convert(heroCenter, from: self) arrowStackItem.containerHelper.alignCenterVerticalConstraint?.constant = convertedPoint.y - stack.bounds.midY rightLabelStackItem.containerHelper.alignCenterVerticalConstraint?.constant = convertedPoint.y - stack.bounds.midY } + return heroCenter } - override open func setupView() { + open override func setupView() { super.setupView() rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal) rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 900), for: .horizontal) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeAllTextAndLinksModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeAllTextAndLinksModel.swift index c048c973..ae4be269 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeAllTextAndLinksModel.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeAllTextAndLinksModel.swift @@ -9,7 +9,6 @@ import Foundation public class ListRightVariablePriceChangeAllTextAndLinksModel: ListItemModel, MoleculeModelProtocol { - public static var identifier: String = "listRVArwAll" public var eyebrowHeadlineBodyLink: EyebrowHeadlineBodyLinkModel public var rightLabel: LabelModel diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeBodyText.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeBodyText.swift index c62a7eaf..2b87294a 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeBodyText.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeBodyText.swift @@ -12,19 +12,20 @@ import Foundation //----------------------------------------------------- // MARK: - Outlets //----------------------------------------------------- - public var stack: Stack - public let headlineBodyLink = EyebrowHeadlineBodyLink(frame: .zero) - public let rightLabel = Label.commonLabelB2(true) + private let stack: Stack + public let headlineBody = HeadlineBody(frame: .zero) public let arrow = Arrow(frame: .zero) + public let rightLabel = Label.commonLabelB2(true) let arrowAndRightLabelStack: Stack + // MARK: - Initializers public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { arrowAndRightLabelStack = Stack.createStack(with: [(view: arrow, model: StackItemModel(horizontalAlignment: .fill)), - (view: rightLabel, model: StackItemModel(horizontalAlignment: .leading))], + (view: rightLabel, model: StackItemModel(horizontalAlignment: .fill))], axis: .horizontal, spacing: 6) - stack = Stack.createStack(with: [(view: headlineBodyLink, model: StackItemModel(percent:70,horizontalAlignment: .leading)), - (view: arrowAndRightLabelStack, model: StackItemModel(percent:30,horizontalAlignment: .trailing,verticalAlignment: .top))], + stack = Stack.createStack(with: [(view: headlineBody, model: StackItemModel(horizontalAlignment: .leading)), + (view: arrowAndRightLabelStack, model: StackItemModel(horizontalAlignment: .fill, verticalAlignment: .leading))], axis: .horizontal) super.init(style: style, reuseIdentifier: reuseIdentifier) } @@ -36,8 +37,14 @@ import Foundation //----------------------------------------------------- // MARK: - View Lifecycle //----------------------------------------------------- - override open func setupView() { + open override func setupView() { super.setupView() + headlineBody.styleListItem() + + rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal) + rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 900), for: .horizontal) + rightLabel.numberOfLines = 1 + arrow.pinHeightAndWidth() addMolecule(stack) stack.restack() @@ -47,17 +54,17 @@ import Foundation open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { super.set(with: model, delegateObject, additionalData) guard let model = model as? ListRightVariablePriceChangeBodyTextModel else { return } - headlineBodyLink.set(with: model.eyebrowHeadlineBodyLink, delegateObject, additionalData) + headlineBody.set(with: model.headlineBody, delegateObject, additionalData) rightLabel.set(with: model.rightLabel, delegateObject, additionalData) arrow.set(with: model.arrow, delegateObject, additionalData) } open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { - return 120 + return 80 } open override func reset() { super.reset() - rightLabel.styleB2(true) + headlineBody.styleListItem() } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeBodyTextModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeBodyTextModel.swift index e2d90eb7..7bf118df 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeBodyTextModel.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeBodyTextModel.swift @@ -9,27 +9,35 @@ import Foundation public class ListRightVariablePriceChangeBodyTextModel: ListItemModel, MoleculeModelProtocol { public static var identifier: String = "listRVArwBdy" - public var eyebrowHeadlineBodyLink: EyebrowHeadlineBodyLinkModel + public var headlineBody: HeadlineBodyModel public var rightLabel: LabelModel public var arrow: ArrowModel - public init(eyebrowHeadlineBodyLink: EyebrowHeadlineBodyLinkModel,rightLabel: LabelModel,arrow: ArrowModel) { - self.eyebrowHeadlineBodyLink = eyebrowHeadlineBodyLink + public init(headlineBody: HeadlineBodyModel,rightLabel: LabelModel,arrow: ArrowModel) { + self.headlineBody = headlineBody self.rightLabel = rightLabel self.arrow = arrow super.init() } + /// Defaults to set + public override func setDefaults() { + super.setDefaults() + if let headline = headlineBody.headline { + headline.hero = 0 + } + } + private enum CodingKeys: String, CodingKey { case moleculeName - case eyebrowHeadlineBodyLink + case headlineBody case rightLabel case arrow } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - eyebrowHeadlineBodyLink = try typeContainer.decode(EyebrowHeadlineBodyLinkModel.self, forKey: .eyebrowHeadlineBodyLink) + headlineBody = try typeContainer.decode(HeadlineBodyModel.self, forKey: .headlineBody) rightLabel = try typeContainer.decode(LabelModel.self, forKey: .rightLabel) arrow = try typeContainer.decode(ArrowModel.self, forKey: .arrow) try super.init(from: decoder) @@ -39,7 +47,7 @@ public class ListRightVariablePriceChangeBodyTextModel: ListItemModel, MoleculeM try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) - try container.encode(eyebrowHeadlineBodyLink, forKey: .eyebrowHeadlineBodyLink) + try container.encode(headlineBody, forKey: .headlineBody) try container.encode(rightLabel, forKey: .rightLabel) try container.encode(arrow, forKey: .arrow) } diff --git a/MVMCoreUI/BaseClasses/TableViewCell.swift b/MVMCoreUI/BaseClasses/TableViewCell.swift index 8170e402..f27a38d8 100644 --- a/MVMCoreUI/BaseClasses/TableViewCell.swift +++ b/MVMCoreUI/BaseClasses/TableViewCell.swift @@ -97,7 +97,7 @@ import UIKit // Ensures accessory view aligns to the center y derived from the if let _ = heroAccessoryCenter { - alignAccessoryToHero() + _ = alignAccessoryToHero() } } @@ -215,14 +215,16 @@ import UIKit } /// NOTE: Should only be called when displayed or about to be displayed. - public func alignAccessoryToHero() { + public func alignAccessoryToHero() -> CGPoint? { // Layout call required to force draw in memory to get dimensions of subviews. layoutIfNeeded() - guard let heroLabel = findHeroLabel(views: contentView.subviews), let hero = heroLabel.hero else { return } + guard let heroLabel = findHeroLabel(views: contentView.subviews), let hero = heroLabel.hero else { return nil } let rect = Label.boundingRect(forCharacterRange: NSRange(location: hero, length: 1), in: heroLabel) - accessoryView?.center.y = convert(UIView(frame: rect).center, from: heroLabel).y + let y = convert(UIView(frame: rect).center, from: heroLabel).y + accessoryView?.center.y = y heroAccessoryCenter = accessoryView?.center + return heroAccessoryCenter ?? CGPoint(x: 0, y: y) } /// Traverses the view hierarchy for a 🦸‍♂️ heroic Label. @@ -269,7 +271,7 @@ import UIKit } public func willDisplay() { - alignAccessoryToHero() + _ = alignAccessoryToHero() } // MARK: - Separator