From 24bad2c37168e9c59114a53627be03044f8c2f35 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 14 Apr 2023 15:41:33 -0500 Subject: [PATCH] refactored trailing tooltip label Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 10 +++++----- .../Attributes/ToolTipLabelAttribute.swift | 11 +++++++++-- ...aunchable.swift => TooltipLaunchable.swift} | 0 .../Tooltip/TrailingTooltipLabel.swift | 18 ++++++++++-------- 4 files changed, 24 insertions(+), 15 deletions(-) rename VDS/Components/Tooltip/{ToolTipLaunchable.swift => TooltipLaunchable.swift} (100%) diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 6fc40507..b1ff247c 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -82,7 +82,7 @@ EAB2376229E9880400AABE9A /* TrailingTooltipLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB2376129E9880400AABE9A /* TrailingTooltipLabel.swift */; }; EAB2376629E9952D00AABE9A /* UIApplication.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB2376529E9952D00AABE9A /* UIApplication.swift */; }; EAB2376829E9992800AABE9A /* TooltipAlertViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB2376729E9992800AABE9A /* TooltipAlertViewController.swift */; }; - EAB2376A29E9E59100AABE9A /* ToolTipLaunchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB2376929E9E59100AABE9A /* ToolTipLaunchable.swift */; }; + EAB2376A29E9E59100AABE9A /* TooltipLaunchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB2376929E9E59100AABE9A /* TooltipLaunchable.swift */; }; EAB5FED429267EB300998C17 /* UIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FED329267EB300998C17 /* UIView.swift */; }; EAB5FEED2927E1B200998C17 /* ButtonGroupPositionLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEEC2927E1B200998C17 /* ButtonGroupPositionLayout.swift */; }; EAB5FEF12927F4AA00998C17 /* SelfSizingCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF02927F4AA00998C17 /* SelfSizingCollectionView.swift */; }; @@ -205,7 +205,7 @@ EAB2376129E9880400AABE9A /* TrailingTooltipLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrailingTooltipLabel.swift; sourceTree = ""; }; EAB2376529E9952D00AABE9A /* UIApplication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIApplication.swift; sourceTree = ""; }; EAB2376729E9992800AABE9A /* TooltipAlertViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TooltipAlertViewController.swift; sourceTree = ""; }; - EAB2376929E9E59100AABE9A /* ToolTipLaunchable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolTipLaunchable.swift; sourceTree = ""; }; + EAB2376929E9E59100AABE9A /* TooltipLaunchable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TooltipLaunchable.swift; sourceTree = ""; }; EAB5FED329267EB300998C17 /* UIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIView.swift; sourceTree = ""; }; EAB5FEEC2927E1B200998C17 /* ButtonGroupPositionLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonGroupPositionLayout.swift; sourceTree = ""; }; EAB5FEF02927F4AA00998C17 /* SelfSizingCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelfSizingCollectionView.swift; sourceTree = ""; }; @@ -596,9 +596,9 @@ isa = PBXGroup; children = ( EAB2375C29E8789100AABE9A /* Tooltip.swift */, - EAB2376129E9880400AABE9A /* TrailingTooltipLabel.swift */, EAB2376729E9992800AABE9A /* TooltipAlertViewController.swift */, - EAB2376929E9E59100AABE9A /* ToolTipLaunchable.swift */, + EAB2376929E9E59100AABE9A /* TooltipLaunchable.swift */, + EAB2376129E9880400AABE9A /* TrailingTooltipLabel.swift */, ); path = Tooltip; sourceTree = ""; @@ -807,7 +807,7 @@ EAC9258C2911C9DE00091998 /* InputField.swift in Sources */, EA3362402892EF6C0071C351 /* Label.swift in Sources */, EAB2376229E9880400AABE9A /* TrailingTooltipLabel.swift in Sources */, - EAB2376A29E9E59100AABE9A /* ToolTipLaunchable.swift in Sources */, + EAB2376A29E9E59100AABE9A /* TooltipLaunchable.swift in Sources */, EAB2375D29E8789100AABE9A /* Tooltip.swift in Sources */, EA985C23296E033A00F2FF2E /* TextArea.swift in Sources */, EAF7F0B3289B1ADC00B287F5 /* ActionLabelAttribute.swift in Sources */, diff --git a/VDS/Components/Label/Attributes/ToolTipLabelAttribute.swift b/VDS/Components/Label/Attributes/ToolTipLabelAttribute.swift index f42ac630..4a31f070 100644 --- a/VDS/Components/Label/Attributes/ToolTipLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/ToolTipLabelAttribute.swift @@ -16,24 +16,31 @@ public struct ToolTipLabelAttribute: ActionLabelAttributeModel { public var location: Int public var length: Int public var tintColor: UIColor + public var lineHeight: CGFloat + public var size: Tooltip.Size public func setAttribute(on attributedString: NSMutableAttributedString) { + let size = size.dimensions.height + var yPos = (lineHeight / 2) - size + if yPos < 0 { yPos = 0 } let image = ImageLabelAttribute(location: location, length: length, imageName: "info", - frame: .init(x: 0, y: -2, width: 13.3, height: 13.3), + frame: .init(x: 0, y: yPos, width: size, height: size), tintColor: tintColor) image.setAttribute(on: attributedString) } - public init(action: PassthroughSubject = .init(), location: Int, length: Int, tintColor: UIColor = .black, accessibleText: String? = nil){ + public init(action: PassthroughSubject = .init(), location: Int, length: Int, tintColor: UIColor = .black, accessibleText: String? = nil, size: Tooltip.Size = .medium, lineHeight: CGFloat = 0.0){ self.action = action self.location = location self.length = length self.tintColor = tintColor self.accessibleText = accessibleText + self.lineHeight = lineHeight + self.size = size } public static func == (lhs: ToolTipLabelAttribute, rhs: ToolTipLabelAttribute) -> Bool { diff --git a/VDS/Components/Tooltip/ToolTipLaunchable.swift b/VDS/Components/Tooltip/TooltipLaunchable.swift similarity index 100% rename from VDS/Components/Tooltip/ToolTipLaunchable.swift rename to VDS/Components/Tooltip/TooltipLaunchable.swift diff --git a/VDS/Components/Tooltip/TrailingTooltipLabel.swift b/VDS/Components/Tooltip/TrailingTooltipLabel.swift index 26b29620..57f62960 100644 --- a/VDS/Components/Tooltip/TrailingTooltipLabel.swift +++ b/VDS/Components/Tooltip/TrailingTooltipLabel.swift @@ -32,7 +32,7 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { label.textColorConfiguration }() { didSet { didChange() }} - open var closeButtonText: String = "Close" { didSet { didChange() }} + open var tooltipCloseButtonText: String = "Close" { didSet { didChange() }} open var tooltipSize: Tooltip.Size = .medium { didSet { didChange() }} @@ -55,7 +55,7 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { self.presentTooltip(surface: self.surface, title: self.tooltipTitle, content: self.tooltipContent, - closeButtonText: self.closeButtonText) + closeButtonText: self.tooltipCloseButtonText) }.store(in: &subscribers) } @@ -68,18 +68,20 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { } var updatedLabelText = labelText - + //add the tool tip - if let oldText = updatedLabelText { + if let oldText = updatedLabelText, !tooltipTitle.isEmpty, !tooltipContent.isEmpty { let toolTipUpdateText = "\(oldText) " //create a little space between the final character and tooltip image let toolTipAttribute = ToolTipLabelAttribute(action: toolTipAction, - location: toolTipUpdateText.count - 1, - length: 1, - tintColor: textColorConfiguration.getColor(self)) + location: toolTipUpdateText.count - 1, + length: 1, + tintColor: textColorConfiguration.getColor(self), + size: tooltipSize, + lineHeight: labelTextStyle.lineHeight) updatedLabelText = toolTipUpdateText attributes.append(toolTipAttribute) } - + label.debugBorder() //set the titleLabel label.text = updatedLabelText label.attributes = attributes