From 2bbe71e1060329e0bd57348607ae123a09a5f0ae Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 8 May 2023 10:45:42 -0500 Subject: [PATCH 1/5] refactored action Signed-off-by: Matt Bruce --- .../Label/Attributes/ActionLabelAttribute.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/VDS/Components/Label/Attributes/ActionLabelAttribute.swift b/VDS/Components/Label/Attributes/ActionLabelAttribute.swift index 1b9ce53a..4a29f613 100644 --- a/VDS/Components/Label/Attributes/ActionLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/ActionLabelAttribute.swift @@ -14,6 +14,12 @@ public protocol ActionLabelAttributeModel: LabelAttributeModel { var action: PassthroughSubject { get set } } +extension ActionLabelAttributeModel { + public func addHandler(on attributedString: NSMutableAttributedString){ + attributedString.addAttribute(NSAttributedString.Key.action, value: "handler", range: range) + } +} + public struct ActionLabelAttribute: ActionLabelAttributeModel { public static func == (lhs: ActionLabelAttribute, rhs: ActionLabelAttribute) -> Bool { @@ -54,7 +60,7 @@ public struct ActionLabelAttribute: ActionLabelAttributeModel { if(shouldUnderline){ UnderlineLabelAttribute(location: location, length: length).setAttribute(on: attributedString) } - attributedString.addAttribute(NSAttributedString.Key.action, value: "handler", range: range) + addHandler(on: attributedString) } } From 8ed250658080e70b376cd37863f95efb34498f42 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 8 May 2023 10:45:52 -0500 Subject: [PATCH 2/5] udpated tooltip attribute Signed-off-by: Matt Bruce --- .../Attributes/TooltipLabelAttribute.swift | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift b/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift index aed3556a..5c395970 100644 --- a/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift @@ -14,19 +14,20 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable public var id = UUID() public var action = PassthroughSubject() private var subscriber: AnyCancellable? + private var size: Tooltip.Size = .small public var location: Int = 0 public var length: Int = 3 public var surface: Surface = .light public var accessibleText: String? = "Tool Tip" public var closeButtonText: String = "Close" - public var size: Tooltip.Size = .medium public var title: String public var content: String public func setAttribute(on attributedString: NSMutableAttributedString) { - //update the location - location = attributedString.string.count - + //update the location + location = attributedString.string.count - 1 + + //set the default color off surface for text var imageTintColor: UIColor = surface == .light ? VDSColor.elementsPrimaryOnlight : VDSColor.elementsPrimaryOndark //see if you can get the current textColor @@ -34,45 +35,50 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable if let textColor = attributedString.attribute(.foregroundColor, at: 0, effectiveRange: &originalRange) as? UIColor { imageTintColor = textColor } - - //create the space in the attirbuted String for the tooltip image and click action - let spaceForTooltip = String(repeating: " ", count: length) - - //find the middle of the space - let middle = (length/2) - //add the space to the attributed string - attributedString.insert(NSAttributedString(string: spaceForTooltip), at: location) + var frame = CGRect.zero + if let font = attributedString.attribute(.font, at: 0, effectiveRange: &originalRange) as? UIFont { + switch font.pointSize { + case 15..<25: + size = .medium + frame = CGRect(x: 0, y: -1, width: size.value.dimensions.width * 0.80, height: size.value.dimensions.height * 0.80) + case 0..<14: + size = .small + frame = CGRect(x: 0, y: -1, width: size.value.dimensions.width * 0.80 , height: size.value.dimensions.height * 0.80) + default: + size = .medium + frame = CGRect(x: 0, y: -1, width: size.value.dimensions.width, height: size.value.dimensions.height) + } + } //create the frame in which to hold the icon - let frame = CGRect(x: 0, y: 0, width: size.value.dimensions.width, height: size.value.dimensions.width) + let spacerframe = CGRect(x: 0, y: 0, width: VDSLayout.Spacing.space1X.value, height: size.value.dimensions.height) //create the image icon and match the color of the text - let tooltipAttribute = ImageLabelAttribute(location: location + middle, - length: 1, + let tooltipAttribute = ImageLabelAttribute(location: location, imageName: "info", frame: frame, tintColor: imageTintColor) - //create the action for the tooltip click - let tooltipAction = ActionLabelAttribute(location: location - middle, - length: length + middle, - shouldUnderline: false, - action: action) + let spacerAttribute = ImageLabelAttribute(location: location, + imageName: "info", + frame: spacerframe, + tintColor: .clear) - //apply the attribtes to the current attributedString - tooltipAttribute.setAttribute(on: attributedString) - tooltipAction.setAttribute(on: attributedString) + guard let tooltip = try? tooltipAttribute.getAttachment(), + let spacer = try? spacerAttribute.getAttachment() else { return } + attributedString.append(NSAttributedString(attachment: spacer)) + attributedString.append(NSAttributedString(attachment: tooltip)) + addHandler(on: attributedString) } - public init(id: UUID = UUID(), action: PassthroughSubject = PassthroughSubject(), subscriber: AnyCancellable? = nil, surface: Surface, accessibleText: String? = nil, closeButtonText: String, size: Tooltip.Size, title: String, content: String) { + public init(id: UUID = UUID(), action: PassthroughSubject = PassthroughSubject(), subscriber: AnyCancellable? = nil, surface: Surface, accessibleText: String? = nil, closeButtonText: String, title: String, content: String) { self.id = id self.action = action self.subscriber = subscriber self.surface = surface self.accessibleText = accessibleText self.closeButtonText = closeButtonText - self.size = size self.title = title self.content = content From 01c7df3c6981c3e536c7d1d7b31028f2790a923c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 8 May 2023 10:46:14 -0500 Subject: [PATCH 3/5] clearout attributes on a text reset Signed-off-by: Matt Bruce --- VDS/Components/Label/Label.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index f540e8e4..762e9daa 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -52,6 +52,7 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable { override open var text: String? { didSet { + attributes = nil didChange() } } From a2696ece91c5c06dee794f5b727fe0c9dfd50862 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 8 May 2023 10:46:42 -0500 Subject: [PATCH 4/5] updated trailing tooltip label Signed-off-by: Matt Bruce --- .../Tooltip/TrailingTooltipLabel.swift | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/VDS/Components/Tooltip/TrailingTooltipLabel.swift b/VDS/Components/Tooltip/TrailingTooltipLabel.swift index 0d0f8e19..5441d6eb 100644 --- a/VDS/Components/Tooltip/TrailingTooltipLabel.swift +++ b/VDS/Components/Tooltip/TrailingTooltipLabel.swift @@ -16,16 +16,16 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { // MARK: - Private Properties //-------------------------------------------------- private let tooltipAction = PassthroughSubject() - + //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- open var label = Label() open var labelText: String? { didSet { didChange() }} - + open var labelAttributes: [any LabelAttributeModel]? { didSet { didChange() } } - + open var labelTextStyle: TextStyle = .defaultStyle { didSet { didChange() } } open var labelTextPosition: TextPosition = .left { didSet { didChange() } } @@ -36,8 +36,6 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { open var tooltipCloseButtonText: String = "Close" { didSet { didChange() } } - open var tooltipSize: Tooltip.Size = .medium { didSet { didChange() } } - open var tooltipTitle: String = "" { didSet { didChange() } } open var tooltipContent: String = "" { didSet { didChange() } } @@ -68,43 +66,35 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { label.text = labelText label.textStyle = labelTextStyle label.textPosition = labelTextPosition + label.attributes = labelAttributes label.surface = surface label.disabled = disabled //add tooltip if let labelText, !labelText.isEmpty, !tooltipTitle.isEmpty, !tooltipContent.isEmpty { - //create the model - let model = Label.TooltipModel(surface: surface, - closeButtonText: tooltipCloseButtonText, - size: tooltipSize, - title: tooltipTitle, - content: tooltipContent) - - //add the model - label.addTooltip(model: model) + label.addTooltip(model: .init(surface: surface, closeButtonText: tooltipCloseButtonText, title: tooltipTitle, content: tooltipContent)) } } } + extension Label { public struct TooltipModel { public var surface: Surface public var closeButtonText: String - public var size: Tooltip.Size public var title: String public var content: String - public init(surface: Surface = .light, closeButtonText: String = "Close", size: Tooltip.Size = .medium, title: String, content: String) { + public init(surface: Surface = .light, closeButtonText: String = "Close", title: String, content: String) { self.surface = surface self.closeButtonText = closeButtonText - self.size = size self.title = title self.content = content } } public func addTooltip(model: TooltipModel) { - + var newAttributes: [any LabelAttributeModel] = [] if let attributes { attributes.forEach { attribute in @@ -113,11 +103,10 @@ extension Label { } } } - + if let text = text, !text.isEmpty { let tooltip = TooltipLabelAttribute(surface: surface, closeButtonText: model.closeButtonText, - size: model.size, title: model.title, content: model.content) newAttributes.append(tooltip) From 9b80d73b5447d833fb03e6a0ca983d8ad063d863 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 8 May 2023 10:46:56 -0500 Subject: [PATCH 5/5] updated entry field Signed-off-by: Matt Bruce --- VDS/Components/TextFields/EntryField/EntryField.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index dfadc9bc..ad31d7c2 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -110,7 +110,6 @@ open class EntryField: Control, Changeable { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.labelTextPosition = .left $0.labelTextStyle = .bodySmall - $0.tooltipSize = .small $0.tooltipYOffset = -2 } @@ -286,7 +285,7 @@ open class EntryField: Control, Changeable { if let oldText = updatedLabelText, !required, !oldText.hasSuffix("Optional") { let optionColorAttr = ColorLabelAttribute(location: oldText.count + 2, length: 8, - color: secondaryColorConfig.getColor(self)) + color: .red) updatedLabelText = "\(oldText) Optional" attributes.append(optionColorAttr)