From 6e74c5e9b318201d753f361cee2b2849fc52e1a6 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 13 Dec 2023 15:07:52 -0600 Subject: [PATCH 1/6] added enum codable Signed-off-by: Matt Bruce --- MVMCoreUI/Atomic/Extensions/VDS-Enums+Codable.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Extensions/VDS-Enums+Codable.swift b/MVMCoreUI/Atomic/Extensions/VDS-Enums+Codable.swift index 1d24a0bd..8831c7c6 100644 --- a/MVMCoreUI/Atomic/Extensions/VDS-Enums+Codable.swift +++ b/MVMCoreUI/Atomic/Extensions/VDS-Enums+Codable.swift @@ -17,10 +17,11 @@ extension TileContainer.BackgroundColor: Codable {} extension TileContainer.Padding: Codable {} extension TileContainer.AspectRatio: Codable {} extension TextLink.Size: Codable {} +extension VDS.TitleLockup.TextAlignment: Codable {} extension VDS.Line.Style: Codable {} extension VDS.Line.Orientation: Codable {} extension Use: Codable {} extension VDS.Button.Size: RawRepresentableCodable { public static var mapping: [String : VDS.Button.Size] { ["standard": .large, "tiny": .small] } public static var defaultValue: VDS.Button.Size? { nil } -} \ No newline at end of file +} From 55b6b491afcad0c8ceb390a739413f317eb40f0f Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 13 Dec 2023 15:28:58 -0600 Subject: [PATCH 2/6] initial cut for TitleLockup and model Signed-off-by: Matt Bruce --- .../LockUps/TitleLockup.swift | 115 ++---------- .../LockUps/TitleLockupModel.swift | 174 +++++------------- 2 files changed, 60 insertions(+), 229 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockup.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockup.swift index b48e4ddb..b0fd7fea 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockup.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockup.swift @@ -5,119 +5,42 @@ // Created by Nadigadda, Sumanth on 04/05/22. // Copyright © 2022 Verizon Wireless. All rights reserved. // +import VDS + +@objcMembers open class TitleLockup: VDS.TitleLockup, VDSMoleculeViewProtocol { -@objcMembers open class TitleLockup: View { //-------------------------------------------------- - // MARK: - Outlets + // MARK: - Public Properties //-------------------------------------------------- + open var viewModel: TitleLockupModel! + open var delegateObject: MVMCoreUIDelegateObject? + open var additionalData: [AnyHashable : Any]? - public let eyebrow = Label(fontStyle: .RegularBodySmall) - public let title = Label(fontStyle: .RegularBodySmall) - public let subTitle = Label(fontStyle: .RegularBodySmall) - public lazy var stack: UIStackView = { - let stack = UIStackView(arrangedSubviews: [eyebrow, title, subTitle]) - stack.translatesAutoresizingMaskIntoConstraints = false - stack.axis = .vertical - return stack - }() - - var castModel: TitleLockupModel? { - get { return model as? TitleLockupModel } + //-------------------------------------------------- + // MARK: - Public Functions + //-------------------------------------------------- + open func viewModelDidUpdate() { + surface = viewModel.surface + eyebrowModel = viewModel.eyebrowModel(delegateObject: delegateObject, additionalData: additionalData) + titleModel = viewModel.titleModel(delegateObject: delegateObject, additionalData: additionalData) + subTitleModel = viewModel.subTitleModel(delegateObject: delegateObject, additionalData: additionalData) } - + //-------------------------------------------------- // MARK: - Initialization //-------------------------------------------------- - public convenience init() { + public convenience required init() { self.init(frame: .zero) } - //-------------------------------------------------- - // MARK: - MFViewProtocol - //-------------------------------------------------- - - open override func setupView() { - super.setupView() - addSubview(stack) - NSLayoutConstraint.constraintPinSubview(toSuperview: stack) - } - - open override func updateView(_ size: CGFloat) { - super.updateView(size) - stack.updateView(size) - } - //-------------------------------------------------- // MARK: - MoleculeViewProtocol //-------------------------------------------------- - - open override func reset() { - super.reset() - stack.reset() - } - - //-------------------------------------------------- - // MARK: - MoleculeViewProtocol - //-------------------------------------------------- - - open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - super.set(with: model, delegateObject, additionalData) - guard let model = model as? TitleLockupModel else { return } - stack.setCustomSpacing(model.defaultEyebrowTitleSpacing(), after: eyebrow) - stack.setCustomSpacing(model.defaultTitleSubTitleSpacing(), after: title) - stack.updateContainedMolecules(with: [model.eyebrow, - model.title, - model.subTitle], - delegateObject, additionalData) - } - - open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { return 65 } - //-------------------------------------------------- - // MARK: - Accessibility Helpers - //-------------------------------------------------- - - /// Returns the labels text in one message. - func getAccessibilityMessage() -> String? { - - var message = "" - - if let eyebrowLabel = eyebrow.text { - message += eyebrowLabel + ", " - } - - if let headlineLabel = title.text { - message += headlineLabel + ", " - } - - if let bodyLabel = subTitle.text { - message += bodyLabel - } - - return message.count > 0 ? message : nil - } - - /// Returns an array of the appropriate accessibility elements. - func getAccessibilityElements() -> [Any]? { - - var elements: [UIView] = [] - - if eyebrow.hasText { - elements.append(eyebrow) - } - - if title.hasText { - elements.append(title) - } - - if subTitle.hasText { - elements.append(subTitle) - } - - return elements.count > 0 ? elements : nil - } + open func updateView(_ size: CGFloat) {} } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift index 89d32ca9..fb930bde 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift @@ -7,6 +7,7 @@ // import VDSColorTokens +import VDS public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtocol { @@ -22,43 +23,10 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco public var title: LabelModel public var subTitle: LabelModel? - public var alignment: Alignment = .left { - didSet { - ///Updating the text alignment for all labels - if let textAlignment = NSTextAlignment(rawValue: alignment.rawValue) { - eyebrow?.textAlignment = textAlignment - title.textAlignment = textAlignment - subTitle?.textAlignment = textAlignment - } - } - } + public var alignment: VDS.TitleLockup.TextAlignment = .left + public var inverted: Bool = false - public var inverted: Bool = false { - didSet { - ///Updating the text color - eyebrow?.textColor = titleColor - title.textColor = titleColor - subTitle?.textColor = subTitleColor - } - } - - private var _backgroundColor: Color? - public var backgroundColor: Color? { - get { - return inverted ? Color(uiColor: VDSColor.backgroundPrimaryDark) : Color(uiColor: VDSColor.backgroundPrimaryLight) - } - set { - _backgroundColor = newValue - } - } - - public var titleColor: Color? { - return inverted ? Color(uiColor: VDSColor.elementsPrimaryOndark) : Color(uiColor: VDSColor.elementsPrimaryOnlight) - } - - public var subTitleColor: Color? { - return inverted ? Color(uiColor: VDSColor.elementsSecondaryOndark) : Color(uiColor: VDSColor.elementsSecondaryOnlight) - } + public var backgroundColor: Color? public var children: [MoleculeModelProtocol] { [eyebrow, title, subTitle].compactMap { (molecule: MoleculeModelProtocol?) in molecule } @@ -72,58 +40,6 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco self.eyebrow = eyebrow self.title = title self.subTitle = subTitle - updateLabelAttributes() - } - - //-------------------------------------------------- - // MARK: - Enum - //-------------------------------------------------- - - public enum Alignment: String, Codable { - case left - case center - } - - //-------------------------------------------------- - // MARK: - Styling - //-------------------------------------------------- - - /// Returns the default fontStyle for the subtitle, based on the title fontStyle. - func defaultSubtitleFontStyle() -> Styler.Font { - switch title.fontStyle { - case .RegularTitleXLarge, .RegularTitle2XLarge, .RegularFeatureXSmall: - return .RegularBodyLarge - case .RegularFeatureSmall, .RegularFeatureMedium: - return .RegularTitleLarge - default: - return .RegularBodySmall - } - } - - /// Returns the default spacing between the eyebrow and title, based on the title fontStyle. - func defaultEyebrowTitleSpacing() -> CGFloat { - switch title.fontStyle { - case .RegularTitleXLarge, .RegularTitle2XLarge, .RegularFeatureXSmall, .RegularFeatureSmall: - return Padding.Three - case .RegularFeatureMedium: - return subTitle?.fontStyle == .RegularBodyLarge ? Padding.Three : Padding.Four - default: - return Padding.Two - } - } - - /// Returns the default spacing between the title and subTitle, based on the title fontStyle. - func defaultTitleSubTitleSpacing() -> CGFloat { - switch title.fontStyle { - case .RegularTitleXLarge: - return Padding.Three - case .RegularTitle2XLarge, .RegularFeatureXSmall, .RegularFeatureSmall: - return Padding.Four - case .RegularFeatureMedium: - return Padding.Five - default: - return Padding.Two - } } //-------------------------------------------------- @@ -133,7 +49,6 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco private enum CodingKeys: String, CodingKey { case id case moleculeName - case backgroundColor case eyebrow case title case subTitle @@ -148,21 +63,17 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString - title = try typeContainer.decodeMolecule(codingKey: .title) + title = try typeContainer.decode(LabelModel.self, forKey: .title) eyebrow = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .eyebrow) - subTitle = try typeContainer.decodeMoleculeIfPresent(codingKey: .subTitle) + subTitle = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .subTitle) - if let newAlignment = try typeContainer.decodeIfPresent(Alignment.self, forKey: .alignment) { + if let newAlignment = try typeContainer.decodeIfPresent(VDS.TitleLockup.TextAlignment.self, forKey: .alignment) { alignment = newAlignment } if let invertedStatus = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) { inverted = invertedStatus } - - backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - - updateLabelAttributes() } public func encode(to encoder: Encoder) throws { @@ -174,46 +85,43 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco try container.encodeIfPresent(subTitle, forKey: .subTitle) try container.encode(alignment, forKey: .alignment) try container.encode(inverted, forKey: .inverted) - try container.encodeIfPresent(_backgroundColor, forKey: .backgroundColor) } - //-------------------------------------------------- - // MARK: - Model updates - //-------------------------------------------------- + public func eyebrowModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> VDS.TitleLockup.EyebrowModel? { + guard let subTitle else { return nil } + let attrs = subTitle.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData) + let style: TextStyle? = subTitle.fontStyle?.vdsTextStyle() + if let style, let standardStyle = VDS.TitleLockup.OtherStandardStyle(rawValue: style.toStandardStyle().rawValue) { + return .init(text: subTitle.text, isBold: style.isBold, standardStyle: standardStyle, textAttributes: attrs) + } else { + return .init(text: subTitle.text, textAttributes: attrs) + } + } + + public func titleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> VDS.TitleLockup.TitleModel? { + let attrs = title.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData) + let style: TextStyle? = title.fontStyle?.vdsTextStyle() + if let style, let standardStyle = VDS.TitleLockup.TitleStandardStyle(rawValue: style.toStandardStyle().rawValue) { + return .init(text: title.text, textAttributes: attrs, isBold: style.isBold, standardStyle: standardStyle) + } else { + return .init(text: title.text, textAttributes: attrs) + } + } - private func updateLabelAttributes() { - // If subtitle style is not available, will set font style based on the component - if subTitle?.fontStyle == nil { - subTitle?.fontStyle = defaultSubtitleFontStyle() - } - - // If eyebrow style is not available, will set font style based on the component. Eyebrow and subtitle share the same font size - if eyebrow?.fontStyle == nil { - eyebrow?.fontStyle = subTitle?.fontStyle - } - - // Updating the text color - if eyebrow?.textColor == nil { - eyebrow?.textColor = subTitleColor - } - if title.textColor == nil { - title.textColor = titleColor - } - if subTitle?.textColor == nil { - subTitle?.textColor = subTitleColor - } - - // Updating the text alignment for all labels - if let textAlignment = NSTextAlignment(rawValue: alignment.rawValue) { - if eyebrow?.textAlignment == nil { - eyebrow?.textAlignment = textAlignment - } - if title.textAlignment == nil { - title.textAlignment = textAlignment - } - if subTitle?.textAlignment == nil { - subTitle?.textAlignment = textAlignment - } + public func subTitleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> VDS.TitleLockup.SubTitleModel? { + guard let subTitle else { return nil } + let attrs = subTitle.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData) + let style: TextStyle? = subTitle.fontStyle?.vdsTextStyle() + if let style, let standardStyle = VDS.TitleLockup.OtherStandardStyle(rawValue: style.toStandardStyle().rawValue) { + return .init(text: subTitle.text, standardStyle: standardStyle, textAttributes: attrs) + } else { + return .init(text: subTitle.text, textAttributes: attrs) } } } + + +extension TitleLockupModel { + public var surface: Surface { inverted ? .dark : .light } +} + From 86b835fc60c846ba02ccde70e2bfa11424bccd3b Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 13 Dec 2023 15:43:40 -0600 Subject: [PATCH 3/6] fixed bug Signed-off-by: Matt Bruce --- .../LockUps/TitleLockupModel.swift | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift index fb930bde..bac8ef34 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift @@ -88,13 +88,13 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco } public func eyebrowModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> VDS.TitleLockup.EyebrowModel? { - guard let subTitle else { return nil } - let attrs = subTitle.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData) - let style: TextStyle? = subTitle.fontStyle?.vdsTextStyle() + guard let eyebrow else { return nil } + let attrs = eyebrow.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData) + let style: TextStyle? = eyebrow.fontStyle?.vdsTextStyle() if let style, let standardStyle = VDS.TitleLockup.OtherStandardStyle(rawValue: style.toStandardStyle().rawValue) { - return .init(text: subTitle.text, isBold: style.isBold, standardStyle: standardStyle, textAttributes: attrs) + return .init(text: eyebrow.text, isBold: style.isBold, standardStyle: standardStyle, textAttributes: attrs, numberOfLines: eyebrow.numberOfLines ?? 0) } else { - return .init(text: subTitle.text, textAttributes: attrs) + return .init(text: eyebrow.text, textAttributes: attrs, numberOfLines: eyebrow.numberOfLines ?? 0) } } @@ -102,9 +102,9 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco let attrs = title.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData) let style: TextStyle? = title.fontStyle?.vdsTextStyle() if let style, let standardStyle = VDS.TitleLockup.TitleStandardStyle(rawValue: style.toStandardStyle().rawValue) { - return .init(text: title.text, textAttributes: attrs, isBold: style.isBold, standardStyle: standardStyle) + return .init(text: title.text, textAttributes: attrs, isBold: style.isBold, standardStyle: standardStyle, numberOfLines: title.numberOfLines ?? 0) } else { - return .init(text: title.text, textAttributes: attrs) + return .init(text: title.text, textAttributes: attrs, numberOfLines: title.numberOfLines ?? 0) } } @@ -113,9 +113,9 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco let attrs = subTitle.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData) let style: TextStyle? = subTitle.fontStyle?.vdsTextStyle() if let style, let standardStyle = VDS.TitleLockup.OtherStandardStyle(rawValue: style.toStandardStyle().rawValue) { - return .init(text: subTitle.text, standardStyle: standardStyle, textAttributes: attrs) + return .init(text: subTitle.text, standardStyle: standardStyle, textAttributes: attrs, numberOfLines: subTitle.numberOfLines ?? 0) } else { - return .init(text: subTitle.text, textAttributes: attrs) + return .init(text: subTitle.text, textAttributes: attrs, numberOfLines: subTitle.numberOfLines ?? 0) } } } From 908c3bddc39e5f360bd2c832e6f0e9488eae951f Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 15 Feb 2024 17:43:26 -0600 Subject: [PATCH 4/6] updated model Signed-off-by: Matt Bruce --- .../Atomic/Extensions/VDS-TextStyle.swift | 17 ++--- .../LockUps/TitleLockupModel.swift | 63 ++++++++++++------- 2 files changed, 51 insertions(+), 29 deletions(-) diff --git a/MVMCoreUI/Atomic/Extensions/VDS-TextStyle.swift b/MVMCoreUI/Atomic/Extensions/VDS-TextStyle.swift index 09fc5dcd..ba638e34 100644 --- a/MVMCoreUI/Atomic/Extensions/VDS-TextStyle.swift +++ b/MVMCoreUI/Atomic/Extensions/VDS-TextStyle.swift @@ -18,14 +18,15 @@ extension Styler.Font { return style } - public func vdsSubsetStyle() -> T? { - guard let style = vdsTextStyle() else { return nil } - guard let rawValue = style.rawValue as? T.RawValue, - let found = T(rawValue: rawValue) else { - print("Style: \(style.rawValue) is not in enum \(T.self)\ronly these cases exist:\r\(T.allCases)") - return nil + public func vdsSubsetStyle() throws -> T { + guard let style = vdsTextStyle(), let rawValue = style.toStandardStyle().rawValue as? T.RawValue, let standardStyle = T(rawValue: rawValue) else { + let err = "\(rawValue) was not found in the \(T.self), only these cases exist:\r\(T.allCases)" + throw MVMCoreError.errorObject(MVMCoreErrorObject(title: "\(T.self) conversion Issue", + messageToLog: err, + code: 999, + domain: ErrorDomainNative, + location: #file)!) } - return found + return standardStyle } } - diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift index bac8ef34..e11aea0f 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift @@ -90,38 +90,59 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco public func eyebrowModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> VDS.TitleLockup.EyebrowModel? { guard let eyebrow else { return nil } let attrs = eyebrow.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData) - let style: TextStyle? = eyebrow.fontStyle?.vdsTextStyle() - if let style, let standardStyle = VDS.TitleLockup.OtherStandardStyle(rawValue: style.toStandardStyle().rawValue) { - return .init(text: eyebrow.text, isBold: style.isBold, standardStyle: standardStyle, textAttributes: attrs, numberOfLines: eyebrow.numberOfLines ?? 0) - } else { - return .init(text: eyebrow.text, textAttributes: attrs, numberOfLines: eyebrow.numberOfLines ?? 0) - } + do { + if let style = eyebrow.fontStyle { + return .init(text: eyebrow.text, + isBold: style.isBold(), + standardStyle: try style.vdsSubsetStyle(), + textAttributes: attrs, + numberOfLines: eyebrow.numberOfLines ?? 0) + } + } catch MVMCoreError.errorObject(let object) { + MVMCoreLoggingHandler.shared()?.addError(toLog: object) + } catch { } + + return .init(text: eyebrow.text, textAttributes: attrs, numberOfLines: eyebrow.numberOfLines ?? 0) } - public func titleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> VDS.TitleLockup.TitleModel? { + public func titleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> VDS.TitleLockup.TitleModel { let attrs = title.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData) - let style: TextStyle? = title.fontStyle?.vdsTextStyle() - if let style, let standardStyle = VDS.TitleLockup.TitleStandardStyle(rawValue: style.toStandardStyle().rawValue) { - return .init(text: title.text, textAttributes: attrs, isBold: style.isBold, standardStyle: standardStyle, numberOfLines: title.numberOfLines ?? 0) - } else { - return .init(text: title.text, textAttributes: attrs, numberOfLines: title.numberOfLines ?? 0) - } + do { + if let style = title.fontStyle { + return .init(text: title.text, + textAttributes: attrs, + isBold: style.isBold(), + standardStyle: try style.vdsSubsetStyle(), + numberOfLines: title.numberOfLines ?? 0) + } + + } catch MVMCoreError.errorObject(let object) { + MVMCoreLoggingHandler.shared()?.addError(toLog: object) + } catch { } + + return .init(text: title.text, textAttributes: attrs, numberOfLines: title.numberOfLines ?? 0) } public func subTitleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> VDS.TitleLockup.SubTitleModel? { guard let subTitle else { return nil } let attrs = subTitle.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData) - let style: TextStyle? = subTitle.fontStyle?.vdsTextStyle() - if let style, let standardStyle = VDS.TitleLockup.OtherStandardStyle(rawValue: style.toStandardStyle().rawValue) { - return .init(text: subTitle.text, standardStyle: standardStyle, textAttributes: attrs, numberOfLines: subTitle.numberOfLines ?? 0) - } else { - return .init(text: subTitle.text, textAttributes: attrs, numberOfLines: subTitle.numberOfLines ?? 0) - } + + do { + if let style = subTitle.fontStyle { + return .init(text: subTitle.text, + standardStyle: try style.vdsSubsetStyle(), + textAttributes: attrs, + numberOfLines: subTitle.numberOfLines ?? 0) + } + } catch MVMCoreError.errorObject(let object) { + MVMCoreLoggingHandler.shared()?.addError(toLog: object) + } catch { } + + return .init(text: subTitle.text, textAttributes: attrs, numberOfLines: subTitle.numberOfLines ?? 0) + } } - extension TitleLockupModel { public var surface: Surface { inverted ? .dark : .light } } - From 8daf1a2b728b47b0b3797feeee0e4933eaa4c51f Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 15 Feb 2024 17:56:50 -0600 Subject: [PATCH 5/6] updated more model properties Signed-off-by: Matt Bruce --- .../DesignedComponents/LockUps/TitleLockup.swift | 1 + .../LockUps/TitleLockupModel.swift | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockup.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockup.swift index b0fd7fea..6339b8e2 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockup.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockup.swift @@ -21,6 +21,7 @@ import VDS //-------------------------------------------------- open func viewModelDidUpdate() { surface = viewModel.surface + textAlignment = viewModel.textAlignment eyebrowModel = viewModel.eyebrowModel(delegateObject: delegateObject, additionalData: additionalData) titleModel = viewModel.titleModel(delegateObject: delegateObject, additionalData: additionalData) subTitleModel = viewModel.subTitleModel(delegateObject: delegateObject, additionalData: additionalData) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift index e11aea0f..034420cd 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift @@ -19,9 +19,11 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco public var moleculeName: String = TitleLockupModel.identifier public var id: String = UUID().uuidString + public var textAlignment: TitleLockup.TextAlignment = .left public var eyebrow: LabelModel? public var title: LabelModel public var subTitle: LabelModel? + public var subTitleColor: Use = .primary public var alignment: VDS.TitleLockup.TextAlignment = .left public var inverted: Bool = false @@ -49,9 +51,11 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco private enum CodingKeys: String, CodingKey { case id case moleculeName + case textAlignment case eyebrow case title case subTitle + case subTitleColor case inverted case alignment } @@ -63,10 +67,12 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString + textAlignment = try typeContainer.decodeIfPresent(TitleLockup.TextAlignment.self, forKey: .textAlignment) ?? .left title = try typeContainer.decode(LabelModel.self, forKey: .title) eyebrow = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .eyebrow) subTitle = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .subTitle) - + subTitleColor = try typeContainer.decodeIfPresent(Use.self, forKey: .subTitleColor) ?? .primary + if let newAlignment = try typeContainer.decodeIfPresent(VDS.TitleLockup.TextAlignment.self, forKey: .alignment) { alignment = newAlignment } @@ -80,9 +86,11 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(id, forKey: .id) try container.encode(moleculeName, forKey: .moleculeName) + try container.encode(textAlignment, forKey: .textAlignment) try container.encodeIfPresent(eyebrow, forKey: .eyebrow) try container.encodeModel(title, forKey: .title) try container.encodeIfPresent(subTitle, forKey: .subTitle) + try container.encode(subTitleColor, forKey: .subTitleColor) try container.encode(alignment, forKey: .alignment) try container.encode(inverted, forKey: .inverted) } @@ -131,6 +139,7 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco if let style = subTitle.fontStyle { return .init(text: subTitle.text, standardStyle: try style.vdsSubsetStyle(), + textColor: subTitleColor, textAttributes: attrs, numberOfLines: subTitle.numberOfLines ?? 0) } @@ -138,7 +147,7 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco MVMCoreLoggingHandler.shared()?.addError(toLog: object) } catch { } - return .init(text: subTitle.text, textAttributes: attrs, numberOfLines: subTitle.numberOfLines ?? 0) + return .init(text: subTitle.text, textColor: subTitleColor, textAttributes: attrs, numberOfLines: subTitle.numberOfLines ?? 0) } } From 881fd5e433c5cb378b4b971b6b662686b0e3a02c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 16 Feb 2024 09:37:44 -0600 Subject: [PATCH 6/6] refactored naming conventions in object Signed-off-by: Matt Bruce --- .../Atomic/Atoms/Views/TileletModel.swift | 38 ++++++++++++------- .../LockUps/TitleLockupModel.swift | 2 +- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/TileletModel.swift b/MVMCoreUI/Atomic/Atoms/Views/TileletModel.swift index b41d9eef..7cc9747e 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/TileletModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/TileletModel.swift @@ -68,23 +68,35 @@ open class TileletModel: MoleculeModelProtocol { public func titleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Tilelet.TitleModel? { guard let title else { return nil } let attrs = title.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData) - let style: TextStyle? = title.fontStyle?.vdsTextStyle() - if let style, let standardStyle = Tilelet.TitleModel.StandardStyle(rawValue: style.toStandardStyle().rawValue) { - return .init(text: title.text, textAttributes: attrs, standardStyle: standardStyle) - } else { - return .init(text: title.text, textAttributes: attrs) - } - } + + do { + if let style = title.fontStyle { + return .init(text: title.text, + textAttributes: attrs, + standardStyle: try style.vdsSubsetStyle()) + } + } catch MVMCoreError.errorObject(let object) { + MVMCoreLoggingHandler.shared()?.addError(toLog: object) + } catch { } + + return .init(text: title.text, textAttributes: attrs) + } + public func subTitleModel(delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Tilelet.SubTitleModel? { guard let subTitle else { return nil } let attrs = subTitle.attributes?.toVDSLabelAttributeModel(delegateObject: delegateObject, additionalData: additionalData) - let style: TextStyle? = subTitle.fontStyle?.vdsTextStyle() - if let style, let standardStyle = Tilelet.SubTitleModel.StandardStyle(rawValue: style.toStandardStyle().rawValue) { - return .init(text: subTitle.text, textAttributes: attrs, standardStyle: standardStyle) - } else { - return .init(text: subTitle.text, textAttributes: attrs) - } + do { + if let style = subTitle.fontStyle { + return .init(text: subTitle.text, + otherStandardStyle: try style.vdsSubsetStyle(), + textAttributes: attrs) + } + } catch MVMCoreError.errorObject(let object) { + MVMCoreLoggingHandler.shared()?.addError(toLog: object) + } catch { } + + return .init(text: subTitle.text, textAttributes: attrs) } public func encode(to encoder: Encoder) throws { diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift index 034420cd..6c48398b 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/LockUps/TitleLockupModel.swift @@ -138,7 +138,7 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco do { if let style = subTitle.fontStyle { return .init(text: subTitle.text, - standardStyle: try style.vdsSubsetStyle(), + otherStandardStyle: try style.vdsSubsetStyle(), textColor: subTitleColor, textAttributes: attrs, numberOfLines: subTitle.numberOfLines ?? 0)