From 4d362f41add272949e72fa61d1e5f9eb4016b07e Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Fri, 28 Oct 2022 10:27:30 -0400 Subject: [PATCH 01/17] Open it up --- VDS/Components/Checkbox/Checkbox.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 303d7f81..f7213864 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -232,7 +232,7 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er } } - public override func reset() { + open override func reset() { super.reset() updateSelector() setAccessibilityLabel() From 42d3fc5c9a30768ec342ceedca3591ef84fe8cfc Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Thu, 10 Nov 2022 09:44:38 -0500 Subject: [PATCH 02/17] Adding dummy test code. --- .../Attributes/LabelAttributeModel.swift | 27 +++++++++++++++++++ VDS/Typography/Typography.swift | 17 ++++++++++++ 2 files changed, 44 insertions(+) diff --git a/VDS/Components/Label/Attributes/LabelAttributeModel.swift b/VDS/Components/Label/Attributes/LabelAttributeModel.swift index c3209f68..8d5c02e1 100644 --- a/VDS/Components/Label/Attributes/LabelAttributeModel.swift +++ b/VDS/Components/Label/Attributes/LabelAttributeModel.swift @@ -22,5 +22,32 @@ extension LabelAttributeModel { public static func == (lhs: any LabelAttributeModel, rhs: any LabelAttributeModel) -> Bool { lhs.isEqual(rhs) } +} + +public extension NSAttributedString { + func createAttributeModels() -> [(any LabelAttributeModel)] { + var attributes: [any VDS.LabelAttributeModel] = [] + enumerateAttributes(in: NSMakeRange(0, length)) { attributeMap, range, stop in + attributeMap.forEach { (key: NSAttributedString.Key, value: Any) in + if let attribute = NSAttributedString.createAttributeModelFor(key: key, range: range, value: value) { + attributes.append(attribute) + } + } + } + return attributes + } + + static func createAttributeModelFor(key: NSAttributedString.Key, range: NSRange, value: Any) -> (any LabelAttributeModel)? { + switch key { + case NSAttributedString.Key.font: + let value = value as! UIFont + let style = TypographicalStyle.style(for: value.fontName, size: value.pointSize) + return FontLabelAttribute(location: range.location, length: range.length, style: style) + case NSAttributedString.Key.foregroundColor: + return ColorLabelAttribute(location: range.location, length: range.length, color: value as! UIColor) + default: + return nil + } + } } diff --git a/VDS/Typography/Typography.swift b/VDS/Typography/Typography.swift index e8b8c2ba..92ff5e9a 100644 --- a/VDS/Typography/Typography.swift +++ b/VDS/Typography/Typography.swift @@ -261,3 +261,20 @@ extension TypographicalStyle { } } +extension TypographicalStyle { + public static func style(for fontName: String, size: CGFloat) -> TypographicalStyle { + //filter all styles by fontName + let styles = allCases.filter{$0.fontFace.fontName == fontName }.sorted { lhs, rhs in lhs.pointSize < rhs.pointSize } + //if there are no styles then return defaultStyle + guard styles.count > 0 else { return defaultStyle } + styles.forEach{print("\($0.rawValue): \($0.pointSize)")} + //if there is an exact match on a style with this pointSize then return it + if let style = styles.first(where: {$0.pointSize == size }) { + return style + } else if let largerIndex = styles.firstIndex(where: { $0.pointSize > size}) { //find the closet one to pointSize + return styles[max(largerIndex - 1, 0)] + } else { //return the last style + return styles.last! + } + } +} From cd94bfde6784e0be9e66cd447d31282694ff191c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 10 Nov 2022 11:25:32 -0600 Subject: [PATCH 03/17] added AnylabelAttribute Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 4 +++ .../Label/Attributes/AnyLabelAttribute.swift | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 VDS/Components/Label/Attributes/AnyLabelAttribute.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 03aa3d87..089a1176 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -44,6 +44,7 @@ EA89200628B526D6006B9984 /* CheckboxGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89200528B526D6006B9984 /* CheckboxGroup.swift */; }; 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 */; }; 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 */; }; @@ -130,6 +131,7 @@ EA89200528B526D6006B9984 /* CheckboxGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxGroup.swift; sourceTree = ""; }; 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 = ""; }; 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 = ""; }; @@ -480,6 +482,7 @@ children = ( EAF7F0A3289B017C00B287F5 /* LabelAttributeModel.swift */, EAF7F0B2289B1ADC00B287F5 /* ActionLabelAttribute.swift */, + EA978EC4291D6AFE00ACC883 /* AnyLabelAttribute.swift */, EAF7F13228A2A16500B287F5 /* AttachmentLabelAttributeModel.swift */, EAF7F0B0289B177F00B287F5 /* ColorLabelAttribute.swift */, EAF7F0AA289B13FD00B287F5 /* FontLabelAttribute.swift */, @@ -631,6 +634,7 @@ EAF7F0AF289B144C00B287F5 /* UnderlineLabelAttribute.swift in Sources */, EAC925842911C63100091998 /* Colorable.swift in Sources */, EA3361C5289030FC0071C351 /* Accessable.swift in Sources */, + EA978EC5291D6AFE00ACC883 /* AnyLabelAttribute.swift in Sources */, EA33622C2891E73B0071C351 /* FontProtocol.swift in Sources */, EAF7F11728A1475A00B287F5 /* RadioButton.swift in Sources */, EAB1D2CD28ABE76100DAE764 /* Withable.swift in Sources */, diff --git a/VDS/Components/Label/Attributes/AnyLabelAttribute.swift b/VDS/Components/Label/Attributes/AnyLabelAttribute.swift new file mode 100644 index 00000000..b914c912 --- /dev/null +++ b/VDS/Components/Label/Attributes/AnyLabelAttribute.swift @@ -0,0 +1,36 @@ +// +// AnyAttribute.swift +// VDS +// +// Created by Matt Bruce on 11/10/22. +// + +import Foundation + +public struct AnyAttribute: LabelAttributeModel { + public var id = UUID() + public var location: Int + public var length: Int + public var key: NSAttributedString.Key + public var value: AnyHashable + + public init(location: Int, length: Int, key: NSAttributedString.Key, value: AnyHashable) { + self.location = location + self.length = length + self.key = key + self.value = value + } + + public func isEqual(_ equatable: AnyAttribute) -> Bool { + return id == equatable.id && range == equatable.range && key == equatable.key && value == equatable.value + } + + public static func == (lhs: AnyAttribute, rhs: AnyAttribute) -> Bool { + lhs.isEqual(rhs) + } + + public func setAttribute(on attributedString: NSMutableAttributedString) { + attributedString.removeAttribute(key, range: range) + attributedString.addAttribute(key, value: value, range: range) + } +} From eb48d8a807382c7d2dd6e92a8323648e7358173b Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 10 Nov 2022 11:26:14 -0600 Subject: [PATCH 04/17] include isForeground Signed-off-by: Matt Bruce --- .../Label/Attributes/ColorLabelAttribute.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/VDS/Components/Label/Attributes/ColorLabelAttribute.swift b/VDS/Components/Label/Attributes/ColorLabelAttribute.swift index 8d70296d..e266f15f 100644 --- a/VDS/Components/Label/Attributes/ColorLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/ColorLabelAttribute.swift @@ -19,17 +19,20 @@ public struct ColorLabelAttribute: LabelAttributeModel { public var location: Int public var length: Int public var color: UIColor + public var isForegroundColor: Bool //-------------------------------------------------- // MARK: - Initializer //-------------------------------------------------- - public init(location: Int, length: Int, color: UIColor = .black) { + public init(location: Int, length: Int, color: UIColor = .black, isForegroundColor: Bool = true) { self.location = location self.length = length self.color = color + self.isForegroundColor = isForegroundColor } public func setAttribute(on attributedString: NSMutableAttributedString) { - attributedString.removeAttribute(.foregroundColor, range: range) - attributedString.addAttribute(.foregroundColor, value: color, range: range) + let attributeKey = isForegroundColor ? NSAttributedString.Key.foregroundColor : NSAttributedString.Key.backgroundColor + attributedString.removeAttribute(attributeKey, range: range) + attributedString.addAttribute(attributeKey, value: color, range: range) } } From f9c8e328cfe06bb9f917fd7c6d5a2840abcf4ab4 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 10 Nov 2022 11:26:38 -0600 Subject: [PATCH 05/17] refactored to use AnyLabelAttribute Signed-off-by: Matt Bruce --- .../Label/Attributes/LabelAttributeModel.swift | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/VDS/Components/Label/Attributes/LabelAttributeModel.swift b/VDS/Components/Label/Attributes/LabelAttributeModel.swift index 8d5c02e1..321e2074 100644 --- a/VDS/Components/Label/Attributes/LabelAttributeModel.swift +++ b/VDS/Components/Label/Attributes/LabelAttributeModel.swift @@ -38,16 +38,7 @@ public extension NSAttributedString { } static func createAttributeModelFor(key: NSAttributedString.Key, range: NSRange, value: Any) -> (any LabelAttributeModel)? { - switch key { - case NSAttributedString.Key.font: - let value = value as! UIFont - let style = TypographicalStyle.style(for: value.fontName, size: value.pointSize) - return FontLabelAttribute(location: range.location, length: range.length, style: style) - case NSAttributedString.Key.foregroundColor: - return ColorLabelAttribute(location: range.location, length: range.length, color: value as! UIColor) - default: - return nil - } + guard let value = value as? AnyHashable else { return nil } + return AnyAttribute(location: range.location, length: range.length, key: key, value: value) } - } From 69ad6e9fb132f72ca7593467b1e1a272dcef2b93 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 10 Nov 2022 11:30:04 -0600 Subject: [PATCH 06/17] added constraints for veritcal Signed-off-by: Matt Bruce --- VDS/Components/Badge/Badge.swift | 4 +++- VDS/Components/Checkbox/Checkbox.swift | 12 +++++++++--- VDS/Components/RadioBox/RadioBox.swift | 12 +++++++++--- VDS/Components/RadioButton/RadioButton.swift | 12 +++++++++--- VDS/Components/Toggle/Toggle.swift | 4 +++- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index d0550acf..72a56ba4 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -18,7 +18,9 @@ public enum BadgeFillColor: String, Codable, CaseIterable { @objc(VDSBadge) public class Badge: View, Accessable { - private var label = Label() + private var label = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } //-------------------------------------------------- // MARK: - Public Properties diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index f7213864..64a4fdc3 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -78,11 +78,17 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er } }() - private var primaryLabel = Label() + private var primaryLabel = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } - private var secondaryLabel = Label() + private var secondaryLabel = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } - private var errorLabel = Label() + private var errorLabel = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } //-------------------------------------------------- // MARK: - Public Properties diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index b5a3c252..2bb90be9 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -70,11 +70,17 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ } }() - private var textLabel = Label() + private var textLabel = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } - private var subTextLabel = Label() + private var subTextLabel = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } - private var subTextRightLabel = Label() + private var subTextRightLabel = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } //-------------------------------------------------- // MARK: - Public Properties diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index e46a4e8c..afcd69e1 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -86,11 +86,17 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, } }() - private var primaryLabel = Label() + private var primaryLabel = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } - private var secondaryLabel = Label() + private var secondaryLabel = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } - private var errorLabel = Label() + private var errorLabel = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } //-------------------------------------------------- // MARK: - Public Properties diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 5a525a05..5400b859 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -70,7 +70,9 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable { } }() - private var label = Label() + private var label = Label().with { + $0.setContentCompressionResistancePriority(.required, for: .vertical) + } private var toggleView: UIView = { return UIView().with { From 64d9ca37774bdef9b33b1293ced129070e88eecd Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 10 Nov 2022 14:42:29 -0600 Subject: [PATCH 07/17] only return a font if a style is found Signed-off-by: Matt Bruce --- VDS/Typography/Typography.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/VDS/Typography/Typography.swift b/VDS/Typography/Typography.swift index 92ff5e9a..86629d91 100644 --- a/VDS/Typography/Typography.swift +++ b/VDS/Typography/Typography.swift @@ -262,17 +262,20 @@ extension TypographicalStyle { } extension TypographicalStyle { - public static func style(for fontName: String, size: CGFloat) -> TypographicalStyle { + public static func style(for fontName: String, size: CGFloat) -> TypographicalStyle? { //filter all styles by fontName let styles = allCases.filter{$0.fontFace.fontName == fontName }.sorted { lhs, rhs in lhs.pointSize < rhs.pointSize } - //if there are no styles then return defaultStyle - guard styles.count > 0 else { return defaultStyle } - styles.forEach{print("\($0.rawValue): \($0.pointSize)")} + + //if there are no styles then return nil + guard styles.count > 0 else { return nil } + //if there is an exact match on a style with this pointSize then return it if let style = styles.first(where: {$0.pointSize == size }) { return style + } else if let largerIndex = styles.firstIndex(where: { $0.pointSize > size}) { //find the closet one to pointSize return styles[max(largerIndex - 1, 0)] + } else { //return the last style return styles.last! } From e46017f3150d4d37b022dbf2d9761dd25b093cb3 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 10 Nov 2022 14:43:02 -0600 Subject: [PATCH 08/17] updated FontLabelAttribute for Kerning/line spacing/ line height Signed-off-by: Matt Bruce --- .../Label/Attributes/FontLabelAttribute.swift | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/VDS/Components/Label/Attributes/FontLabelAttribute.swift b/VDS/Components/Label/Attributes/FontLabelAttribute.swift index 6456b76c..a1fc2ff2 100644 --- a/VDS/Components/Label/Attributes/FontLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/FontLabelAttribute.swift @@ -24,21 +24,59 @@ public struct FontLabelAttribute: LabelAttributeModel { public var length: Int public var style: TypographicalStyle public var color: UIColor + public var textPosition: TextPosition + public var lineBreakMode: NSLineBreakMode //-------------------------------------------------- // MARK: - Initializer //-------------------------------------------------- - public init(location: Int, length: Int, style: TypographicalStyle, color: UIColor = .black) { + public init(location: Int, length: Int, style: TypographicalStyle, color: UIColor = .black, textPosition: TextPosition = .left, lineBreakMode: NSLineBreakMode = .byWordWrapping) { self.location = location self.length = length self.style = style self.color = color + self.textPosition = textPosition + self.lineBreakMode = lineBreakMode } public func setAttribute(on attributedString: NSMutableAttributedString) { - attributedString.removeAttribute(.font, range: range) attributedString.removeAttribute(.foregroundColor, range: range) attributedString.addAttribute(.font, value: style.font, range: range) attributedString.addAttribute(.foregroundColor, value: color, range: range) + setStyleAttributes(attributedString) } + + private func setStyleAttributes(_ attributedString: NSMutableAttributedString) { + //set letterSpacing + if style.letterSpacing > 0.0 { + attributedString.removeAttribute(.kern, range: range) + attributedString.addAttribute(.kern, value: style.letterSpacing, range: range) + } + + //set lineHeight + if style.lineHeight > 0.0 { + let lineHeight = style.lineHeight + let adjustment = lineHeight > style.font.lineHeight ? 2.0 : 1.0 + let baselineOffset = (lineHeight - style.font.lineHeight) / 2.0 / adjustment + let paragraph = NSMutableParagraphStyle().with { + $0.maximumLineHeight = lineHeight + $0.minimumLineHeight = lineHeight + $0.alignment = textPosition.textAlignment + $0.lineBreakMode = lineBreakMode + } + attributedString.removeAttribute(.baselineOffset, range: range) + attributedString.removeAttribute(.paragraphStyle, range: range) + attributedString.addAttribute(.baselineOffset, value: baselineOffset, range: range) + attributedString.addAttribute(.paragraphStyle, value: paragraph, range: range) + + } else if textPosition != .left { + let paragraph = NSMutableParagraphStyle().with { + $0.alignment = textPosition.textAlignment + $0.lineBreakMode = lineBreakMode + } + attributedString.removeAttribute(.paragraphStyle, range: range) + attributedString.addAttribute(.paragraphStyle, value: paragraph, range: range) + } + } + } From 0b73207bd6af80277d097362c3df374b096e5f1e Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 10 Nov 2022 14:43:40 -0600 Subject: [PATCH 09/17] update to look for a font with a found style to use our FontLabelAttribute Signed-off-by: Matt Bruce --- VDS/Components/Label/Attributes/LabelAttributeModel.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/VDS/Components/Label/Attributes/LabelAttributeModel.swift b/VDS/Components/Label/Attributes/LabelAttributeModel.swift index 321e2074..7196a346 100644 --- a/VDS/Components/Label/Attributes/LabelAttributeModel.swift +++ b/VDS/Components/Label/Attributes/LabelAttributeModel.swift @@ -39,6 +39,11 @@ public extension NSAttributedString { static func createAttributeModelFor(key: NSAttributedString.Key, range: NSRange, value: Any) -> (any LabelAttributeModel)? { guard let value = value as? AnyHashable else { return nil } - return AnyAttribute(location: range.location, length: range.length, key: key, value: value) + + guard let font = value as? UIFont, let style = TypographicalStyle.style(for: font.fontName, size: font.pointSize), key == .font + else { + return AnyAttribute(location: range.location, length: range.length, key: key, value: value) + } + return FontLabelAttribute(location: range.location, length: range.length, style: style) } } From c150f1552bbc3abd8baa4dc80c149e9d7b6848fb Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 10 Nov 2022 14:44:13 -0600 Subject: [PATCH 10/17] added escape hatch for using a user set attributedText directly to the label Signed-off-by: Matt Bruce --- VDS/Components/Label/Label.swift | 78 +++++++++++++++++--------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 449c9c80..2b195de8 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -27,6 +27,8 @@ open class LabelBase: UILabel, Handlerable, ViewProtocol, Resettable { // MARK: - Properties //-------------------------------------------------- private var initialSetupPerformed = false + + open var useAttributedText: Bool = false open var surface: Surface = .light { didSet { didChange() }} @@ -119,49 +121,53 @@ open class LabelBase: UILabel, Handlerable, ViewProtocol, Resettable { // MARK: - Overrides //-------------------------------------------------- open func updateView() { - textAlignment = textPosition.textAlignment - textColor = textColorConfiguration.getColor(self) - font = typograpicalStyle.font + if !useAttributedText { + textAlignment = textPosition.textAlignment + textColor = textColorConfiguration.getColor(self) + font = typograpicalStyle.font + + if let text = text, let font = font, let textColor = textColor { + //clear the arrays holding actions + accessibilityCustomActions = [] + + //create the primary string + let startingAttributes = [NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: textColor] + let mutableText = NSMutableAttributedString(string: text, attributes: startingAttributes) + + //set the local lineHeight/lineSpacing attributes + setStyleAttributes(attributedString: mutableText) + + applyAttributes(mutableText) + + //set the attributed text + attributedText = mutableText + } + } + } - if let text = text, let font = font, let textColor = textColor { - //clear the arrays holding actions - accessibilityCustomActions = [] - actions = [] - - //create the primary string - let startingAttributes = [NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: textColor] - let mutableText = NSMutableAttributedString(string: text, attributes: startingAttributes) - - //set the local lineHeight/lineSpacing attributes - setStyleAttributes(attributedString: mutableText) - - if let attributes = attributes { - //loop through the models attributes - for attribute in attributes { + // MARK: - Private Attributes + private func applyAttributes(_ mutableAttributedString: NSMutableAttributedString) { + actions = [] + + if let attributes = attributes { + //loop through the models attributes + for attribute in attributes { + + //add attribute on the string + attribute.setAttribute(on: mutableAttributedString) + + //see if the attribute is Actionable + if let actionable = attribute as? any ActionLabelAttributeModel{ + //create a accessibleAction + let customAccessibilityAction = customAccessibilityAction(range: actionable.range, accessibleText: actionable.accessibleText) - //add attribute on the string - attribute.setAttribute(on: mutableText) - - //see if the attribute is Actionable - if let actionable = attribute as? any ActionLabelAttributeModel{ - //create a accessibleAction - let customAccessibilityAction = customAccessibilityAction(range: actionable.range, accessibleText: actionable.accessibleText) - - //create a wrapper for the attributes range, block and - actions.append(LabelAction(range: actionable.range, action: actionable.action, accessibilityID: customAccessibilityAction?.hashValue ?? -1)) - } + //create a wrapper for the attributes range, block and + actions.append(LabelAction(range: actionable.range, action: actionable.action, accessibilityID: customAccessibilityAction?.hashValue ?? -1)) } } - - //only enabled if enabled and has actions - isUserInteractionEnabled = !disabled && !actions.isEmpty - - //set the attributed text - attributedText = mutableText } } - // MARK: - Private Attributes private func setStyleAttributes(attributedString: NSMutableAttributedString) { //get the range let entireRange = NSRange(location: 0, length: attributedString.length) From 7f0da4703664bf134ecc5a3350156e82ed9296ca Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 10 Nov 2022 14:44:42 -0600 Subject: [PATCH 11/17] added the logic for a attributedText Signed-off-by: Matt Bruce --- VDS/Components/Checkbox/Checkbox.swift | 33 ++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 64a4fdc3..a0426c09 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -51,7 +51,7 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er } private var shouldShowLabels: Bool { - guard labelText?.isEmpty == false || childText?.isEmpty == false else { return false } + guard labelText?.isEmpty == false || childText?.isEmpty == false || labelAttributedText?.string.isEmpty == false || childAttributedText?.string.isEmpty == false else { return false } return true } @@ -105,11 +105,27 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er open var labelText: String? { didSet { didChange() }} open var labelTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} - + + open var labelAttributedText: NSAttributedString? { + didSet { + primaryLabel.useAttributedText = !(labelAttributedText?.string.isEmpty ?? true) + primaryLabel.attributedText = labelAttributedText + didChange() + } + } + open var childText: String? { didSet { didChange() }} - + open var childTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} - + + open var childAttributedText: NSAttributedString? { + didSet { + secondaryLabel.useAttributedText = !(childAttributedText?.string.isEmpty ?? true) + secondaryLabel.attributedText = childAttributedText + didChange() + } + } + open var showError: Bool = false { didSet { didChange() }} open var errorText: String? { didSet { didChange() }} @@ -192,11 +208,14 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er if let labelText { primaryLabel.textPosition = .left primaryLabel.typograpicalStyle = .BoldBodyLarge - primaryLabel.text = labelText primaryLabel.surface = surface primaryLabel.disabled = disabled primaryLabel.attributes = labelTextAttributes + primaryLabel.text = labelText primaryLabel.isHidden = false + } else if labelAttributedText != nil { + primaryLabel.isHidden = false + } else { primaryLabel.isHidden = true } @@ -210,6 +229,10 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er secondaryLabel.disabled = disabled secondaryLabel.attributes = childTextAttributes secondaryLabel.isHidden = false + + } else if childAttributedText != nil { + secondaryLabel.isHidden = false + } else { secondaryLabel.isHidden = true } From 92c8c1073fd95254248530ed88b6fdbeb10fb5b3 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 10 Nov 2022 14:51:41 -0600 Subject: [PATCH 12/17] refactored radiobox/radiobutton to have attributedText override Signed-off-by: Matt Bruce --- VDS/Components/RadioBox/RadioBox.swift | 32 ++++++++++++++++++++ VDS/Components/RadioButton/RadioButton.swift | 26 +++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index 2bb90be9..2893c0a9 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -95,14 +95,38 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ open var textAttributes: [any LabelAttributeModel]? { didSet { didChange() }} + open var textAttributedText: NSAttributedString? { + didSet { + textLabel.useAttributedText = !(textAttributedText?.string.isEmpty ?? true) + textLabel.attributedText = textAttributedText + didChange() + } + } + open var subText: String? { didSet { didChange() }} open var subTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} + open var subTextAttributedText: NSAttributedString? { + didSet { + subTextLabel.useAttributedText = !(subTextAttributedText?.string.isEmpty ?? true) + subTextLabel.attributedText = subTextAttributedText + didChange() + } + } + open var subTextRight: String? { didSet { didChange() }} open var subTextRightAttributes: [any LabelAttributeModel]? { didSet { didChange() }} + open var subTextRightAttributedText: NSAttributedString? { + didSet { + subTextRightLabel.useAttributedText = !(subTextRightAttributedText?.string.isEmpty ?? true) + subTextRightLabel.attributedText = subTextRightAttributedText + didChange() + } + } + open var strikethrough: Bool = false { didSet { didChange() }} open var inputId: String? { didSet { didChange() }} @@ -191,6 +215,10 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ subTextLabel.disabled = disabled subTextLabel.attributes = subTextAttributes subTextLabel.isHidden = false + + } else if subTextAttributedText != nil { + subTextLabel.isHidden = false + } else { subTextLabel.isHidden = true } @@ -204,6 +232,10 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ subTextRightLabel.disabled = disabled subTextRightLabel.attributes = subTextRightAttributes subTextRightLabel.isHidden = false + + } else if subTextAttributedText != nil { + subTextRightLabel.isHidden = false + } else { subTextRightLabel.isHidden = true } diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index afcd69e1..c2938af9 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -59,7 +59,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, } private var shouldShowLabels: Bool { - guard labelText?.isEmpty == false || childText?.isEmpty == false else { return false } + guard labelText?.isEmpty == false || childText?.isEmpty == false || labelAttributedText?.string.isEmpty == false || childAttributedText?.string.isEmpty == false else { return false } return true } @@ -111,9 +111,25 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, open var labelTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} + open var labelAttributedText: NSAttributedString? { + didSet { + primaryLabel.useAttributedText = !(labelAttributedText?.string.isEmpty ?? true) + primaryLabel.attributedText = labelAttributedText + didChange() + } + } + open var childText: String? { didSet { didChange() }} open var childTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} + + open var childAttributedText: NSAttributedString? { + didSet { + secondaryLabel.useAttributedText = !(childAttributedText?.string.isEmpty ?? true) + secondaryLabel.attributedText = childAttributedText + didChange() + } + } open var showError: Bool = false { didSet { didChange() }} @@ -202,6 +218,10 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, primaryLabel.disabled = disabled primaryLabel.attributes = labelTextAttributes primaryLabel.isHidden = false + + } else if labelAttributedText != nil { + primaryLabel.isHidden = false + } else { primaryLabel.isHidden = true } @@ -215,6 +235,10 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, secondaryLabel.disabled = disabled secondaryLabel.attributes = childTextAttributes secondaryLabel.isHidden = false + + } else if childAttributedText != nil { + secondaryLabel.isHidden = false + } else { secondaryLabel.isHidden = true } From 19a7ba562799162e4b7068718c50d3118dffa9cf Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 10 Nov 2022 15:10:18 -0600 Subject: [PATCH 13/17] updated defaults into initializers update all initializers to look the same Signed-off-by: Matt Bruce --- VDS/Components/Badge/Badge.swift | 10 +- VDS/Components/Checkbox/Checkbox.swift | 54 ++++----- VDS/Components/RadioBox/RadioBox.swift | 68 +++++------ VDS/Components/RadioButton/RadioButton.swift | 115 +++++++++---------- VDS/Components/RadioSwatch/RadioSwatch.swift | 20 ++-- VDS/Components/Toggle/Toggle.swift | 34 +++--- 6 files changed, 135 insertions(+), 166 deletions(-) diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index 72a56ba4..eec78f9a 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -20,6 +20,10 @@ public class Badge: View, Accessable { private var label = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.adjustsFontSizeToFitWidth = false + $0.lineBreakMode = .byTruncatingTail + $0.textPosition = .left + $0.typograpicalStyle = .BoldBodySmall } //-------------------------------------------------- @@ -64,8 +68,6 @@ public class Badge: View, Accessable { addSubview(label) layer.cornerRadius = 2 - label.adjustsFontSizeToFitWidth = false - label.lineBreakMode = .byTruncatingTail label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 4).isActive = true label.topAnchor.constraint(equalTo: topAnchor, constant: 2).isActive = true @@ -75,6 +77,7 @@ public class Badge: View, Accessable { maxWidthConstraint = label.widthAnchor.constraint(lessThanOrEqualToConstant: 100) minWidthConstraint = label.widthAnchor.constraint(greaterThanOrEqualToConstant: 23) minWidthConstraint?.isActive = true + } public override func reset() { @@ -162,10 +165,9 @@ public class Badge: View, Accessable { //-------------------------------------------------- open override func updateView() { backgroundColor = backgroundColor() + label.textColorConfiguration = textColorConfiguration() label.numberOfLines = numberOfLines - label.textPosition = .left - label.typograpicalStyle = .BoldBodySmall label.text = text label.surface = surface label.disabled = disabled diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index a0426c09..5b42cb77 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -55,49 +55,47 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er return true } - private var mainStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.alignment = .top - $0.axis = .vertical - } - }() + private var mainStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.alignment = .top + $0.axis = .vertical + } - private var selectorStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.alignment = .top - $0.axis = .horizontal - } - }() + private var selectorStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.alignment = .top + $0.axis = .horizontal + } - private var selectorLabelStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.axis = .vertical - } - }() + private var selectorLabelStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.axis = .vertical + } private var primaryLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.typograpicalStyle = .BoldBodyLarge } private var secondaryLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.typograpicalStyle = .BodyLarge } private var errorLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.typograpicalStyle = .BodyMedium } //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- - public var selectorView: UIView = { - return UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - }() + public var selectorView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } //can't bind to @Proxy open override var isSelected: Bool { didSet { didChange() }} @@ -206,8 +204,6 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er //add the stackview to hold the 2 labels //top label if let labelText { - primaryLabel.textPosition = .left - primaryLabel.typograpicalStyle = .BoldBodyLarge primaryLabel.surface = surface primaryLabel.disabled = disabled primaryLabel.attributes = labelTextAttributes @@ -222,8 +218,6 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er //bottom label if let childText { - secondaryLabel.textPosition = .left - secondaryLabel.typograpicalStyle = .BodyLarge secondaryLabel.text = childText secondaryLabel.surface = surface secondaryLabel.disabled = disabled @@ -248,8 +242,6 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er //either add/remove the error from the main stack if let errorText, shouldShowError { - errorLabel.textPosition = .left - errorLabel.typograpicalStyle = .BodyMedium errorLabel.text = errorText errorLabel.surface = surface errorLabel.disabled = disabled diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index 2893c0a9..029c3203 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -46,51 +46,52 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- - private var mainStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.alignment = .top - $0.axis = .vertical - $0.spacing = 0 - } - }() + private var mainStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.alignment = .top + $0.axis = .vertical + $0.spacing = 0 + } + + private var selectorStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.alignment = .top + $0.axis = .horizontal + $0.spacing = 12 + } - private var selectorStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.alignment = .top - $0.axis = .horizontal - } - }() - - private var selectorLeftLabelStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.axis = .vertical - } - }() + private var selectorLeftLabelStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.axis = .vertical + $0.spacing = 4 + $0.isHidden = false + } private var textLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.typograpicalStyle = .BoldBodyLarge } private var subTextLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.typograpicalStyle = .BodyLarge } private var subTextRightLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .right + $0.typograpicalStyle = .BodyLarge } //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- - public var selectorView: UIView = { - return UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - }() - + public var selectorView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } + open var text: String = "Default Text" { didSet { didChange() }} open var textAttributes: [any LabelAttributeModel]? { didSet { didChange() }} @@ -177,10 +178,6 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ selectorLeftLabelStackView.addArrangedSubview(textLabel) selectorLeftLabelStackView.addArrangedSubview(subTextLabel) - selectorStackView.spacing = 12 - selectorLeftLabelStackView.spacing = 4 - selectorLeftLabelStackView.isHidden = false - updateSelector() selectorView.topAnchor.constraint(equalTo: topAnchor).isActive = true @@ -192,15 +189,12 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ mainStackView.leadingAnchor.constraint(equalTo: selectorView.leadingAnchor, constant: 16).isActive = true mainStackView.trailingAnchor.constraint(equalTo: selectorView.trailingAnchor, constant: -16).isActive = true mainStackView.bottomAnchor.constraint(equalTo: selectorView.bottomAnchor, constant: -16).isActive = true - } func updateLabels() { //add the stackview to hold the 2 labels //text label - textLabel.textPosition = .left - textLabel.typograpicalStyle = .BoldBodyLarge textLabel.text = text textLabel.surface = surface textLabel.disabled = disabled @@ -208,8 +202,6 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ //subText label if let subText { - subTextLabel.textPosition = .left - subTextLabel.typograpicalStyle = .BodyLarge subTextLabel.text = subText subTextLabel.surface = surface subTextLabel.disabled = disabled @@ -225,8 +217,6 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ //subTextRight label if let subTextRight { - subTextRightLabel.textPosition = .right - subTextRightLabel.typograpicalStyle = .BodyLarge subTextRightLabel.text = subTextRight subTextRightLabel.surface = surface subTextRightLabel.disabled = disabled diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index c2938af9..9a26565b 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -49,7 +49,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, public required init?(coder: NSCoder) { super.init(coder: coder) } - + //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- @@ -62,29 +62,23 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, guard labelText?.isEmpty == false || childText?.isEmpty == false || labelAttributedText?.string.isEmpty == false || childAttributedText?.string.isEmpty == false else { return false } return true } - - private var mainStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.alignment = .top - $0.axis = .vertical - } - }() - private var selectorStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.alignment = .top - $0.axis = .horizontal - } - }() + private var mainStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.alignment = .top + $0.axis = .vertical + } - private var selectorLabelStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.axis = .vertical - } - }() + private var selectorStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.alignment = .top + $0.axis = .horizontal + } + + private var selectorLabelStackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.axis = .vertical + } private var primaryLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) @@ -97,20 +91,18 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, private var errorLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) } - + //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- - public var selectorView: UIView = { - return UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - }() - + public var selectorView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } + open var labelText: String? { didSet { didChange() }} - + open var labelTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} - + open var labelAttributedText: NSAttributedString? { didSet { primaryLabel.useAttributedText = !(labelAttributedText?.string.isEmpty ?? true) @@ -118,9 +110,9 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, didChange() } } - + open var childText: String? { didSet { didChange() }} - + open var childTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} open var childAttributedText: NSAttributedString? { @@ -130,21 +122,21 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, didChange() } } - + open var showError: Bool = false { didSet { didChange() }} open var errorText: String? { didSet { didChange() }} - + open var inputId: String? { didSet { didChange() }} - + open var value: AnyHashable? { didSet { didChange() }} open var dataAnalyticsTrack: String? { didSet { didChange() }} - + open var dataClickStream: String? { didSet { didChange() }} - + open var dataTrack: String? { didSet { didChange() }} - + open var accessibilityHintEnabled: String? { didSet { didChange() }} open var accessibilityHintDisabled: String? { didSet { didChange() }} @@ -156,7 +148,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, open var accessibilityLabelEnabled: String? { didSet { didChange() }} open var accessibilityLabelDisabled: String? { didSet { didChange() }} - + //-------------------------------------------------- // MARK: - Constraints //-------------------------------------------------- @@ -168,7 +160,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - + open override func setup() { super.setup() @@ -187,32 +179,39 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, selectorStackView.addArrangedSubview(selectorLabelStackView) selectorLabelStackView.addArrangedSubview(primaryLabel) selectorLabelStackView.addArrangedSubview(secondaryLabel) - + let selectorSize = getSelectorSize() selectorHeightConstraint = selectorView.heightAnchor.constraint(equalToConstant: selectorSize.height) selectorHeightConstraint?.isActive = true selectorWidthConstraint = selectorView.widthAnchor.constraint(equalToConstant: selectorSize.width) selectorWidthConstraint?.isActive = true - + updateSelector() mainStackView.topAnchor.constraint(equalTo: topAnchor).isActive = true mainStackView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true mainStackView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true mainStackView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true - + + //defaults + primaryLabel.textPosition = .left + primaryLabel.typograpicalStyle = .BoldBodyLarge + + secondaryLabel.textPosition = .left + secondaryLabel.typograpicalStyle = .BodyLarge + + errorLabel.textPosition = .left + errorLabel.typograpicalStyle = .BodyMedium } func updateLabels() { - + //deal with labels if shouldShowLabels { //add the stackview to hold the 2 labels //top label if let labelText { - primaryLabel.textPosition = .left - primaryLabel.typograpicalStyle = .BoldBodyLarge primaryLabel.text = labelText primaryLabel.surface = surface primaryLabel.disabled = disabled @@ -221,15 +220,13 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, } else if labelAttributedText != nil { primaryLabel.isHidden = false - + } else { primaryLabel.isHidden = true } //bottom label if let childText { - secondaryLabel.textPosition = .left - secondaryLabel.typograpicalStyle = .BodyLarge secondaryLabel.text = childText secondaryLabel.surface = surface secondaryLabel.disabled = disabled @@ -238,7 +235,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, } else if childAttributedText != nil { secondaryLabel.isHidden = false - + } else { secondaryLabel.isHidden = true } @@ -254,8 +251,6 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, //either add/remove the error from the main stack if let errorText, shouldShowError { - errorLabel.textPosition = .left - errorLabel.typograpicalStyle = .BodyMedium errorLabel.text = errorText errorLabel.surface = surface errorLabel.disabled = disabled @@ -273,11 +268,11 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, updateSelector() setAccessibilityLabel() } - + /// This will checkbox the state of the Selector and execute the actionBlock if provided. open func toggle() { guard !isSelected else { return } - + //removed error if showError && isSelected == false { showError.toggle() @@ -285,10 +280,10 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, isSelected.toggle() sendActions(for: .valueChanged) } - + //-------------------------------------------------- // MARK: - State - //-------------------------------------------------- + //-------------------------------------------------- open override func updateView() { updateLabels() updateSelector() @@ -353,7 +348,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, let bounds = selectorView.bounds let length = max(bounds.size.height, bounds.size.width) guard length > 0.0, shapeLayer == nil else { return } - + //get the colors let backgroundColor = radioButtonBackgroundColorConfiguration.getColor(self) let borderColor = radioButtonBorderColorConfiguration.getColor(self) @@ -367,9 +362,9 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, if shapeLayer == nil { let selectedBounds = radioButtonSelectedSize let bezierPath = UIBezierPath(ovalIn: CGRect(x: (bounds.width - selectedBounds.width) / 2, - y: (bounds.height - selectedBounds.height) / 2, + y: (bounds.height - selectedBounds.height) / 2, width: radioButtonSelectedSize.width, - height: radioButtonSelectedSize.height)) + height: radioButtonSelectedSize.height)) let shapeLayer = CAShapeLayer() self.shapeLayer = shapeLayer shapeLayer.frame = bounds diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift index f548f18d..c3df2853 100644 --- a/VDS/Components/RadioSwatch/RadioSwatch.swift +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -43,18 +43,14 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- - public var selectorView: UIView = { - return UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - }() - - public var fillView: UIImageView = { - return UIImageView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.contentMode = .scaleAspectFit - } - }() + public var selectorView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } + + public var fillView = UIImageView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.contentMode = .scaleAspectFit + } open var fillImage: UIImage? { didSet { didChange() }} diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 5400b859..50594fad 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -58,34 +58,28 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable { public required init?(coder: NSCoder) { super.init(coder: coder) } - + //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- - private var stackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.axis = .horizontal - $0.distribution = .fill - } - }() + private var stackView = UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.axis = .horizontal + $0.distribution = .fill + } private var label = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) } - private var toggleView: UIView = { - return UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - }() - - private var knobView: UIView = { - return UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.backgroundColor = .white - } - }() + private var toggleView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } + + private var knobView = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.backgroundColor = .white + } //-------------------------------------------------- // MARK: - Configuration Properties From ed07680965a3f566dc2a9502537ae01fc2a7d637 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 10 Nov 2022 15:17:39 -0600 Subject: [PATCH 14/17] refactored private var names Signed-off-by: Matt Bruce --- VDS/Components/Checkbox/Checkbox.swift | 44 ++++++++--------- VDS/Components/RadioButton/RadioButton.swift | 52 ++++++++++---------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 5b42cb77..07d5c523 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -72,13 +72,13 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er $0.axis = .vertical } - private var primaryLabel = Label().with { + private var label = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.textPosition = .left $0.typograpicalStyle = .BoldBodyLarge } - private var secondaryLabel = Label().with { + private var childLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.textPosition = .left $0.typograpicalStyle = .BodyLarge @@ -106,8 +106,8 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er open var labelAttributedText: NSAttributedString? { didSet { - primaryLabel.useAttributedText = !(labelAttributedText?.string.isEmpty ?? true) - primaryLabel.attributedText = labelAttributedText + label.useAttributedText = !(labelAttributedText?.string.isEmpty ?? true) + label.attributedText = labelAttributedText didChange() } } @@ -118,8 +118,8 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er open var childAttributedText: NSAttributedString? { didSet { - secondaryLabel.useAttributedText = !(childAttributedText?.string.isEmpty ?? true) - secondaryLabel.attributedText = childAttributedText + childLabel.useAttributedText = !(childAttributedText?.string.isEmpty ?? true) + childLabel.attributedText = childAttributedText didChange() } } @@ -178,8 +178,8 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er mainStackView.addArrangedSubview(errorLabel) selectorStackView.addArrangedSubview(selectorView) selectorStackView.addArrangedSubview(selectorLabelStackView) - selectorLabelStackView.addArrangedSubview(primaryLabel) - selectorLabelStackView.addArrangedSubview(secondaryLabel) + selectorLabelStackView.addArrangedSubview(label) + selectorLabelStackView.addArrangedSubview(childLabel) let selectorSize = getSelectorSize() selectorHeightConstraint = selectorView.heightAnchor.constraint(equalToConstant: selectorSize.height) @@ -204,31 +204,31 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er //add the stackview to hold the 2 labels //top label if let labelText { - primaryLabel.surface = surface - primaryLabel.disabled = disabled - primaryLabel.attributes = labelTextAttributes - primaryLabel.text = labelText - primaryLabel.isHidden = false + label.surface = surface + label.disabled = disabled + label.attributes = labelTextAttributes + label.text = labelText + label.isHidden = false } else if labelAttributedText != nil { - primaryLabel.isHidden = false + label.isHidden = false } else { - primaryLabel.isHidden = true + label.isHidden = true } //bottom label if let childText { - secondaryLabel.text = childText - secondaryLabel.surface = surface - secondaryLabel.disabled = disabled - secondaryLabel.attributes = childTextAttributes - secondaryLabel.isHidden = false + childLabel.text = childText + childLabel.surface = surface + childLabel.disabled = disabled + childLabel.attributes = childTextAttributes + childLabel.isHidden = false } else if childAttributedText != nil { - secondaryLabel.isHidden = false + childLabel.isHidden = false } else { - secondaryLabel.isHidden = true + childLabel.isHidden = true } selectorStackView.spacing = 12 selectorLabelStackView.spacing = 4 diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index 9a26565b..3d084335 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -80,11 +80,11 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, $0.axis = .vertical } - private var primaryLabel = Label().with { + private var label = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) } - private var secondaryLabel = Label().with { + private var childLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) } @@ -105,8 +105,8 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, open var labelAttributedText: NSAttributedString? { didSet { - primaryLabel.useAttributedText = !(labelAttributedText?.string.isEmpty ?? true) - primaryLabel.attributedText = labelAttributedText + label.useAttributedText = !(labelAttributedText?.string.isEmpty ?? true) + label.attributedText = labelAttributedText didChange() } } @@ -117,8 +117,8 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, open var childAttributedText: NSAttributedString? { didSet { - secondaryLabel.useAttributedText = !(childAttributedText?.string.isEmpty ?? true) - secondaryLabel.attributedText = childAttributedText + childLabel.useAttributedText = !(childAttributedText?.string.isEmpty ?? true) + childLabel.attributedText = childAttributedText didChange() } } @@ -177,8 +177,8 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, mainStackView.addArrangedSubview(errorLabel) selectorStackView.addArrangedSubview(selectorView) selectorStackView.addArrangedSubview(selectorLabelStackView) - selectorLabelStackView.addArrangedSubview(primaryLabel) - selectorLabelStackView.addArrangedSubview(secondaryLabel) + selectorLabelStackView.addArrangedSubview(label) + selectorLabelStackView.addArrangedSubview(childLabel) let selectorSize = getSelectorSize() selectorHeightConstraint = selectorView.heightAnchor.constraint(equalToConstant: selectorSize.height) @@ -195,11 +195,11 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, mainStackView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true //defaults - primaryLabel.textPosition = .left - primaryLabel.typograpicalStyle = .BoldBodyLarge + label.textPosition = .left + label.typograpicalStyle = .BoldBodyLarge - secondaryLabel.textPosition = .left - secondaryLabel.typograpicalStyle = .BodyLarge + childLabel.textPosition = .left + childLabel.typograpicalStyle = .BodyLarge errorLabel.textPosition = .left errorLabel.typograpicalStyle = .BodyMedium @@ -212,32 +212,32 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, //add the stackview to hold the 2 labels //top label if let labelText { - primaryLabel.text = labelText - primaryLabel.surface = surface - primaryLabel.disabled = disabled - primaryLabel.attributes = labelTextAttributes - primaryLabel.isHidden = false + label.text = labelText + label.surface = surface + label.disabled = disabled + label.attributes = labelTextAttributes + label.isHidden = false } else if labelAttributedText != nil { - primaryLabel.isHidden = false + label.isHidden = false } else { - primaryLabel.isHidden = true + label.isHidden = true } //bottom label if let childText { - secondaryLabel.text = childText - secondaryLabel.surface = surface - secondaryLabel.disabled = disabled - secondaryLabel.attributes = childTextAttributes - secondaryLabel.isHidden = false + childLabel.text = childText + childLabel.surface = surface + childLabel.disabled = disabled + childLabel.attributes = childTextAttributes + childLabel.isHidden = false } else if childAttributedText != nil { - secondaryLabel.isHidden = false + childLabel.isHidden = false } else { - secondaryLabel.isHidden = true + childLabel.isHidden = true } selectorStackView.spacing = 12 selectorLabelStackView.spacing = 4 From 9b75fd4edc252f8f64336615289c9052e0dacf84 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 10 Nov 2022 18:25:07 -0600 Subject: [PATCH 15/17] ensure resets are working Signed-off-by: Matt Bruce --- VDS/Classes/SelectorGroupHandlerBase.swift | 5 +++++ VDS/Components/Badge/Badge.swift | 1 + VDS/Components/Buttons/TextLink/TextLink.swift | 1 + VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift | 1 + VDS/Components/Checkbox/Checkbox.swift | 3 +++ VDS/Components/RadioBox/RadioBox.swift | 3 +++ VDS/Components/RadioButton/RadioButton.swift | 3 +++ VDS/Components/Toggle/Toggle.swift | 1 + 8 files changed, 18 insertions(+) diff --git a/VDS/Classes/SelectorGroupHandlerBase.swift b/VDS/Classes/SelectorGroupHandlerBase.swift index 27c56353..acae21c5 100644 --- a/VDS/Classes/SelectorGroupHandlerBase.swift +++ b/VDS/Classes/SelectorGroupHandlerBase.swift @@ -43,6 +43,11 @@ public class SelectorGroupHandlerBase: Control { self?.sendActions(for: .valueChanged) } } + + public override func reset() { + super.reset() + selectorViews.forEach{ $0.reset() } + } } public class SelectorGroupSelectedHandlerBase: SelectorGroupHandlerBase{ diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index eec78f9a..f7da7374 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -82,6 +82,7 @@ public class Badge: View, Accessable { public override func reset() { super.reset() + label.reset() setAccessibilityLabel() } diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index b4eedd81..2a8b9335 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -84,6 +84,7 @@ open class TextLink: Control { open override func reset() { super.reset() size = .large + label.reset() accessibilityCustomActions = [] accessibilityTraits = .staticText } diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index 224f3466..6fa22280 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -96,6 +96,7 @@ open class TextLinkCaret: Control { open override func reset() { super.reset() + label.reset() accessibilityCustomActions = [] accessibilityTraits = .staticText } diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 07d5c523..f2565c49 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -255,6 +255,9 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er open override func reset() { super.reset() + label.reset() + childLabel.reset() + errorLabel.reset() updateSelector() setAccessibilityLabel() } diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index bc474cbe..6bc9b02a 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -233,6 +233,9 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ public override func reset() { super.reset() + textLabel.reset() + subTextLabel.reset() + subTextRightLabel.reset() updateSelector() setAccessibilityLabel() } diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index 3d084335..dae5f322 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -265,6 +265,9 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, public override func reset() { super.reset() + label.reset() + childLabel.reset() + errorLabel.reset() updateSelector() setAccessibilityLabel() } diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 50594fad..b7782e1e 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -294,6 +294,7 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable { public override func reset() { super.reset() + label.reset() toggleView.backgroundColor = toggleColorConfiguration.getColor(self) knobView.backgroundColor = knobColorConfiguration.getColor(self) setAccessibilityLabel() From 00f1418e693c2adf79e742e3b2e45abf732898d9 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 15 Nov 2022 10:10:04 -0600 Subject: [PATCH 16/17] updated controls for reset() Signed-off-by: Matt Bruce --- VDS/Classes/Control.swift | 4 +- VDS/Components/Badge/Badge.swift | 18 ++++++-- .../Buttons/TextLink/TextLink.swift | 4 +- .../Buttons/TextLinkCaret/TextLinkCaret.swift | 5 +++ VDS/Components/Checkbox/Checkbox.swift | 26 +++++++++++ VDS/Components/RadioBox/RadioBox.swift | 29 ++++++++++++ VDS/Components/RadioButton/RadioButton.swift | 42 ++++++++++++++---- VDS/Components/RadioSwatch/RadioSwatch.swift | 18 ++++++++ .../TextFields/EntryField/EntryField.swift | 44 ++++++++++++++++--- .../TextEntryField/TextEntryField.swift | 16 ++++++- VDS/Components/Toggle/Toggle.swift | 13 ++++++ 11 files changed, 196 insertions(+), 23 deletions(-) diff --git a/VDS/Classes/Control.swift b/VDS/Classes/Control.swift index 0f7a2631..12e8fba4 100644 --- a/VDS/Classes/Control.swift +++ b/VDS/Classes/Control.swift @@ -86,7 +86,7 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable { open func reset() { backgroundColor = .clear surface = .light - disabled = false + disabled = false } // MARK: - ViewProtocol @@ -94,5 +94,5 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable { open func setup() { translatesAutoresizingMaskIntoConstraints = false insetsLayoutMarginsFromSafeArea = false - } + } } diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index f7da7374..94c4b8e0 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -21,9 +21,6 @@ public class Badge: View, Accessable { private var label = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.adjustsFontSizeToFitWidth = false - $0.lineBreakMode = .byTruncatingTail - $0.textPosition = .left - $0.typograpicalStyle = .BoldBodySmall } //-------------------------------------------------- @@ -83,6 +80,21 @@ public class Badge: View, Accessable { public override func reset() { super.reset() label.reset() + label.lineBreakMode = .byTruncatingTail + label.textPosition = .left + label.typograpicalStyle = .BoldBodySmall + + fillColor = .red + text = "" + maxWidth = nil + numberOfLines = 1 + accessibilityHintEnabled = nil + accessibilityHintDisabled = nil + accessibilityValueEnabled = nil + accessibilityValueDisabled = nil + accessibilityLabelEnabled = nil + accessibilityLabelDisabled = nil + setAccessibilityLabel() } diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index 2a8b9335..d1287c2e 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -83,8 +83,10 @@ open class TextLink: Control { open override func reset() { super.reset() - size = .large label.reset() + size = .large + text = nil + accessibilityCustomActions = [] accessibilityTraits = .staticText } diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index 6fa22280..83958072 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -97,6 +97,11 @@ open class TextLinkCaret: Control { open override func reset() { super.reset() label.reset() + + label.typograpicalStyle = TypographicalStyle.BoldBodyLarge + text = nil + iconPosition = .right + accessibilityCustomActions = [] accessibilityTraits = .staticText } diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index f2565c49..3a515eb4 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -258,6 +258,32 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er label.reset() childLabel.reset() errorLabel.reset() + + label.typograpicalStyle = .BoldBodyLarge + childLabel.typograpicalStyle = .BodyLarge + errorLabel.typograpicalStyle = .BodyMedium + + labelText = nil + labelTextAttributes = nil + labelAttributedText = nil + childText = nil + childTextAttributes = nil + childAttributedText = nil + showError = false + errorText = nil + inputId = nil + value = nil + dataAnalyticsTrack = nil + dataClickStream = nil + dataTrack = nil + accessibilityHintEnabled = nil + accessibilityHintDisabled = nil + accessibilityValueEnabled = nil + accessibilityValueDisabled = nil + accessibilityLabelEnabled = nil + accessibilityLabelDisabled = nil + isSelected = false + updateSelector() setAccessibilityLabel() } diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index 6bc9b02a..d9245790 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -236,6 +236,35 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ textLabel.reset() subTextLabel.reset() subTextRightLabel.reset() + + textLabel.typograpicalStyle = .BoldBodyLarge + subTextLabel.typograpicalStyle = .BodyLarge + subTextRightLabel.typograpicalStyle = .BodyLarge + + text = "Default Text" + textAttributes = nil + textAttributedText = nil + subText = nil + subTextAttributes = nil + subTextAttributedText = nil + subTextRight = nil + subTextRightAttributes = nil + subTextRightAttributedText = nil + strikethrough = false + inputId = nil + value = nil + dataAnalyticsTrack = nil + dataClickStream = nil + dataTrack = nil + accessibilityHintEnabled = nil + accessibilityHintDisabled = nil + accessibilityValueEnabled = nil + accessibilityValueDisabled = nil + accessibilityLabelEnabled = nil + accessibilityLabelDisabled = nil + + isSelected = false + updateSelector() setAccessibilityLabel() } diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index dae5f322..f52f2a09 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -82,14 +82,20 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, private var label = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.typograpicalStyle = .BoldBodyLarge } private var childLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.typograpicalStyle = .BodyLarge } private var errorLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.typograpicalStyle = .BodyMedium } //-------------------------------------------------- @@ -194,15 +200,6 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, mainStackView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true mainStackView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true - //defaults - label.textPosition = .left - label.typograpicalStyle = .BoldBodyLarge - - childLabel.textPosition = .left - childLabel.typograpicalStyle = .BodyLarge - - errorLabel.textPosition = .left - errorLabel.typograpicalStyle = .BodyMedium } func updateLabels() { @@ -268,6 +265,33 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, label.reset() childLabel.reset() errorLabel.reset() + + label.typograpicalStyle = .BoldBodyLarge + childLabel.typograpicalStyle = .BodyLarge + errorLabel.typograpicalStyle = .BodyMedium + + labelText = nil + labelTextAttributes = nil + labelAttributedText = nil + childText = nil + childTextAttributes = nil + childAttributedText = nil + showError = false + errorText = nil + inputId = nil + value = nil + dataAnalyticsTrack = nil + dataClickStream = nil + dataTrack = nil + accessibilityHintEnabled = nil + accessibilityHintDisabled = nil + accessibilityValueEnabled = nil + accessibilityValueDisabled = nil + accessibilityLabelEnabled = nil + accessibilityLabelDisabled = nil + + isSelected = false + updateSelector() setAccessibilityLabel() } diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift index 758e5911..520262d1 100644 --- a/VDS/Components/RadioSwatch/RadioSwatch.swift +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -122,6 +122,24 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable public override func reset() { super.reset() + + fillImage = nil + text = "" + primaryColor = nil + secondaryColor = nil + strikethrough = false + inputId = nil + value = nil + dataAnalyticsTrack = nil + dataClickStream = nil + dataTrack = nil + accessibilityHintEnabled = nil + accessibilityHintDisabled = nil + accessibilityValueEnabled = nil + accessibilityValueDisabled = nil + accessibilityLabelEnabled = nil + accessibilityLabelDisabled = nil + setNeedsDisplay() setAccessibilityLabel() } diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index 65c1533f..3d8cfce0 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -46,14 +46,20 @@ open class EntryField: Control, Accessable { internal var titleLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.attributes = [] + $0.textPosition = .left + $0.typograpicalStyle = .BodySmall } internal var errorLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.typograpicalStyle = .BodySmall } internal var helperLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.typograpicalStyle = .BodySmall } internal var containerView: UIView = { @@ -256,6 +262,38 @@ open class EntryField: Control, Accessable { public override func reset() { super.reset() + titleLabel.reset() + errorLabel.reset() + helperLabel.reset() + + titleLabel.textPosition = .left + titleLabel.typograpicalStyle = .BodySmall + errorLabel.textPosition = .left + errorLabel.typograpicalStyle = .BodySmall + helperLabel.textPosition = .left + helperLabel.typograpicalStyle = .BodySmall + + labelText = nil + helperText = nil + showError = false + errorText = nil + tooltipTitle = nil + tooltipContent = nil + transparentBackground = false + width = nil + maxLength = nil + inputId = nil + value = nil + defaultValue = nil + required = false + readOnly = false + accessibilityHintEnabled = nil + accessibilityHintDisabled = nil + accessibilityValueEnabled = nil + accessibilityValueDisabled = nil + accessibilityLabelEnabled = nil + accessibilityLabelDisabled = nil + setAccessibilityLabel() } @@ -313,8 +351,6 @@ open class EntryField: Control, Accessable { } //set the titleLabel - titleLabel.textPosition = .left - titleLabel.typograpicalStyle = .BodySmall titleLabel.text = updatedLabelText titleLabel.attributes = attributes titleLabel.surface = surface @@ -324,8 +360,6 @@ open class EntryField: Control, Accessable { open func updateErrorLabel(){ if showError, let errorText { - errorLabel.textPosition = .left - errorLabel.typograpicalStyle = .BodySmall errorLabel.text = errorText errorLabel.surface = surface errorLabel.disabled = disabled @@ -338,8 +372,6 @@ open class EntryField: Control, Accessable { open func updateHelperLabel(){ //set the helper label position if let helperText { - helperLabel.textPosition = .left - helperLabel.typograpicalStyle = .BodySmall helperLabel.text = helperText helperLabel.surface = surface helperLabel.disabled = disabled diff --git a/VDS/Components/TextFields/TextEntryField/TextEntryField.swift b/VDS/Components/TextFields/TextEntryField/TextEntryField.swift index f64e27e9..c0eee646 100644 --- a/VDS/Components/TextFields/TextEntryField/TextEntryField.swift +++ b/VDS/Components/TextFields/TextEntryField/TextEntryField.swift @@ -60,6 +60,8 @@ open class TextEntryFieldBase: EntryField { private var successLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.textPosition = .left + $0.typograpicalStyle = .BodySmall } internal var minWidthConstraint: NSLayoutConstraint? @@ -80,6 +82,18 @@ open class TextEntryFieldBase: EntryField { } + public override func reset() { + super.reset() + successLabel.reset() + successLabel.textPosition = .left + successLabel.typograpicalStyle = .BodySmall + + type = .text + showSuccess = false + successText = nil + helperTextPlacement = .bottom + } + open override func getContainer() -> UIView { containerStackView.addArrangedSubview(containerView) return containerStackView @@ -126,8 +140,6 @@ open class TextEntryFieldBase: EntryField { successLabel.isHidden = true } else if showSuccess, let successText { - successLabel.textPosition = .left - successLabel.typograpicalStyle = .BodySmall successLabel.text = successText successLabel.surface = surface successLabel.disabled = disabled diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index b7782e1e..0694d0fb 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -295,6 +295,19 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable { public override func reset() { super.reset() label.reset() + isSelected = false + isOn = false + + isAnimated = true + showText = false + onText = "On" + offText = "Off" + textSize = .small + textWeight = .regular + textPosition = .left + inputId = nil + value = nil + toggleView.backgroundColor = toggleColorConfiguration.getColor(self) knobView.backgroundColor = knobColorConfiguration.getColor(self) setAccessibilityLabel() From aba977dd776f6aa4c63d1d855299f644cd5857c8 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 15 Nov 2022 10:12:42 -0600 Subject: [PATCH 17/17] fixed bug of accidental removal Signed-off-by: Matt Bruce --- VDS/Components/Badge/Badge.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index 94c4b8e0..288ebf9b 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -21,6 +21,9 @@ public class Badge: View, Accessable { private var label = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.adjustsFontSizeToFitWidth = false + $0.lineBreakMode = .byTruncatingTail + $0.textPosition = .left + $0.typograpicalStyle = .BoldBodySmall } //--------------------------------------------------