From 410ee5afdf7bb647d86f3c0ea2972b221051d2fd Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 3 Jan 2023 11:36:36 -0600 Subject: [PATCH 01/12] refactored to use tokens instead of hardcoded values Signed-off-by: Matt Bruce --- VDS/Components/Badge/Badge.swift | 2 +- VDS/Components/Buttons/Button/Button.swift | 2 +- VDS/Components/Checkbox/Checkbox.swift | 4 ++-- VDS/Components/RadioBox/RadioBox.swift | 10 +++++----- VDS/Components/RadioButton/RadioButton.swift | 2 +- VDS/Components/RadioSwatch/RadioSwatch.swift | 4 ++-- VDS/Components/TextFields/EntryField/EntryField.swift | 4 ++-- VDS/Components/TileContainer/TileContainer.swift | 9 +++++---- VDS/Extensions/UIView.swift | 3 ++- 9 files changed, 21 insertions(+), 19 deletions(-) diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index b3ffb2bd..40c1139b 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -67,7 +67,7 @@ public class Badge: View, Accessable { isAccessibilityElement = true accessibilityTraits = .staticText - layer.cornerRadius = 2 + layer.cornerRadius = VDSFormControls.borderradius addSubview(label) label.pinToSuperView(.init(top: 2, left: 4, bottom: 2, right: 4)) diff --git a/VDS/Components/Buttons/Button/Button.swift b/VDS/Components/Buttons/Button/Button.swift index ee2c0ab5..43682d96 100644 --- a/VDS/Components/Buttons/Button/Button.swift +++ b/VDS/Components/Buttons/Button/Button.swift @@ -146,7 +146,7 @@ open class Button: ButtonBase, Useable { super.updateView() let bgColor = backgroundColorConfiguration.getColor(self) let borderColor = borderColorConfiguration.getColor(self) - let borderWidth = use == .secondary ? 1.0 : 0.0 + let borderWidth = use == .secondary ? VDSFormControls.widthBorder : 0.0 let buttonHeight = size.height let cornerRadius = size.cornerRadius let minWidth = size.minimumWidth diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 91c08aab..d16c12f4 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -371,8 +371,8 @@ open class CheckboxBase: Control, Accessable, DataTrackable, Errorable { selectorView.backgroundColor = backgroundColor selectorView.layer.borderColor = borderColor.cgColor - selectorView.layer.cornerRadius = 2.0 - selectorView.layer.borderWidth = 1.0 + selectorView.layer.cornerRadius = VDSFormControls.borderradius + selectorView.layer.borderWidth = VDSFormControls.widthBorder if shapeLayer == nil { let bounds = selectorView.bounds diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index 7951c4cd..d9398259 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -281,10 +281,10 @@ open class RadioBoxBase: Control, Accessable, DataTrackable{ //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- - private var strikeThroughLineThickness: CGFloat = 1.0 - private var selectorCornerRadius: CGFloat = 4.0 - private var selectorBorderWidthSelected: CGFloat = 2.0 - private var selectorBorderWidth: CGFloat = 1.0 + private var strikeThroughLineThickness: CGFloat = VDSFormControls.widthBorder + private var selectorCornerRadius: CGFloat = VDSFormControls.borderradius + private var selectorBorderWidthSelected: CGFloat = VDSFormControls.widthBorder + VDSFormControls.widthBorder + private var selectorBorderWidth: CGFloat = VDSFormControls.widthBorder private var backgroundColorConfiguration = ControlColorConfiguration().with { $0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .normal) @@ -311,7 +311,7 @@ open class RadioBoxBase: Control, Accessable, DataTrackable{ //get the colors let backgroundColor = backgroundColorConfiguration.getColor(self) let borderColor = borderColorConfiguration.getColor(self) - let borderWidth = isSelected || isHighlighted ? selectorBorderWidthSelected : selectorBorderWidth + let borderWidth = isSelected ? selectorBorderWidthSelected : selectorBorderWidth selectorView.backgroundColor = backgroundColor selectorView.layer.borderColor = borderColor.cgColor diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index 674a0a6f..3972fcf7 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -373,7 +373,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, Errorable { selectorView.backgroundColor = backgroundColor selectorView.layer.borderColor = borderColor.cgColor selectorView.layer.cornerRadius = selectorView.bounds.width * 0.5 - selectorView.layer.borderWidth = 1.0 + selectorView.layer.borderWidth = VDSFormControls.widthBorder if shapeLayer == nil { let selectedBounds = radioButtonSelectedSize diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift index 5c36c575..e17eef28 100644 --- a/VDS/Components/RadioSwatch/RadioSwatch.swift +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -162,8 +162,8 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable { //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- - private var strikeThroughLineThickness: CGFloat = 1.0 - private var selectorBorderWidth: CGFloat = 1.0 + private var strikeThroughLineThickness: CGFloat = VDSFormControls.widthBorder + private var selectorBorderWidth: CGFloat = VDSFormControls.widthBorder public let swatchSize = CGSize(width: 48, height: 48) public let fillSize = CGSize(width: 36, height: 36) public let disabledAlpha = 0.5 diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index 851fb0e5..ab9c0a98 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -285,8 +285,8 @@ open class EntryField: Control, Accessable { containerView.backgroundColor = backgroundColorConfiguration.getColor(self) containerView.layer.borderColor = borderColorConfiguration.getColor(self).cgColor - containerView.layer.borderWidth = 1 - containerView.layer.cornerRadius = 4 + containerView.layer.borderWidth = VDSFormControls.widthBorder + containerView.layer.cornerRadius = VDSFormControls.borderradius updateTitleLabel() updateErrorLabel() diff --git a/VDS/Components/TileContainer/TileContainer.swift b/VDS/Components/TileContainer/TileContainer.swift index 1f676421..f6086b47 100644 --- a/VDS/Components/TileContainer/TileContainer.swift +++ b/VDS/Components/TileContainer/TileContainer.swift @@ -7,6 +7,7 @@ import Foundation import VDSColorTokens +import VDSFormControlsTokens import UIKit @objc(VDSTileContainer) @@ -181,8 +182,8 @@ open class TileContainer: Control { //corner radius layer.cornerRadius = cornerRadius - backgroundImageView.layer.cornerRadius = 8 - highlightView.layer.cornerRadius = 8 + backgroundImageView.layer.cornerRadius = cornerRadius + highlightView.layer.cornerRadius = cornerRadius } @@ -194,7 +195,7 @@ open class TileContainer: Control { //-------------------------------------------------- // MARK: - Configuration //-------------------------------------------------- - private let cornerRadius = 8.0 + private let cornerRadius = VDSFormControls.borderradius * 2 private var backgroundColorConfig = BackgroundColorConfiguration() @@ -262,7 +263,7 @@ open class TileContainer: Control { } layer.borderColor = borderColorConfig.getColor(self).cgColor - layer.borderWidth = showBorder ? 1 : 0 + layer.borderWidth = showBorder ? VDSFormControls.widthBorder : 0 containerTopConstraint?.constant = padding containerLeadingConstraint?.constant = padding diff --git a/VDS/Extensions/UIView.swift b/VDS/Extensions/UIView.swift index 6db07dd2..951cbbf5 100644 --- a/VDS/Extensions/UIView.swift +++ b/VDS/Extensions/UIView.swift @@ -7,6 +7,7 @@ import Foundation import UIKit +import VDSFormControlsTokens extension UIView { public func pin(_ view: UIView, with edges: UIEdgeInsets = UIEdgeInsets.zero) { @@ -122,7 +123,7 @@ extension UIView { public func debugBorder(show shouldShow: Bool = true, color: UIColor = .red) { if shouldShow { layer.borderColor = color.cgColor - layer.borderWidth = 1 + layer.borderWidth = VDSFormControls.widthBorder } else { layer.borderColor = UIColor.clear.cgColor layer.borderWidth = 0 From b74954dd25afe2a4391dc6befc3866ab9528415d Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 4 Jan 2023 11:30:04 -0600 Subject: [PATCH 02/12] add logic for height Signed-off-by: Matt Bruce --- VDS/Components/TileContainer/TileContainer.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/VDS/Components/TileContainer/TileContainer.swift b/VDS/Components/TileContainer/TileContainer.swift index f6086b47..40efde6d 100644 --- a/VDS/Components/TileContainer/TileContainer.swift +++ b/VDS/Components/TileContainer/TileContainer.swift @@ -82,8 +82,10 @@ open class TileContainer: Control { set { if newValue > 100 { _width = newValue - didChange() + } else { + _width = 100 } + didChange() } } @@ -270,7 +272,7 @@ open class TileContainer: Control { containerBottomConstraint?.constant = -padding containerTrailingConstraint?.constant = -padding - if aspectRatio == .none { + if aspectRatio == .none && height == nil{ widthConstraint?.constant = width heightConstraint?.isActive = false heightGreaterThanConstraint?.isActive = true From 7a550f4eb5190eda27ed967ab7d9c059a263c255 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 4 Jan 2023 11:30:25 -0600 Subject: [PATCH 03/12] added titleLockup config Signed-off-by: Matt Bruce --- VDS/Components/Tilet/Tilet.swift | 109 ++++++++++++++++++++++++------- 1 file changed, 84 insertions(+), 25 deletions(-) diff --git a/VDS/Components/Tilet/Tilet.swift b/VDS/Components/Tilet/Tilet.swift index 417a7f08..1dd1424d 100644 --- a/VDS/Components/Tilet/Tilet.swift +++ b/VDS/Components/Tilet/Tilet.swift @@ -36,7 +36,7 @@ public enum TiletOtherTypographicalStyle: String, Codable, EnumSubset { @objc(VDSTilet) -open class Tilet: View { +open class Tilet: TileContainer { //-------------------------------------------------- // MARK: - Initializers @@ -58,12 +58,68 @@ open class Tilet: View { //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- - private var tileContainer = TileContainer().with { - $0.aspectRatio = .none - $0.surface = .light + private var titleLockup = TitleLockup().with { + let configs = [ + TypographicalStyleDeviceSpacingConfig([.TitleSmall, .BoldTitleSmall], + neighboring: [ + .BodySmall, .BoldBodySmall, + .BodyMedium, .BoldBodyMedium + ], + spacing: 8.0, + deviceType: .iPhone), + + TypographicalStyleDeviceSpacingConfig([.TitleMedium, .BoldTitleMedium, + .TitleLarge, .BoldTitleLarge], + neighboring: [ + .BodySmall, .BoldBodySmall, + .BodyMedium, .BoldBodyMedium, + .BodyLarge, .BoldBodyLarge], + spacing: 8.0, + deviceType: .iPhone), + + TypographicalStyleDeviceSpacingConfig([.TitleXLarge, .BoldTitleXLarge], + neighboring: [ + .BodySmall, .BoldBodySmall, + .BodyMedium, .BoldBodyMedium, + .BodyLarge, .BoldBodyLarge, + .TitleMedium, .BoldTitleMedium + ], + spacing: 12.0, + deviceType: .iPhone), + + TypographicalStyleDeviceSpacingConfig([.TitleSmall, .BoldTitleSmall, + .TitleMedium, .BoldTitleMedium], + neighboring: [ + .BodySmall, .BoldBodySmall, + .BodyMedium, .BoldBodyMedium, + .BodyLarge, .BoldBodyLarge + ], + spacing: 8.0, + deviceType: .iPad), + + TypographicalStyleDeviceSpacingConfig([.TitleLarge, .BoldTitleLarge], + neighboring: [ + .BodySmall, .BoldBodySmall, + .BodyMedium, .BoldBodyMedium, + .BodyLarge, .BoldBodyLarge, + .TitleSmall, .BoldTitleSmall + ], + spacing: 12.0, + deviceType: .iPad), + + TypographicalStyleDeviceSpacingConfig([.TitleXLarge, .BoldTitleXLarge], + neighboring: [ + .BodyLarge, .BoldBodyLarge, + .TitleMedium, .BoldTitleMedium + ], + spacing: 16.0, + deviceType: .iPad) + + ] + + $0.bottomTypographicalStyleSpacingConfig = TypographicalStyleSpacingConfig(configs: configs) } - private var titleLockup = TitleLockup() //-------------------------------------------------- // MARK: - Public Properties @@ -72,8 +128,6 @@ open class Tilet: View { open var titleTypograpicalStyle: TiletTitleTypographicalStyle = .BoldTitleSmall { didSet { didChange() }} open var otherTypograpicalStyle: TiletOtherTypographicalStyle = .BodySmall { didSet { didChange() }} - open var width: CGFloat = 100 { didSet { didChange() }} - private var _textWidth: CGFloat? open var textWidth: CGFloat? { get { _textWidth } @@ -107,15 +161,21 @@ open class Tilet: View { } } + //badge + open var showBadge: Bool = false { didSet { didChange() }} + open var badgeText: String = "" { didSet { didChange() }} + open var badgeColor: BadgeFillColor = .red { didSet { didChange() }} + //text open var titleText: String = "" { didSet { didChange() }} open var titleTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} - open var subTitleText: String = "" { didSet { didChange() }} open var subTitleTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} - open var subTitleColor: Use = .primary { didSet { didChange() }} + //icons + + //-------------------------------------------------- // MARK: - Constraints //-------------------------------------------------- @@ -128,23 +188,25 @@ open class Tilet: View { open override func setup() { super.setup() - addSubview(tileContainer) - tileContainer.pinToSuperView() - tileContainer.addContentView(titleLockup, shouldPin: false) + width = 100 + aspectRatio = .none + containerBackgroundColor = .black + + addContentView(titleLockup, shouldPin: false) titleLockup.pinTop() titleLockup.pinLeading() - titleLockup.pinBottom() + titleLockup.bottomAnchor.constraint(lessThanOrEqualTo: containerView.bottomAnchor).isActive = true //either you are 100% width of the tileContainer.contentView - titleLockupTrailingConstraint = titleLockup.trailingAnchor.constraint(equalTo: tileContainer.containerView.trailingAnchor) + titleLockupTrailingConstraint = titleLockup.trailingAnchor.constraint(equalTo: containerView.trailingAnchor) titleLockupTrailingConstraint?.isActive = true } public override func reset() { super.reset() - tileContainer.reset() - tileContainer.aspectRatio = .none - tileContainer.surface = .light + aspectRatio = .none + surface = .light + containerBackgroundColor = .black titleLockup.reset() @@ -161,14 +223,9 @@ open class Tilet: View { open override func updateView() { super.updateView() - - //flip the color - let flippedColor:TileContainer.ContainerBackgroundColor = surface == .dark ? .white : .black - tileContainer.containerBackgroundColor = flippedColor - tileContainer.width = width - + //flip the surface for the titleLockup - let flippedSurface: Surface = surface == .dark ? .light : .dark + let flippedSurface: Surface = containerBackgroundColor == .black ? .dark : .light titleLockup.surface = flippedSurface //either use textWidth @@ -184,7 +241,7 @@ open class Tilet: View { titleLockupWidthConstraint = NSLayoutConstraint(item: titleLockup, attribute: .width, relatedBy: .equal, - toItem: tileContainer.containerView, + toItem: containerView, attribute: .width, multiplier: textPercentage / 100, constant: 0.0) @@ -206,3 +263,5 @@ open class Tilet: View { titleLockup.subTitleColor = subTitleColor } } + + From 2f603b1a64ed3dd4d3312df5e8d263b595b81309 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 6 Jan 2023 11:40:02 -0600 Subject: [PATCH 04/12] refactored into files Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 8 ++++ VDS/Components/Tilet/TiletBadgeModel.swift | 37 +++++++++++++++++++ .../Tilet/TiletTypographicalStyle.swift | 32 ++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 VDS/Components/Tilet/TiletBadgeModel.swift create mode 100644 VDS/Components/Tilet/TiletTypographicalStyle.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 7ef890b9..77cc6883 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -51,6 +51,8 @@ EA89201328B568D8006B9984 /* RadioBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89201228B568D8006B9984 /* RadioBox.swift */; }; EA89201528B56CF4006B9984 /* RadioBoxGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89201428B56CF4006B9984 /* RadioBoxGroup.swift */; }; EA978EC5291D6AFE00ACC883 /* AnyLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA978EC4291D6AFE00ACC883 /* AnyLabelAttribute.swift */; }; + EA985BE429688F3300F2FF2E /* TiletTypographicalStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BE329688F3300F2FF2E /* TiletTypographicalStyle.swift */; }; + EA985BE629688F6A00F2FF2E /* TiletBadgeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BE529688F6A00F2FF2E /* TiletBadgeModel.swift */; }; EAA5EEB528ECBFB4003B3210 /* ImageLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEB428ECBFB4003B3210 /* ImageLabelAttribute.swift */; }; EAA5EEB728ECC03A003B3210 /* ToolTipLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEB628ECC03A003B3210 /* ToolTipLabelAttribute.swift */; }; EAA5EEB928ECD24B003B3210 /* Icons.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EAA5EEB828ECD24B003B3210 /* Icons.xcassets */; }; @@ -151,6 +153,8 @@ EA89201228B568D8006B9984 /* RadioBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioBox.swift; sourceTree = ""; }; EA89201428B56CF4006B9984 /* RadioBoxGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioBoxGroup.swift; sourceTree = ""; }; EA978EC4291D6AFE00ACC883 /* AnyLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyLabelAttribute.swift; sourceTree = ""; }; + EA985BE329688F3300F2FF2E /* TiletTypographicalStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TiletTypographicalStyle.swift; sourceTree = ""; }; + EA985BE529688F6A00F2FF2E /* TiletBadgeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TiletBadgeModel.swift; sourceTree = ""; }; EAA5EEB428ECBFB4003B3210 /* ImageLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageLabelAttribute.swift; sourceTree = ""; }; EAA5EEB628ECC03A003B3210 /* ToolTipLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolTipLabelAttribute.swift; sourceTree = ""; }; EAA5EEB828ECD24B003B3210 /* Icons.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Icons.xcassets; sourceTree = ""; }; @@ -465,6 +469,8 @@ isa = PBXGroup; children = ( EA5E3057295105A40082B959 /* Tilet.swift */, + EA985BE329688F3300F2FF2E /* TiletTypographicalStyle.swift */, + EA985BE529688F6A00F2FF2E /* TiletBadgeModel.swift */, ); path = Tilet; sourceTree = ""; @@ -724,6 +730,7 @@ EAB1D2EA28AE84AA00DAE764 /* UIControlPublisher.swift in Sources */, EAF7F13328A2A16500B287F5 /* AttachmentLabelAttributeModel.swift in Sources */, EA0FC2C62914222900DF80B4 /* ButtonGroup.swift in Sources */, + EA985BE429688F3300F2FF2E /* TiletTypographicalStyle.swift in Sources */, EA89200628B526D6006B9984 /* CheckboxGroup.swift in Sources */, EAD8D2C128BFDE8B006EB6A6 /* UIGestureRecognizer+Publisher.swift in Sources */, EAF7F0B9289C139800B287F5 /* ColorConfiguration.swift in Sources */, @@ -742,6 +749,7 @@ EA89200228AECF2A006B9984 /* UIButton+Publisher.swift in Sources */, EAF7F0AB289B13FD00B287F5 /* TypographicalStyleLabelAttribute.swift in Sources */, EAB1D29C28A5618900DAE764 /* RadioButtonGroup.swift in Sources */, + EA985BE629688F6A00F2FF2E /* TiletBadgeModel.swift in Sources */, EA336171288B19200071C351 /* VDS.docc in Sources */, EA5E30532950DDA60082B959 /* TitleLockup.swift in Sources */, EAA5EEB528ECBFB4003B3210 /* ImageLabelAttribute.swift in Sources */, diff --git a/VDS/Components/Tilet/TiletBadgeModel.swift b/VDS/Components/Tilet/TiletBadgeModel.swift new file mode 100644 index 00000000..61e68f4c --- /dev/null +++ b/VDS/Components/Tilet/TiletBadgeModel.swift @@ -0,0 +1,37 @@ +// +// TiletBadgeModel.swift +// VDS +// +// Created by Matt Bruce on 1/6/23. +// + +import Foundation + +public struct TiletBadgeModel { + public var text: String = "" + public var fillColor: BadgeFillColor + public var surface: Surface + public var numberOfLines: Int + public var maxWidth: CGFloat? + public init(text: String, fillColor: BadgeFillColor = .red, surface: Surface = .light, numberOfLines: Int = 0, maxWidth: CGFloat? = nil) { + self.text = text + self.fillColor = fillColor + self.surface = surface + self.numberOfLines = numberOfLines + self.maxWidth = maxWidth + } +} + +extension Badge { + public func set(with model: TiletBadgeModel?) { + if let model, !model.text.isEmpty { + text = model.text + fillColor = model.fillColor + numberOfLines = model.numberOfLines + surface = model.surface + maxWidth = model.maxWidth + } else { + reset() + } + } +} diff --git a/VDS/Components/Tilet/TiletTypographicalStyle.swift b/VDS/Components/Tilet/TiletTypographicalStyle.swift new file mode 100644 index 00000000..331f5538 --- /dev/null +++ b/VDS/Components/Tilet/TiletTypographicalStyle.swift @@ -0,0 +1,32 @@ +// +// TiletTypographicalStyle.swift +// VDS +// +// Created by Matt Bruce on 1/6/23. +// + +import Foundation + +public enum TiletTitleTypographicalStyle: String, Codable, EnumSubset { + case TitleXLarge + case BoldTitleXLarge + case TitleLarge + case BoldTitleLarge + case TitleMedium + case BoldTitleMedium + case TitleSmall + case BoldTitleSmall + + public var defaultValue: TitleLockupTitleTypographicalStyle { .BoldTitleSmall } +} + +public enum TiletOtherTypographicalStyle: String, Codable, EnumSubset { + case BodyLarge + case BoldBodyLarge + case BodyMedium + case BoldBodyMedium + case BodySmall + case BoldBodySmall + + public var defaultValue: TitleLockupOtherTypographicalStyle { .BodySmall } +} From f868312b1f037a777eff587a730c88fa27733e6e Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 6 Jan 2023 11:40:19 -0600 Subject: [PATCH 05/12] refactored stackview and added in badge Signed-off-by: Matt Bruce --- VDS/Components/Tilet/Tilet.swift | 200 +++++++++++++++++-------------- 1 file changed, 113 insertions(+), 87 deletions(-) diff --git a/VDS/Components/Tilet/Tilet.swift b/VDS/Components/Tilet/Tilet.swift index 1dd1424d..2fa05dde 100644 --- a/VDS/Components/Tilet/Tilet.swift +++ b/VDS/Components/Tilet/Tilet.swift @@ -10,31 +10,6 @@ import Foundation import VDSColorTokens import UIKit -public enum TiletTitleTypographicalStyle: String, Codable, EnumSubset { - case TitleXLarge - case BoldTitleXLarge - case TitleLarge - case BoldTitleLarge - case TitleMedium - case BoldTitleMedium - case TitleSmall - case BoldTitleSmall - - public var defaultValue: TitleLockupTitleTypographicalStyle { .BoldTitleSmall } -} - -public enum TiletOtherTypographicalStyle: String, Codable, EnumSubset { - case BodyLarge - case BoldBodyLarge - case BodyMedium - case BoldBodyMedium - case BodySmall - case BoldBodySmall - - public var defaultValue: TitleLockupOtherTypographicalStyle { .BodySmall } -} - - @objc(VDSTilet) open class Tilet: TileContainer { @@ -58,12 +33,23 @@ open class Tilet: TileContainer { //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- + private var stackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.axis = .vertical + $0.distribution = .fill + $0.spacing = 5 + } + + private var titleLockupContainerView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } + private var titleLockup = TitleLockup().with { let configs = [ TypographicalStyleDeviceSpacingConfig([.TitleSmall, .BoldTitleSmall], neighboring: [ .BodySmall, .BoldBodySmall, - .BodyMedium, .BoldBodyMedium + .BodyMedium, .BoldBodyMedium ], spacing: 8.0, deviceType: .iPhone), @@ -84,8 +70,8 @@ open class Tilet: TileContainer { .BodyLarge, .BoldBodyLarge, .TitleMedium, .BoldTitleMedium ], - spacing: 12.0, - deviceType: .iPhone), + spacing: 12.0, + deviceType: .iPhone), TypographicalStyleDeviceSpacingConfig([.TitleSmall, .BoldTitleSmall, .TitleMedium, .BoldTitleMedium], @@ -104,30 +90,34 @@ open class Tilet: TileContainer { .BodyLarge, .BoldBodyLarge, .TitleSmall, .BoldTitleSmall ], - spacing: 12.0, - deviceType: .iPad), + spacing: 12.0, + deviceType: .iPad), TypographicalStyleDeviceSpacingConfig([.TitleXLarge, .BoldTitleXLarge], neighboring: [ .BodyLarge, .BoldBodyLarge, .TitleMedium, .BoldTitleMedium ], - spacing: 16.0, - deviceType: .iPad) - - ] + spacing: 16.0, + deviceType: .iPad) + + ] $0.bottomTypographicalStyleSpacingConfig = TypographicalStyleSpacingConfig(configs: configs) } + private var badgeContainerView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } + + private var badge = Badge().with { + $0.fillColor = .red + } //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- //style - open var titleTypograpicalStyle: TiletTitleTypographicalStyle = .BoldTitleSmall { didSet { didChange() }} - open var otherTypograpicalStyle: TiletOtherTypographicalStyle = .BodySmall { didSet { didChange() }} - private var _textWidth: CGFloat? open var textWidth: CGFloat? { get { _textWidth } @@ -161,20 +151,19 @@ open class Tilet: TileContainer { } } - //badge - open var showBadge: Bool = false { didSet { didChange() }} - open var badgeText: String = "" { didSet { didChange() }} - open var badgeColor: BadgeFillColor = .red { didSet { didChange() }} + public var badgeModel: TiletBadgeModel? { didSet { didChange() }} //text + open var titleTypograpicalStyle: TiletTitleTypographicalStyle = .BoldTitleSmall { didSet { didChange() }} + open var otherTypograpicalStyle: TiletOtherTypographicalStyle = .BodySmall { didSet { didChange() }} open var titleText: String = "" { didSet { didChange() }} open var titleTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} open var subTitleText: String = "" { didSet { didChange() }} open var subTitleTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} open var subTitleColor: Use = .primary { didSet { didChange() }} - + //icons - + //-------------------------------------------------- // MARK: - Constraints @@ -192,14 +181,27 @@ open class Tilet: TileContainer { aspectRatio = .none containerBackgroundColor = .black - addContentView(titleLockup, shouldPin: false) - titleLockup.pinTop() - titleLockup.pinLeading() - titleLockup.bottomAnchor.constraint(lessThanOrEqualTo: containerView.bottomAnchor).isActive = true + addContentView(stackView) - //either you are 100% width of the tileContainer.contentView - titleLockupTrailingConstraint = titleLockup.trailingAnchor.constraint(equalTo: containerView.trailingAnchor) + //badge + badgeContainerView.addSubview(badge) + badge + .pinTop() + .pinLeading() + .pinBottom() + badge.trailingAnchor.constraint(lessThanOrEqualTo: badgeContainerView.trailingAnchor).isActive = true + + titleLockupContainerView.addSubview(titleLockup) + titleLockup + .pinTop() + .pinLeading() + .pinBottom() + titleLockupTrailingConstraint = titleLockup.trailingAnchor.constraint(equalTo: titleLockupContainerView.trailingAnchor) titleLockupTrailingConstraint?.isActive = true + + //stackView.addArrangedSubview(badgeContainerView) + //stackView.addArrangedSubview(titleLockupContainerView) + } public override func reset() { @@ -207,60 +209,84 @@ open class Tilet: TileContainer { aspectRatio = .none surface = .light containerBackgroundColor = .black - - titleLockup.reset() + //badge + badge.reset() + badgeModel = nil + + //titleLockup + titleLockup.reset() titleText = "" titleTextAttributes = nil subTitleText = "" subTitleTextAttributes = nil subTitleColor = .primary } - + //-------------------------------------------------- // MARK: - State //-------------------------------------------------- - + open override func updateView() { super.updateView() - - //flip the surface for the titleLockup - let flippedSurface: Surface = containerBackgroundColor == .black ? .dark : .light - titleLockup.surface = flippedSurface - //either use textWidth - if let textWidth { - titleLockupTrailingConstraint?.isActive = false - titleLockupWidthConstraint?.isActive = false - titleLockupWidthConstraint = titleLockup.widthAnchor.constraint(equalToConstant: textWidth) - titleLockupWidthConstraint?.isActive = true - - } else if let textPercentage { - titleLockupTrailingConstraint?.isActive = false - titleLockupWidthConstraint?.isActive = false - titleLockupWidthConstraint = NSLayoutConstraint(item: titleLockup, - attribute: .width, - relatedBy: .equal, - toItem: containerView, - attribute: .width, - multiplier: textPercentage / 100, - constant: 0.0) - titleLockupWidthConstraint?.isActive = true - + //flip the surface for the titleLockup + let titleLockupSurface: Surface = containerBackgroundColor == .black ? .dark : .light + titleLockup.surface = titleLockupSurface + + //update constraints + + //badge + if let badgeModel { + if badgeContainerView.superview == nil { + stackView.insertArrangedSubview(badgeContainerView, at: 0) + } + badge.set(with: badgeModel) } else { - titleLockupWidthConstraint?.isActive = false - titleLockupTrailingConstraint?.isActive = true - + badgeContainerView.removeFromSuperview() } - titleLockup.titleText = titleText - titleLockup.titleTypograpicalStyle = titleTypograpicalStyle.value - titleLockup.titleTextAttributes = titleTextAttributes - - titleLockup.subTitleText = subTitleText - titleLockup.otherTypograpicalStyle = otherTypograpicalStyle.value - titleLockup.subTitleTextAttributes = titleTextAttributes - titleLockup.subTitleColor = subTitleColor + if !titleText.isEmpty || !subTitleText.isEmpty { + if titleLockupContainerView.superview == nil { + stackView.insertArrangedSubview(titleLockupContainerView, at: badgeContainerView.superview == nil ? 0 : 1) + } + + //titleLockup + if let textWidth { + titleLockupTrailingConstraint?.isActive = false + titleLockupWidthConstraint?.isActive = false + titleLockupWidthConstraint = titleLockup.widthAnchor.constraint(equalToConstant: textWidth) + titleLockupWidthConstraint?.isActive = true + + } else if let textPercentage { + titleLockupTrailingConstraint?.isActive = false + titleLockupWidthConstraint?.isActive = false + titleLockupWidthConstraint = NSLayoutConstraint(item: titleLockup, + attribute: .width, + relatedBy: .equal, + toItem: containerView, + attribute: .width, + multiplier: textPercentage / 100, + constant: 0.0) + titleLockupWidthConstraint?.isActive = true + + } else { + titleLockupWidthConstraint?.isActive = false + titleLockupTrailingConstraint?.isActive = true + } + + titleLockup.titleText = titleText + titleLockup.titleTypograpicalStyle = titleTypograpicalStyle.value + titleLockup.titleTextAttributes = titleTextAttributes + + titleLockup.subTitleText = subTitleText + titleLockup.otherTypograpicalStyle = otherTypograpicalStyle.value + titleLockup.subTitleTextAttributes = titleTextAttributes + titleLockup.subTitleColor = subTitleColor + + } else { + titleLockupContainerView.removeFromSuperview() + } } } From 6ec5b10c820f3e79831e3e76dd8b933d6ad92854 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 6 Jan 2023 12:35:49 -0600 Subject: [PATCH 06/12] converted to models for titleLabel, subtitleLabel Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 8 +++ VDS/Components/Tilet/Tilet.swift | 38 +++++++------- VDS/Components/Tilet/TiletSubTitleModel.swift | 49 +++++++++++++++++++ VDS/Components/Tilet/TiletTitleModel.swift | 47 ++++++++++++++++++ .../Tilet/TiletTypographicalStyle.swift | 13 ----- 5 files changed, 121 insertions(+), 34 deletions(-) create mode 100644 VDS/Components/Tilet/TiletSubTitleModel.swift create mode 100644 VDS/Components/Tilet/TiletTitleModel.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 77cc6883..d686322f 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -53,6 +53,8 @@ EA978EC5291D6AFE00ACC883 /* AnyLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA978EC4291D6AFE00ACC883 /* AnyLabelAttribute.swift */; }; EA985BE429688F3300F2FF2E /* TiletTypographicalStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BE329688F3300F2FF2E /* TiletTypographicalStyle.swift */; }; EA985BE629688F6A00F2FF2E /* TiletBadgeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BE529688F6A00F2FF2E /* TiletBadgeModel.swift */; }; + EA985BE82968951C00F2FF2E /* TiletTitleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BE72968951C00F2FF2E /* TiletTitleModel.swift */; }; + EA985BEA29689B6D00F2FF2E /* TiletSubTitleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BE929689B6D00F2FF2E /* TiletSubTitleModel.swift */; }; EAA5EEB528ECBFB4003B3210 /* ImageLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEB428ECBFB4003B3210 /* ImageLabelAttribute.swift */; }; EAA5EEB728ECC03A003B3210 /* ToolTipLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEB628ECC03A003B3210 /* ToolTipLabelAttribute.swift */; }; EAA5EEB928ECD24B003B3210 /* Icons.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EAA5EEB828ECD24B003B3210 /* Icons.xcassets */; }; @@ -155,6 +157,8 @@ EA978EC4291D6AFE00ACC883 /* AnyLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyLabelAttribute.swift; sourceTree = ""; }; EA985BE329688F3300F2FF2E /* TiletTypographicalStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TiletTypographicalStyle.swift; sourceTree = ""; }; EA985BE529688F6A00F2FF2E /* TiletBadgeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TiletBadgeModel.swift; sourceTree = ""; }; + EA985BE72968951C00F2FF2E /* TiletTitleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TiletTitleModel.swift; sourceTree = ""; }; + EA985BE929689B6D00F2FF2E /* TiletSubTitleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TiletSubTitleModel.swift; sourceTree = ""; }; EAA5EEB428ECBFB4003B3210 /* ImageLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageLabelAttribute.swift; sourceTree = ""; }; EAA5EEB628ECC03A003B3210 /* ToolTipLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolTipLabelAttribute.swift; sourceTree = ""; }; EAA5EEB828ECD24B003B3210 /* Icons.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Icons.xcassets; sourceTree = ""; }; @@ -471,6 +475,8 @@ EA5E3057295105A40082B959 /* Tilet.swift */, EA985BE329688F3300F2FF2E /* TiletTypographicalStyle.swift */, EA985BE529688F6A00F2FF2E /* TiletBadgeModel.swift */, + EA985BE72968951C00F2FF2E /* TiletTitleModel.swift */, + EA985BE929689B6D00F2FF2E /* TiletSubTitleModel.swift */, ); path = Tilet; sourceTree = ""; @@ -720,6 +726,8 @@ EAB1D2CD28ABE76100DAE764 /* Withable.swift in Sources */, EAC846F3294B95CE00F685BA /* ButtonGroupCollectionViewCell.swift in Sources */, EAF7F0952899861000B287F5 /* Checkbox.swift in Sources */, + EA985BE82968951C00F2FF2E /* TiletTitleModel.swift in Sources */, + EA985BEA29689B6D00F2FF2E /* TiletSubTitleModel.swift in Sources */, EA3361C9289054C50071C351 /* Surfaceable.swift in Sources */, EAB5FEED2927E1B200998C17 /* ButtonGroupPositionLayout.swift in Sources */, EA4DB30228DCBCA500103EE3 /* Badge.swift in Sources */, diff --git a/VDS/Components/Tilet/Tilet.swift b/VDS/Components/Tilet/Tilet.swift index 2fa05dde..afbff53b 100644 --- a/VDS/Components/Tilet/Tilet.swift +++ b/VDS/Components/Tilet/Tilet.swift @@ -154,13 +154,8 @@ open class Tilet: TileContainer { public var badgeModel: TiletBadgeModel? { didSet { didChange() }} //text - open var titleTypograpicalStyle: TiletTitleTypographicalStyle = .BoldTitleSmall { didSet { didChange() }} - open var otherTypograpicalStyle: TiletOtherTypographicalStyle = .BodySmall { didSet { didChange() }} - open var titleText: String = "" { didSet { didChange() }} - open var titleTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} - open var subTitleText: String = "" { didSet { didChange() }} - open var subTitleTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} - open var subTitleColor: Use = .primary { didSet { didChange() }} + public var titleModel: TiletTitleModel? { didSet { didChange() }} + public var subTitleModel: TiletSubTitleModel? { didSet { didChange() }} //icons @@ -216,11 +211,8 @@ open class Tilet: TileContainer { //titleLockup titleLockup.reset() - titleText = "" - titleTextAttributes = nil - subTitleText = "" - subTitleTextAttributes = nil - subTitleColor = .primary + titleModel = nil + subTitleModel = nil } //-------------------------------------------------- @@ -246,7 +238,17 @@ open class Tilet: TileContainer { badgeContainerView.removeFromSuperview() } - if !titleText.isEmpty || !subTitleText.isEmpty { + var showTitleLockup = false + + if let titleModel, !titleModel.text.isEmpty { + showTitleLockup = true + } + + if let subTitleModel, !subTitleModel.text.isEmpty { + showTitleLockup = true + } + + if showTitleLockup { if titleLockupContainerView.superview == nil { stackView.insertArrangedSubview(titleLockupContainerView, at: badgeContainerView.superview == nil ? 0 : 1) } @@ -275,14 +277,8 @@ open class Tilet: TileContainer { titleLockupTrailingConstraint?.isActive = true } - titleLockup.titleText = titleText - titleLockup.titleTypograpicalStyle = titleTypograpicalStyle.value - titleLockup.titleTextAttributes = titleTextAttributes - - titleLockup.subTitleText = subTitleText - titleLockup.otherTypograpicalStyle = otherTypograpicalStyle.value - titleLockup.subTitleTextAttributes = titleTextAttributes - titleLockup.subTitleColor = subTitleColor + titleLockup.set(with: titleModel) + titleLockup.set(with: subTitleModel) } else { titleLockupContainerView.removeFromSuperview() diff --git a/VDS/Components/Tilet/TiletSubTitleModel.swift b/VDS/Components/Tilet/TiletSubTitleModel.swift new file mode 100644 index 00000000..bfe2d062 --- /dev/null +++ b/VDS/Components/Tilet/TiletSubTitleModel.swift @@ -0,0 +1,49 @@ +// +// TiletSubTitleModel.swift +// VDS +// +// Created by Matt Bruce on 1/6/23. +// + +import Foundation + +public struct TiletSubTitleModel { + public enum SubTitleTypographicalStyle: String, Codable, EnumSubset { + case BodyLarge + case BoldBodyLarge + case BodyMedium + case BoldBodyMedium + case BodySmall + case BoldBodySmall + + public var defaultValue: TitleLockupOtherTypographicalStyle { .BodySmall } + } + + public var text: String = "" + public var textAttributes: [any LabelAttributeModel]? + public var typographicalStyle: SubTitleTypographicalStyle + public var textColor: Use + + public init(text: String, + textColor: Use = .primary, + textAttributes: [any LabelAttributeModel]? = nil, + typographicalStyle: SubTitleTypographicalStyle = .BodySmall) { + self.text = text + self.textColor = textColor + self.textAttributes = textAttributes + self.typographicalStyle = typographicalStyle + } +} + +extension TitleLockup { + public func set(with model: TiletSubTitleModel?) { + if let model, !model.text.isEmpty { + subTitleText = model.text + subTitleTextAttributes = model.textAttributes + otherTypograpicalStyle = model.typographicalStyle.value + subTitleColor = model.textColor + } else { + reset() + } + } +} diff --git a/VDS/Components/Tilet/TiletTitleModel.swift b/VDS/Components/Tilet/TiletTitleModel.swift new file mode 100644 index 00000000..80b04369 --- /dev/null +++ b/VDS/Components/Tilet/TiletTitleModel.swift @@ -0,0 +1,47 @@ +// +// TiletTitleModel.swift +// VDS +// +// Created by Matt Bruce on 1/6/23. +// + +import Foundation + +public struct TiletTitleModel { + public enum TitleTypographicalStyle: String, EnumSubset { + case TitleXLarge + case BoldTitleXLarge + case TitleLarge + case BoldTitleLarge + case TitleMedium + case BoldTitleMedium + case TitleSmall + case BoldTitleSmall + + public var defaultValue: TitleLockupTitleTypographicalStyle { .BoldTitleSmall } + } + + public var text: String = "" + public var textAttributes: [any LabelAttributeModel]? + public var typographicalStyle: TitleTypographicalStyle + + public init(text: String, + textAttributes: [any LabelAttributeModel]? = nil, + typographicalStyle: TitleTypographicalStyle = .BoldTitleSmall) { + self.text = text + self.textAttributes = textAttributes + self.typographicalStyle = typographicalStyle + } +} + +extension TitleLockup { + public func set(with model: TiletTitleModel?) { + if let model, !model.text.isEmpty { + titleText = model.text + titleTextAttributes = model.textAttributes + titleTypograpicalStyle = model.typographicalStyle.value + } else { + reset() + } + } +} diff --git a/VDS/Components/Tilet/TiletTypographicalStyle.swift b/VDS/Components/Tilet/TiletTypographicalStyle.swift index 331f5538..ad2f028e 100644 --- a/VDS/Components/Tilet/TiletTypographicalStyle.swift +++ b/VDS/Components/Tilet/TiletTypographicalStyle.swift @@ -7,19 +7,6 @@ import Foundation -public enum TiletTitleTypographicalStyle: String, Codable, EnumSubset { - case TitleXLarge - case BoldTitleXLarge - case TitleLarge - case BoldTitleLarge - case TitleMedium - case BoldTitleMedium - case TitleSmall - case BoldTitleSmall - - public var defaultValue: TitleLockupTitleTypographicalStyle { .BoldTitleSmall } -} - public enum TiletOtherTypographicalStyle: String, Codable, EnumSubset { case BodyLarge case BoldBodyLarge From 0b295258ee6eaa11627b7c43c0de8bfc37911b88 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 6 Jan 2023 13:04:50 -0600 Subject: [PATCH 07/12] made internal Signed-off-by: Matt Bruce --- VDS/Components/Tilet/TiletSubTitleModel.swift | 2 +- VDS/Components/Tilet/TiletTitleModel.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VDS/Components/Tilet/TiletSubTitleModel.swift b/VDS/Components/Tilet/TiletSubTitleModel.swift index bfe2d062..2ee22d52 100644 --- a/VDS/Components/Tilet/TiletSubTitleModel.swift +++ b/VDS/Components/Tilet/TiletSubTitleModel.swift @@ -36,7 +36,7 @@ public struct TiletSubTitleModel { } extension TitleLockup { - public func set(with model: TiletSubTitleModel?) { + internal func set(with model: TiletSubTitleModel?) { if let model, !model.text.isEmpty { subTitleText = model.text subTitleTextAttributes = model.textAttributes diff --git a/VDS/Components/Tilet/TiletTitleModel.swift b/VDS/Components/Tilet/TiletTitleModel.swift index 80b04369..3676348f 100644 --- a/VDS/Components/Tilet/TiletTitleModel.swift +++ b/VDS/Components/Tilet/TiletTitleModel.swift @@ -35,7 +35,7 @@ public struct TiletTitleModel { } extension TitleLockup { - public func set(with model: TiletTitleModel?) { + internal func set(with model: TiletTitleModel?) { if let model, !model.text.isEmpty { titleText = model.text titleTextAttributes = model.textAttributes From 2009a520601ec6c9b9583f952b9fb9836b1aa98d Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 6 Jan 2023 13:10:45 -0600 Subject: [PATCH 08/12] updated comment Signed-off-by: Matt Bruce --- VDS/Components/Tilet/Tilet.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/VDS/Components/Tilet/Tilet.swift b/VDS/Components/Tilet/Tilet.swift index afbff53b..18ff5950 100644 --- a/VDS/Components/Tilet/Tilet.swift +++ b/VDS/Components/Tilet/Tilet.swift @@ -151,9 +151,8 @@ open class Tilet: TileContainer { } } + //models public var badgeModel: TiletBadgeModel? { didSet { didChange() }} - - //text public var titleModel: TiletTitleModel? { didSet { didChange() }} public var subTitleModel: TiletSubTitleModel? { didSet { didChange() }} From 98242fe0559ad2bbd66d06d8dc2afddc63782a94 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 6 Jan 2023 14:54:49 -0600 Subject: [PATCH 09/12] TitleLockup converted to models Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 22 ++- VDS/Components/TitleLockup/TitleLockup.swift | 125 +++++++----------- .../TitleLockup/TitleLockupEyebrowModel.swift | 22 +++ .../TitleLockupSubTitleModel.swift | 25 ++++ .../TitleLockup/TitleLockupTitleModel.swift | 25 ++++ .../TitleLockup/TitleLockupTypography.swift | 42 ++++++ 6 files changed, 176 insertions(+), 85 deletions(-) create mode 100644 VDS/Components/TitleLockup/TitleLockupEyebrowModel.swift create mode 100644 VDS/Components/TitleLockup/TitleLockupSubTitleModel.swift create mode 100644 VDS/Components/TitleLockup/TitleLockupTitleModel.swift create mode 100644 VDS/Components/TitleLockup/TitleLockupTypography.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index d686322f..1648be01 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -51,10 +51,13 @@ EA89201328B568D8006B9984 /* RadioBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89201228B568D8006B9984 /* RadioBox.swift */; }; EA89201528B56CF4006B9984 /* RadioBoxGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89201428B56CF4006B9984 /* RadioBoxGroup.swift */; }; EA978EC5291D6AFE00ACC883 /* AnyLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA978EC4291D6AFE00ACC883 /* AnyLabelAttribute.swift */; }; - EA985BE429688F3300F2FF2E /* TiletTypographicalStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BE329688F3300F2FF2E /* TiletTypographicalStyle.swift */; }; EA985BE629688F6A00F2FF2E /* TiletBadgeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BE529688F6A00F2FF2E /* TiletBadgeModel.swift */; }; EA985BE82968951C00F2FF2E /* TiletTitleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BE72968951C00F2FF2E /* TiletTitleModel.swift */; }; EA985BEA29689B6D00F2FF2E /* TiletSubTitleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BE929689B6D00F2FF2E /* TiletSubTitleModel.swift */; }; + EA985BEC2968A91200F2FF2E /* TitleLockupTitleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BEB2968A91200F2FF2E /* TitleLockupTitleModel.swift */; }; + EA985BEE2968A92400F2FF2E /* TitleLockupSubTitleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BED2968A92400F2FF2E /* TitleLockupSubTitleModel.swift */; }; + EA985BF02968A93600F2FF2E /* TitleLockupEyebrowModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BEF2968A93600F2FF2E /* TitleLockupEyebrowModel.swift */; }; + EA985BF22968B5BB00F2FF2E /* TitleLockupTypography.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BF12968B5BB00F2FF2E /* TitleLockupTypography.swift */; }; EAA5EEB528ECBFB4003B3210 /* ImageLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEB428ECBFB4003B3210 /* ImageLabelAttribute.swift */; }; EAA5EEB728ECC03A003B3210 /* ToolTipLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEB628ECC03A003B3210 /* ToolTipLabelAttribute.swift */; }; EAA5EEB928ECD24B003B3210 /* Icons.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EAA5EEB828ECD24B003B3210 /* Icons.xcassets */; }; @@ -155,10 +158,13 @@ EA89201228B568D8006B9984 /* RadioBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioBox.swift; sourceTree = ""; }; EA89201428B56CF4006B9984 /* RadioBoxGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioBoxGroup.swift; sourceTree = ""; }; EA978EC4291D6AFE00ACC883 /* AnyLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyLabelAttribute.swift; sourceTree = ""; }; - EA985BE329688F3300F2FF2E /* TiletTypographicalStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TiletTypographicalStyle.swift; sourceTree = ""; }; EA985BE529688F6A00F2FF2E /* TiletBadgeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TiletBadgeModel.swift; sourceTree = ""; }; EA985BE72968951C00F2FF2E /* TiletTitleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TiletTitleModel.swift; sourceTree = ""; }; EA985BE929689B6D00F2FF2E /* TiletSubTitleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TiletSubTitleModel.swift; sourceTree = ""; }; + EA985BEB2968A91200F2FF2E /* TitleLockupTitleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupTitleModel.swift; sourceTree = ""; }; + EA985BED2968A92400F2FF2E /* TitleLockupSubTitleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupSubTitleModel.swift; sourceTree = ""; }; + EA985BEF2968A93600F2FF2E /* TitleLockupEyebrowModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupEyebrowModel.swift; sourceTree = ""; }; + EA985BF12968B5BB00F2FF2E /* TitleLockupTypography.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupTypography.swift; sourceTree = ""; }; EAA5EEB428ECBFB4003B3210 /* ImageLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageLabelAttribute.swift; sourceTree = ""; }; EAA5EEB628ECC03A003B3210 /* ToolTipLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolTipLabelAttribute.swift; sourceTree = ""; }; EAA5EEB828ECD24B003B3210 /* Icons.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Icons.xcassets; sourceTree = ""; }; @@ -465,6 +471,10 @@ isa = PBXGroup; children = ( EA5E30522950DDA60082B959 /* TitleLockup.swift */, + EA985BEF2968A93600F2FF2E /* TitleLockupEyebrowModel.swift */, + EA985BED2968A92400F2FF2E /* TitleLockupSubTitleModel.swift */, + EA985BEB2968A91200F2FF2E /* TitleLockupTitleModel.swift */, + EA985BF12968B5BB00F2FF2E /* TitleLockupTypography.swift */, ); path = TitleLockup; sourceTree = ""; @@ -473,10 +483,9 @@ isa = PBXGroup; children = ( EA5E3057295105A40082B959 /* Tilet.swift */, - EA985BE329688F3300F2FF2E /* TiletTypographicalStyle.swift */, EA985BE529688F6A00F2FF2E /* TiletBadgeModel.swift */, - EA985BE72968951C00F2FF2E /* TiletTitleModel.swift */, EA985BE929689B6D00F2FF2E /* TiletSubTitleModel.swift */, + EA985BE72968951C00F2FF2E /* TiletTitleModel.swift */, ); path = Tilet; sourceTree = ""; @@ -723,6 +732,8 @@ EA978EC5291D6AFE00ACC883 /* AnyLabelAttribute.swift in Sources */, EA33622C2891E73B0071C351 /* FontProtocol.swift in Sources */, EAF7F11728A1475A00B287F5 /* RadioButton.swift in Sources */, + EA985BEE2968A92400F2FF2E /* TitleLockupSubTitleModel.swift in Sources */, + EA985BF22968B5BB00F2FF2E /* TitleLockupTypography.swift in Sources */, EAB1D2CD28ABE76100DAE764 /* Withable.swift in Sources */, EAC846F3294B95CE00F685BA /* ButtonGroupCollectionViewCell.swift in Sources */, EAF7F0952899861000B287F5 /* Checkbox.swift in Sources */, @@ -738,7 +749,6 @@ EAB1D2EA28AE84AA00DAE764 /* UIControlPublisher.swift in Sources */, EAF7F13328A2A16500B287F5 /* AttachmentLabelAttributeModel.swift in Sources */, EA0FC2C62914222900DF80B4 /* ButtonGroup.swift in Sources */, - EA985BE429688F3300F2FF2E /* TiletTypographicalStyle.swift in Sources */, EA89200628B526D6006B9984 /* CheckboxGroup.swift in Sources */, EAD8D2C128BFDE8B006EB6A6 /* UIGestureRecognizer+Publisher.swift in Sources */, EAF7F0B9289C139800B287F5 /* ColorConfiguration.swift in Sources */, @@ -759,6 +769,7 @@ EAB1D29C28A5618900DAE764 /* RadioButtonGroup.swift in Sources */, EA985BE629688F6A00F2FF2E /* TiletBadgeModel.swift in Sources */, EA336171288B19200071C351 /* VDS.docc in Sources */, + EA985BF02968A93600F2FF2E /* TitleLockupEyebrowModel.swift in Sources */, EA5E30532950DDA60082B959 /* TitleLockup.swift in Sources */, EAA5EEB528ECBFB4003B3210 /* ImageLabelAttribute.swift in Sources */, EAB5FF0129424ACB00998C17 /* UIControl.swift in Sources */, @@ -778,6 +789,7 @@ EA3361A8288B23300071C351 /* UIColor.swift in Sources */, EAC9257D29119B5400091998 /* TextLink.swift in Sources */, EA1F266628B945070033E859 /* RadioSwatchGroup.swift in Sources */, + EA985BEC2968A91200F2FF2E /* TitleLockupTitleModel.swift in Sources */, 5FC35BE328D51405004EBEAC /* Button.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/VDS/Components/TitleLockup/TitleLockup.swift b/VDS/Components/TitleLockup/TitleLockup.swift index 958d7a81..74865ac3 100644 --- a/VDS/Components/TitleLockup/TitleLockup.swift +++ b/VDS/Components/TitleLockup/TitleLockup.swift @@ -23,40 +23,6 @@ public enum TitleLockupTextPosition: String, Codable, CaseIterable { } } -public enum TitleLockupTitleTypographicalStyle: String, Codable, EnumSubset { - - case FeatureMedium - case BoldFeatureMedium - case FeatureSmall - case BoldFeatureSmall - case FeatureXSmall - case BoldFeatureXSmall - - case Title2XLarge - case BoldTitle2XLarge - case TitleXLarge - case BoldTitleXLarge - case TitleLarge - case BoldTitleLarge - case TitleMedium - case BoldTitleMedium - case TitleSmall - case BoldTitleSmall - - public var defaultValue: TypographicalStyle {.BoldFeatureXSmall } -} - -public enum TitleLockupOtherTypographicalStyle: String, Codable, EnumSubset { - case BodyLarge - case BoldBodyLarge - case BodyMedium - case BoldBodyMedium - case BodySmall - case BoldBodySmall - - public var defaultValue: TypographicalStyle {.BodyLarge } -} - @objc(VDSTitleLockup) open class TitleLockup: View { @@ -214,30 +180,26 @@ open class TitleLockup: View { open var textPosition: TitleLockupTextPosition = .left { didSet { didChange() }} //style - open var titleTypograpicalStyle: TitleLockupTitleTypographicalStyle = .BoldFeatureXSmall { didSet { didChange() }} open var otherTypograpicalStyle: TitleLockupOtherTypographicalStyle = UIDevice.isIPad ? .BodyLarge : .BodyMedium { didSet { didChange() }} //first row open var eyebrowLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) } - open var eyebrowText: String = "" { didSet { didChange() }} - open var eyebrowTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} + open var eyebrowModel: TitleLockupEyebrowModel? { didSet { didChange() }} //second row open var titleLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) } - open var titleText: String = "" { didSet { didChange() }} - open var titleTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} + open var titleModel: TitleLockupTitleModel? { didSet { didChange() }} //third row open var subTitleLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) } - open var subTitleText: String = "" { didSet { didChange() }} - open var subTitleTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} - open var subTitleColor: Use = .primary { didSet { didChange() }} + open var subTitleModel: TitleLockupSubTitleModel? { didSet { didChange() }} + //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- @@ -266,14 +228,9 @@ open class TitleLockup: View { textPosition = .left - eyebrowText = "" - eyebrowTextAttributes = nil - titleText = "" - titleTextAttributes = nil - subTitleText = "" - subTitleTextAttributes = nil - titleTextAttributes = nil - titleTypograpicalStyle = .BoldFeatureXSmall + eyebrowModel = nil + titleModel = nil + subTitleModel = nil otherTypograpicalStyle = .BodyLarge } @@ -285,48 +242,56 @@ open class TitleLockup: View { super.updateView() let allLabelsTextPosition = textPosition.labelTextPosition + var eyebrowTextIsEmpty = true + var titleTextIsEmpty = true + var subTitleTextIsEmpty = true - eyebrowLabel.textPosition = allLabelsTextPosition - eyebrowLabel.typograpicalStyle = otherTypograpicalStyle.value - eyebrowLabel.text = eyebrowText - eyebrowLabel.attributes = eyebrowTextAttributes - eyebrowLabel.surface = surface + if let eyebrowModel, !eyebrowModel.text.isEmpty { + eyebrowTextIsEmpty = false + eyebrowLabel.textPosition = allLabelsTextPosition + eyebrowLabel.typograpicalStyle = otherTypograpicalStyle.value + eyebrowLabel.text = eyebrowModel.text + eyebrowLabel.attributes = eyebrowModel.textAttributes + eyebrowLabel.numberOfLines = eyebrowModel.numberOfLines + eyebrowLabel.surface = surface + } - titleLabel.textPosition = allLabelsTextPosition - titleLabel.typograpicalStyle = titleTypograpicalStyle.value - titleLabel.text = titleText - titleLabel.attributes = titleTextAttributes - titleLabel.surface = surface + if let titleModel, !titleModel.text.isEmpty { + titleTextIsEmpty = false + titleLabel.textPosition = allLabelsTextPosition + titleLabel.typograpicalStyle = titleModel.typographicalStyle.value + titleLabel.text = titleModel.text + titleLabel.attributes = titleModel.textAttributes + titleLabel.numberOfLines = titleModel.numberOfLines + titleLabel.surface = surface + } + + if let subTitleModel, !subTitleModel.text.isEmpty { + subTitleTextIsEmpty = false + subTitleLabel.textPosition = allLabelsTextPosition + subTitleLabel.typograpicalStyle = otherTypograpicalStyle.value + subTitleLabel.text = subTitleModel.text + subTitleLabel.attributes = subTitleModel.textAttributes + subTitleLabel.numberOfLines = subTitleModel.numberOfLines + subTitleLabel.surface = surface + subTitleLabel.disabled = subTitleModel.textColor == .secondary + } - subTitleLabel.textPosition = allLabelsTextPosition - subTitleLabel.typograpicalStyle = otherTypograpicalStyle.value - subTitleLabel.text = subTitleText - subTitleLabel.attributes = subTitleTextAttributes - subTitleLabel.surface = surface - subTitleLabel.disabled = subTitleColor == .secondary - //if both first 2 rows not empty set spacing - if !eyebrowText.isEmpty && !titleText.isEmpty { - stackView.spacing = getTopSpacing() + if let eyebrowModel, let titleModel, !eyebrowModel.text.isEmpty, !titleModel.text.isEmpty { + stackView.spacing = topTypographicalStyleSpacingConfig.spacing(for: titleModel.typographicalStyle.value, neighboring: otherTypograpicalStyle.value) } else { stackView.spacing = 0.0 } //if either first 2 rows not empty and subtile not empty, create space else collapse - if (!eyebrowText.isEmpty || !titleText.isEmpty) && !subTitleText.isEmpty { - stackView.setCustomSpacing(getBottomSpacing(), after: titleLabel) - } else if (!eyebrowText.isEmpty || !titleText.isEmpty) && subTitleText.isEmpty { + if let titleModel, (!eyebrowTextIsEmpty || !titleTextIsEmpty) && !subTitleTextIsEmpty { + let bottomSpace = bottomTypographicalStyleSpacingConfig.spacing(for: titleModel.typographicalStyle.value, neighboring: otherTypograpicalStyle.value) + stackView.setCustomSpacing(bottomSpace, after: titleLabel) + } else if (!eyebrowTextIsEmpty || !titleTextIsEmpty) && subTitleTextIsEmpty { stackView.setCustomSpacing(0.0, after: titleLabel) } } - - open func getTopSpacing() -> CGFloat { - topTypographicalStyleSpacingConfig.spacing(for: titleTypograpicalStyle.value, neighboring: otherTypograpicalStyle.value) - } - - open func getBottomSpacing() -> CGFloat { - bottomTypographicalStyleSpacingConfig.spacing(for: titleTypograpicalStyle.value, neighboring: otherTypograpicalStyle.value) - } } extension TypographicalStyle { diff --git a/VDS/Components/TitleLockup/TitleLockupEyebrowModel.swift b/VDS/Components/TitleLockup/TitleLockupEyebrowModel.swift new file mode 100644 index 00000000..786d3b09 --- /dev/null +++ b/VDS/Components/TitleLockup/TitleLockupEyebrowModel.swift @@ -0,0 +1,22 @@ +// +// TitleLockupEyebrowModel.swift +// VDS +// +// Created by Matt Bruce on 1/6/23. +// + +import Foundation + +public struct TitleLockupEyebrowModel { + public var text: String + public var textAttributes: [any LabelAttributeModel]? + public var numberOfLines: Int + + public init(text: String, + textAttributes: [any LabelAttributeModel]? = nil, + numberOfLines: Int = 0) { + self.text = text + self.textAttributes = textAttributes + self.numberOfLines = numberOfLines + } +} diff --git a/VDS/Components/TitleLockup/TitleLockupSubTitleModel.swift b/VDS/Components/TitleLockup/TitleLockupSubTitleModel.swift new file mode 100644 index 00000000..f5b1380b --- /dev/null +++ b/VDS/Components/TitleLockup/TitleLockupSubTitleModel.swift @@ -0,0 +1,25 @@ +// +// TitleLockupSubTitleModel.swift +// VDS +// +// Created by Matt Bruce on 1/6/23. +// + +import Foundation + +public struct TitleLockupSubTitleModel { + public var text: String + public var textColor: Use + public var textAttributes: [any LabelAttributeModel]? + public var numberOfLines: Int + + public init(text: String, + textColor: Use = .primary, + textAttributes: [any LabelAttributeModel]? = nil, + numberOfLines: Int = 0) { + self.text = text + self.textColor = textColor + self.textAttributes = textAttributes + self.numberOfLines = numberOfLines + } +} diff --git a/VDS/Components/TitleLockup/TitleLockupTitleModel.swift b/VDS/Components/TitleLockup/TitleLockupTitleModel.swift new file mode 100644 index 00000000..c351206c --- /dev/null +++ b/VDS/Components/TitleLockup/TitleLockupTitleModel.swift @@ -0,0 +1,25 @@ +// +// TitleLockupTitleModel.swift +// VDS +// +// Created by Matt Bruce on 1/6/23. +// + +import Foundation + +public struct TitleLockupTitleModel { + public var text: String + public var textAttributes: [any LabelAttributeModel]? + public var typographicalStyle: TitleLockupTitleTypographicalStyle + public var numberOfLines: Int + + public init(text: String, + textAttributes: [any LabelAttributeModel]? = nil, + typographicalStyle: TitleLockupTitleTypographicalStyle = .BoldFeatureXSmall, + numberOfLines: Int = 0) { + self.text = text + self.textAttributes = textAttributes + self.typographicalStyle = typographicalStyle + self.numberOfLines = numberOfLines + } +} diff --git a/VDS/Components/TitleLockup/TitleLockupTypography.swift b/VDS/Components/TitleLockup/TitleLockupTypography.swift new file mode 100644 index 00000000..0e67d58a --- /dev/null +++ b/VDS/Components/TitleLockup/TitleLockupTypography.swift @@ -0,0 +1,42 @@ +// +// TitleLockupTypography.swift +// VDS +// +// Created by Matt Bruce on 1/6/23. +// + +import Foundation + +public enum TitleLockupTitleTypographicalStyle: String, Codable, EnumSubset { + + case FeatureMedium + case BoldFeatureMedium + case FeatureSmall + case BoldFeatureSmall + case FeatureXSmall + case BoldFeatureXSmall + + case Title2XLarge + case BoldTitle2XLarge + case TitleXLarge + case BoldTitleXLarge + case TitleLarge + case BoldTitleLarge + case TitleMedium + case BoldTitleMedium + case TitleSmall + case BoldTitleSmall + + public var defaultValue: TypographicalStyle {.BoldFeatureXSmall } +} + +public enum TitleLockupOtherTypographicalStyle: String, Codable, EnumSubset { + case BodyLarge + case BoldBodyLarge + case BodyMedium + case BoldBodyMedium + case BodySmall + case BoldBodySmall + + public var defaultValue: TypographicalStyle {.BodyLarge } +} From 7819cd8646a7540a5e2ab43d734d30959ad6a628 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 6 Jan 2023 14:55:04 -0600 Subject: [PATCH 10/12] updated to converted titleLockup Signed-off-by: Matt Bruce --- VDS/Components/Tilet/TiletSubTitleModel.swift | 5 ++--- VDS/Components/Tilet/TiletTitleModel.swift | 4 +--- .../Tilet/TiletTypographicalStyle.swift | 19 ------------------- 3 files changed, 3 insertions(+), 25 deletions(-) delete mode 100644 VDS/Components/Tilet/TiletTypographicalStyle.swift diff --git a/VDS/Components/Tilet/TiletSubTitleModel.swift b/VDS/Components/Tilet/TiletSubTitleModel.swift index 2ee22d52..530638ce 100644 --- a/VDS/Components/Tilet/TiletSubTitleModel.swift +++ b/VDS/Components/Tilet/TiletSubTitleModel.swift @@ -38,12 +38,11 @@ public struct TiletSubTitleModel { extension TitleLockup { internal func set(with model: TiletSubTitleModel?) { if let model, !model.text.isEmpty { - subTitleText = model.text - subTitleTextAttributes = model.textAttributes + subTitleModel = TitleLockupSubTitleModel(text: model.text, textColor: model.textColor, textAttributes: model.textAttributes) otherTypograpicalStyle = model.typographicalStyle.value - subTitleColor = model.textColor } else { reset() } } + } diff --git a/VDS/Components/Tilet/TiletTitleModel.swift b/VDS/Components/Tilet/TiletTitleModel.swift index 3676348f..9e7be868 100644 --- a/VDS/Components/Tilet/TiletTitleModel.swift +++ b/VDS/Components/Tilet/TiletTitleModel.swift @@ -37,9 +37,7 @@ public struct TiletTitleModel { extension TitleLockup { internal func set(with model: TiletTitleModel?) { if let model, !model.text.isEmpty { - titleText = model.text - titleTextAttributes = model.textAttributes - titleTypograpicalStyle = model.typographicalStyle.value + titleModel = TitleLockupTitleModel(text: model.text, textAttributes: model.textAttributes, typographicalStyle: model.typographicalStyle.value) } else { reset() } diff --git a/VDS/Components/Tilet/TiletTypographicalStyle.swift b/VDS/Components/Tilet/TiletTypographicalStyle.swift deleted file mode 100644 index ad2f028e..00000000 --- a/VDS/Components/Tilet/TiletTypographicalStyle.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// TiletTypographicalStyle.swift -// VDS -// -// Created by Matt Bruce on 1/6/23. -// - -import Foundation - -public enum TiletOtherTypographicalStyle: String, Codable, EnumSubset { - case BodyLarge - case BoldBodyLarge - case BodyMedium - case BoldBodyMedium - case BodySmall - case BoldBodySmall - - public var defaultValue: TitleLockupOtherTypographicalStyle { .BodySmall } -} From 3db7cf0a42fc1eddf91c7be2cbc7aaa4c92e3e46 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 6 Jan 2023 15:14:08 -0600 Subject: [PATCH 11/12] udpated to fix bug in resetting Signed-off-by: Matt Bruce --- VDS/Components/Tilet/TiletSubTitleModel.swift | 2 +- VDS/Components/Tilet/TiletTitleModel.swift | 2 +- VDS/Components/TitleLockup/TitleLockup.swift | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/VDS/Components/Tilet/TiletSubTitleModel.swift b/VDS/Components/Tilet/TiletSubTitleModel.swift index 530638ce..84932595 100644 --- a/VDS/Components/Tilet/TiletSubTitleModel.swift +++ b/VDS/Components/Tilet/TiletSubTitleModel.swift @@ -41,7 +41,7 @@ extension TitleLockup { subTitleModel = TitleLockupSubTitleModel(text: model.text, textColor: model.textColor, textAttributes: model.textAttributes) otherTypograpicalStyle = model.typographicalStyle.value } else { - reset() + subTitleModel = nil } } diff --git a/VDS/Components/Tilet/TiletTitleModel.swift b/VDS/Components/Tilet/TiletTitleModel.swift index 9e7be868..f2e1b131 100644 --- a/VDS/Components/Tilet/TiletTitleModel.swift +++ b/VDS/Components/Tilet/TiletTitleModel.swift @@ -39,7 +39,7 @@ extension TitleLockup { if let model, !model.text.isEmpty { titleModel = TitleLockupTitleModel(text: model.text, textAttributes: model.textAttributes, typographicalStyle: model.typographicalStyle.value) } else { - reset() + titleModel = nil } } } diff --git a/VDS/Components/TitleLockup/TitleLockup.swift b/VDS/Components/TitleLockup/TitleLockup.swift index 74865ac3..33633723 100644 --- a/VDS/Components/TitleLockup/TitleLockup.swift +++ b/VDS/Components/TitleLockup/TitleLockup.swift @@ -254,8 +254,10 @@ open class TitleLockup: View { eyebrowLabel.attributes = eyebrowModel.textAttributes eyebrowLabel.numberOfLines = eyebrowModel.numberOfLines eyebrowLabel.surface = surface + } else { + eyebrowLabel.reset() } - + if let titleModel, !titleModel.text.isEmpty { titleTextIsEmpty = false titleLabel.textPosition = allLabelsTextPosition @@ -264,6 +266,8 @@ open class TitleLockup: View { titleLabel.attributes = titleModel.textAttributes titleLabel.numberOfLines = titleModel.numberOfLines titleLabel.surface = surface + } else { + titleLabel.reset() } if let subTitleModel, !subTitleModel.text.isEmpty { @@ -275,6 +279,8 @@ open class TitleLockup: View { subTitleLabel.numberOfLines = subTitleModel.numberOfLines subTitleLabel.surface = surface subTitleLabel.disabled = subTitleModel.textColor == .secondary + } else { + subTitleLabel.reset() } //if both first 2 rows not empty set spacing @@ -291,6 +297,11 @@ open class TitleLockup: View { } else if (!eyebrowTextIsEmpty || !titleTextIsEmpty) && subTitleTextIsEmpty { stackView.setCustomSpacing(0.0, after: titleLabel) } + + //hide/show + eyebrowLabel.isHidden = eyebrowTextIsEmpty + titleLabel.isHidden = titleTextIsEmpty + subTitleLabel.isHidden = subTitleTextIsEmpty } } From e41812e7c78fe8876164a3be641f595b4c886da0 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 6 Jan 2023 15:29:37 -0600 Subject: [PATCH 12/12] removed helper methods Signed-off-by: Matt Bruce --- VDS/Components/Tilet/Tilet.swift | 16 +++++++++++++--- VDS/Components/Tilet/TiletBadgeModel.swift | 14 -------------- VDS/Components/Tilet/TiletSubTitleModel.swift | 16 +++++----------- VDS/Components/Tilet/TiletTitleModel.swift | 12 +++--------- 4 files changed, 21 insertions(+), 37 deletions(-) diff --git a/VDS/Components/Tilet/Tilet.swift b/VDS/Components/Tilet/Tilet.swift index 18ff5950..5c44503a 100644 --- a/VDS/Components/Tilet/Tilet.swift +++ b/VDS/Components/Tilet/Tilet.swift @@ -232,8 +232,13 @@ open class Tilet: TileContainer { if badgeContainerView.superview == nil { stackView.insertArrangedSubview(badgeContainerView, at: 0) } - badge.set(with: badgeModel) + badge.text = badgeModel.text + badge.fillColor = badgeModel.fillColor + badge.numberOfLines = badgeModel.numberOfLines + badge.surface = badgeModel.surface + badge.maxWidth = badgeModel.maxWidth } else { + badge.reset() badgeContainerView.removeFromSuperview() } @@ -276,9 +281,14 @@ open class Tilet: TileContainer { titleLockupTrailingConstraint?.isActive = true } - titleLockup.set(with: titleModel) - titleLockup.set(with: subTitleModel) + //set models + titleLockup.titleModel = titleModel?.toTitleLockupTitleModel() + titleLockup.subTitleModel = subTitleModel?.toTitleLockupSubTitleModel() + if let style = subTitleModel?.typographicalStyle.value { + titleLockup.otherTypograpicalStyle = style + } + } else { titleLockupContainerView.removeFromSuperview() } diff --git a/VDS/Components/Tilet/TiletBadgeModel.swift b/VDS/Components/Tilet/TiletBadgeModel.swift index 61e68f4c..fbad4d5f 100644 --- a/VDS/Components/Tilet/TiletBadgeModel.swift +++ b/VDS/Components/Tilet/TiletBadgeModel.swift @@ -21,17 +21,3 @@ public struct TiletBadgeModel { self.maxWidth = maxWidth } } - -extension Badge { - public func set(with model: TiletBadgeModel?) { - if let model, !model.text.isEmpty { - text = model.text - fillColor = model.fillColor - numberOfLines = model.numberOfLines - surface = model.surface - maxWidth = model.maxWidth - } else { - reset() - } - } -} diff --git a/VDS/Components/Tilet/TiletSubTitleModel.swift b/VDS/Components/Tilet/TiletSubTitleModel.swift index 84932595..10161008 100644 --- a/VDS/Components/Tilet/TiletSubTitleModel.swift +++ b/VDS/Components/Tilet/TiletSubTitleModel.swift @@ -33,16 +33,10 @@ public struct TiletSubTitleModel { self.textAttributes = textAttributes self.typographicalStyle = typographicalStyle } -} - -extension TitleLockup { - internal func set(with model: TiletSubTitleModel?) { - if let model, !model.text.isEmpty { - subTitleModel = TitleLockupSubTitleModel(text: model.text, textColor: model.textColor, textAttributes: model.textAttributes) - otherTypograpicalStyle = model.typographicalStyle.value - } else { - subTitleModel = nil - } - } + public func toTitleLockupSubTitleModel() -> TitleLockupSubTitleModel { + TitleLockupSubTitleModel(text: text, + textColor: textColor, + textAttributes: textAttributes) + } } diff --git a/VDS/Components/Tilet/TiletTitleModel.swift b/VDS/Components/Tilet/TiletTitleModel.swift index f2e1b131..179c543a 100644 --- a/VDS/Components/Tilet/TiletTitleModel.swift +++ b/VDS/Components/Tilet/TiletTitleModel.swift @@ -32,14 +32,8 @@ public struct TiletTitleModel { self.textAttributes = textAttributes self.typographicalStyle = typographicalStyle } -} - -extension TitleLockup { - internal func set(with model: TiletTitleModel?) { - if let model, !model.text.isEmpty { - titleModel = TitleLockupTitleModel(text: model.text, textAttributes: model.textAttributes, typographicalStyle: model.typographicalStyle.value) - } else { - titleModel = nil - } + + public func toTitleLockupTitleModel() -> TitleLockupTitleModel { + TitleLockupTitleModel(text: text, textAttributes: textAttributes, typographicalStyle: typographicalStyle.value) } }