From fdd0d35f2b683f6c05dff5c3e50cecc202480a0f Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Fri, 15 Mar 2024 17:05:15 +0530 Subject: [PATCH] Added EyebrowModel for tilelet --- VDS.xcodeproj/project.pbxproj | 6 +- VDS/Components/Tilelet/Tilelet.swift | 20 ++++--- .../Tilelet/TileletSubTitleModel.swift | 3 - .../Tilelet/TiletEyebrowModel.swift | 55 +++++++++++++++++++ 4 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 VDS/Components/Tilelet/TiletEyebrowModel.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 1d773b71..a22c51b8 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ 5FC35BE328D51405004EBEAC /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC35BE228D51405004EBEAC /* Button.swift */; }; 710607952B91A99500F2863F /* TitleletChangeLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = 710607942B91A99500F2863F /* TitleletChangeLog.txt */; }; 7115BD3C2B84C0C200E0A610 /* TileContainerChangeLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = 7115BD3B2B84C0C200E0A610 /* TileContainerChangeLog.txt */; }; + 71ACE89E2BA1CC1700FB6ADC /* TiletEyebrowModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71ACE89D2BA1CC1700FB6ADC /* TiletEyebrowModel.swift */; }; 71BFA70A2B7F70E6000DCE33 /* DropShadowable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71BFA7092B7F70E6000DCE33 /* DropShadowable.swift */; }; 71C02B382B7BD98F00E93E66 /* NotificationChangeLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = 71C02B372B7BD98F00E93E66 /* NotificationChangeLog.txt */; }; 71FC86DE2B9738B900700965 /* SurfaceConfigurationValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71FC86DD2B9738B900700965 /* SurfaceConfigurationValue.swift */; }; @@ -190,6 +191,7 @@ 5FC35BE228D51405004EBEAC /* Button.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Button.swift; sourceTree = ""; }; 710607942B91A99500F2863F /* TitleletChangeLog.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = TitleletChangeLog.txt; sourceTree = ""; }; 7115BD3B2B84C0C200E0A610 /* TileContainerChangeLog.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = TileContainerChangeLog.txt; sourceTree = ""; }; + 71ACE89D2BA1CC1700FB6ADC /* TiletEyebrowModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TiletEyebrowModel.swift; sourceTree = ""; }; 71BFA7092B7F70E6000DCE33 /* DropShadowable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropShadowable.swift; sourceTree = ""; }; 71C02B372B7BD98F00E93E66 /* NotificationChangeLog.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = NotificationChangeLog.txt; sourceTree = ""; }; 71FC86DD2B9738B900700965 /* SurfaceConfigurationValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SurfaceConfigurationValue.swift; sourceTree = ""; }; @@ -691,8 +693,9 @@ children = ( EA5E3057295105A40082B959 /* Tilelet.swift */, EA985BE529688F6A00F2FF2E /* TileletBadgeModel.swift */, - EA985BE929689B6D00F2FF2E /* TileletSubTitleModel.swift */, + 71ACE89D2BA1CC1700FB6ADC /* TiletEyebrowModel.swift */, EA985BE72968951C00F2FF2E /* TileletTitleModel.swift */, + EA985BE929689B6D00F2FF2E /* TileletSubTitleModel.swift */, EA985C2C296F03FE00F2FF2E /* TileletIconModels.swift */, 710607942B91A99500F2863F /* TitleletChangeLog.txt */, ); @@ -1042,6 +1045,7 @@ EAC71A1F2A2E173D00E47A9F /* RadioButton.swift in Sources */, EA33622C2891E73B0071C351 /* FontProtocol.swift in Sources */, EA596ABD2A16B4EC00300C4B /* Tab.swift in Sources */, + 71ACE89E2BA1CC1700FB6ADC /* TiletEyebrowModel.swift in Sources */, EAF7F11728A1475A00B287F5 /* RadioButtonItem.swift in Sources */, EA985BEE2968A92400F2FF2E /* TitleLockupSubTitleModel.swift in Sources */, EA985BF22968B5BB00F2FF2E /* TitleLockupTextStyle.swift in Sources */, diff --git a/VDS/Components/Tilelet/Tilelet.swift b/VDS/Components/Tilelet/Tilelet.swift index f8a3b4db..0f595343 100644 --- a/VDS/Components/Tilelet/Tilelet.swift +++ b/VDS/Components/Tilelet/Tilelet.swift @@ -250,6 +250,9 @@ open class Tilelet: TileContainerBase { /// If set, this is used to render the subTitleLabel of the TitleLockup. open var subTitleModel: SubTitleModel? { didSet { setNeedsUpdate() } } + /// If set, this is used to render the eyebrowLabel of the TitleLockup. + open var eyebrowModel: EyebrowModel? { didSet { setNeedsUpdate() } } + //only 1 Icon can be active private var _descriptiveIconModel: DescriptiveIcon? @@ -320,7 +323,7 @@ open class Tilelet: TileContainerBase { titleLockupBottomGreaterThanConstraint = titleLockupContainerView.bottomAnchor.constraint(greaterThanOrEqualTo: titleLockup.bottomAnchor) titleLockupTopGreaterThanConstraint = titleLockup.topAnchor.constraint(greaterThanOrEqualTo: titleLockupContainerView.topAnchor) titleLockupCenterYConstraint = titleLockup.centerYAnchor.constraint(equalTo: titleLockupContainerView.centerYAnchor) - + iconContainerView.addSubview(descriptiveIcon) iconContainerView.addSubview(directionalIcon) @@ -335,7 +338,7 @@ open class Tilelet: TileContainerBase { .pinBottom() //If a Tilelet has Badge, Title and Subtitle, then Subtitle will be truncated first and Badge will be truncated second. Title will be truncated last (lowest priority). - var labelPriority = UILayoutPriority.defaultHigh.rawValue + let labelPriority = UILayoutPriority.defaultHigh.rawValue titleLockup.titleLabel.setContentCompressionResistancePriority(UILayoutPriority(labelPriority), for: .vertical) badge.label.setContentCompressionResistancePriority(UILayoutPriority(labelPriority-1), for: .vertical) titleLockup.subTitleLabel.setContentCompressionResistancePriority(UILayoutPriority(labelPriority-2), for: .vertical) @@ -400,7 +403,11 @@ open class Tilelet: TileContainerBase { private func updateTitleLockup() { var showTitleLockup = false - + + if let eyebrowModel, !eyebrowModel.text.isEmpty { + showTitleLockup = true + } + if let titleModel, !titleModel.text.isEmpty { showTitleLockup = true } @@ -444,6 +451,7 @@ open class Tilelet: TileContainerBase { } //set models + titleLockup.eyebrowModel = eyebrowModel?.toTitleLockupEyebrowModel() titleLockup.titleModel = titleModel?.toTitleLockupTitleModel() titleLockup.subTitleModel = subTitleModel?.toTitleLockupSubTitleModel() @@ -495,12 +503,6 @@ open class Tilelet: TileContainerBase { } else { removeFromSuperview(iconContainerView) } - if let lastElement = titleLockup.lastElement { - titleLockupTitleLabelBottomConstraint?.deactivate() - let anchorConstraint = showIconContainerView ? iconContainerView.topAnchor : containerView.bottomAnchor - titleLockupTitleLabelBottomConstraint = anchorConstraint.constraint(greaterThanOrEqualTo: lastElement.bottomAnchor) - titleLockupTitleLabelBottomConstraint?.activate() - } } private func updateTextPositionAlignment() { diff --git a/VDS/Components/Tilelet/TileletSubTitleModel.swift b/VDS/Components/Tilelet/TileletSubTitleModel.swift index 62adda7e..fb68ff53 100644 --- a/VDS/Components/Tilelet/TileletSubTitleModel.swift +++ b/VDS/Components/Tilelet/TileletSubTitleModel.swift @@ -48,14 +48,11 @@ extension Tilelet { otherStandardStyle: OtherStandardStyle = .bodySmall, textColor: Use = .primary, textAttributes: [any LabelAttributeModel]? = nil, - standardStyle: StandardStyle = .bodySmall, lineBreakMode: NSLineBreakMode = .byTruncatingTail) { - textAttributes: [any LabelAttributeModel]? = nil) { self.text = text self.otherStandardStyle = otherStandardStyle self.textAttributes = textAttributes self.textColor = textColor - self.standardStyle = standardStyle self.lineBreakMode = lineBreakMode } diff --git a/VDS/Components/Tilelet/TiletEyebrowModel.swift b/VDS/Components/Tilelet/TiletEyebrowModel.swift new file mode 100644 index 00000000..e7c008b4 --- /dev/null +++ b/VDS/Components/Tilelet/TiletEyebrowModel.swift @@ -0,0 +1,55 @@ +// +// TiletEyebrowModel.swift +// VDS +// +// Created by Bandaru, Krishna Kishore on 13/03/24. +// + +import Foundation +import UIKit + +extension Tilelet { + + /// Model that represents the options available for the eyebrow label. + public struct EyebrowModel { + //-------------------------------------------------- + // MARK: - Public Properties + //-------------------------------------------------- + /// Text that will be used for the eyebrow label. + public var text: String = "" + + /// Used in combination with standardStyle to set the textStyle that will be used for the eyebrow label. + public var isBold: Bool = false + /// Text attributes that will be used for the eyebrow label. + public var textAttributes: [any LabelAttributeModel]? + + /// Text style that will be used for the eyebrow label. If subtitle standard style + public var standardStyle: Tilelet.SubTitleModel.OtherStandardStyle = .titleSmall + + /// LineBreakMode used in Badge label. + public var lineBreakMode: NSLineBreakMode + + //-------------------------------------------------- + // MARK: - Initializers + //-------------------------------------------------- + public init(text: String, + textAttributes: [any LabelAttributeModel]? = nil, + isBold: Bool = true, + standardStyle: Tilelet.SubTitleModel.OtherStandardStyle = .bodySmall, + lineBreakMode: NSLineBreakMode = .byTruncatingTail) { + self.text = text + self.textAttributes = textAttributes + self.standardStyle = standardStyle + self.isBold = isBold + self.lineBreakMode = lineBreakMode + } + + //-------------------------------------------------- + // MARK: - Public Methods + //-------------------------------------------------- + /// Converts this type of model to a TitleLockup.TitleModel. + public func toTitleLockupEyebrowModel() -> TitleLockup.EyebrowModel { + TitleLockup.EyebrowModel(text: text, isBold: isBold, standardStyle: standardStyle.value, textAttributes: textAttributes) + } + } +}