From c3992be682bf847b3d76b37613c4f1aef2ab2955 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 17 Apr 2023 13:35:23 -0500 Subject: [PATCH] refactored to use new TrailingTooltip Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 4 - .../Attributes/ToolTipLabelAttribute.swift | 58 ------------- .../TextFields/EntryField/EntryField.swift | 82 +++---------------- .../Tooltip/TrailingTooltipLabel.swift | 3 +- 4 files changed, 14 insertions(+), 133 deletions(-) delete mode 100644 VDS/Components/Label/Attributes/ToolTipLabelAttribute.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index b1ff247c..971a0126 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -68,7 +68,6 @@ EA985C692971B90B00F2FF2E /* IconSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985C682971B90B00F2FF2E /* IconSize.swift */; }; EA985C7D297DAED300F2FF2E /* Primitive.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985C7C297DAED300F2FF2E /* Primitive.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 */; }; EAA5EEE428F5B855003B3210 /* VerizonNHGDS-Light.otf in Resources */ = {isa = PBXBuildFile; fileRef = EAA5EEE328F5B855003B3210 /* VerizonNHGDS-Light.otf */; }; EAA5EEEF28F5C908003B3210 /* VDSTypographyTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAA5EEEC28F5C908003B3210 /* VDSTypographyTokens.xcframework */; }; @@ -190,7 +189,6 @@ EA985C682971B90B00F2FF2E /* IconSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconSize.swift; sourceTree = ""; }; EA985C7C297DAED300F2FF2E /* Primitive.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Primitive.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 = ""; }; EAA5EEDF28F49DB3003B3210 /* Colorable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colorable.swift; sourceTree = ""; }; EAA5EEE328F5B855003B3210 /* VerizonNHGDS-Light.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "VerizonNHGDS-Light.otf"; sourceTree = ""; }; @@ -665,7 +663,6 @@ EAF7F0AA289B13FD00B287F5 /* TextStyleLabelAttribute.swift */, EAA5EEB428ECBFB4003B3210 /* ImageLabelAttribute.swift */, EAF7F0AC289B142900B287F5 /* StrikeThroughLabelAttribute.swift */, - EAA5EEB628ECC03A003B3210 /* ToolTipLabelAttribute.swift */, EAF7F0AE289B144C00B287F5 /* UnderlineLabelAttribute.swift */, ); path = Attributes; @@ -814,7 +811,6 @@ EAC925832911B35400091998 /* TextLinkCaret.swift in Sources */, EA33622E2891EA3C0071C351 /* DispatchQueue+Once.swift in Sources */, EA4DB2FD28D3D0CA00103EE3 /* AnyEquatable.swift in Sources */, - EAA5EEB728ECC03A003B3210 /* ToolTipLabelAttribute.swift in Sources */, EA5E305A29510F8B0082B959 /* EnumSubset.swift in Sources */, EA985BF7296C665E00F2FF2E /* IconName.swift in Sources */, EAF7F0AF289B144C00B287F5 /* UnderlineLabelAttribute.swift in Sources */, diff --git a/VDS/Components/Label/Attributes/ToolTipLabelAttribute.swift b/VDS/Components/Label/Attributes/ToolTipLabelAttribute.swift deleted file mode 100644 index 9b3f19e7..00000000 --- a/VDS/Components/Label/Attributes/ToolTipLabelAttribute.swift +++ /dev/null @@ -1,58 +0,0 @@ -// -// ToolTipLabelAttribute.swift -// VDS -// -// Created by Matt Bruce on 10/4/22. -// - -import Foundation -import UIKit -import Combine - -public struct ToolTipLabelAttribute: ActionLabelAttributeModel { - public var id = UUID() - public var accessibleText: String? = "Tool Tip" - public var action: PassthroughSubject - 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) { - var size = size.dimensions.height - var yPos = (lineHeight - size) / 2 - print("tooltip yPos: \(yPos)") - if yPos < 0 { - yPos = 0 - size = lineHeight - } - let image = ImageLabelAttribute(location: location, - length: length, - imageName: "info", - 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, 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 { - lhs.isEqual(rhs) - } - - public func isEqual(_ equatable: ToolTipLabelAttribute) -> Bool { - return id == equatable.id && range == equatable.range - } -} - diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index 20f221cb..dfadc9bc 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -106,11 +106,12 @@ open class EntryField: Control, Changeable { } } - open var titleLabel = Label().with { + open var titleLabel = TrailingTooltipLabel().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) - $0.attributes = [] - $0.textPosition = .left - $0.textStyle = .bodySmall + $0.labelTextPosition = .left + $0.labelTextStyle = .bodySmall + $0.tooltipSize = .small + $0.tooltipYOffset = -2 } open var errorLabel = Label().with { @@ -228,56 +229,14 @@ open class EntryField: Control, Changeable { return containerView } - open func getToolTipView() -> UIView? { - guard let tooltipTitle, let tooltipContent, !tooltipTitle.isEmpty, !tooltipContent.isEmpty else { - return nil - } - - let stack = UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.axis = .vertical - $0.distribution = .fill - $0.spacing = 4 - } - - let title = Label().with { - $0.setContentCompressionResistancePriority(.required, for: .vertical) - $0.textPosition = .left - $0.textStyle = .boldBodySmall - $0.text = tooltipTitle - $0.surface = surface - $0.disabled = disabled - } - - let content = Label().with { - $0.setContentCompressionResistancePriority(.required, for: .vertical) - $0.textPosition = .left - $0.textStyle = .boldBodySmall - $0.text = tooltipContent - $0.surface = surface - $0.disabled = disabled - } - - stack.addArrangedSubview(title) - stack.addArrangedSubview(content) - - stack.backgroundColor = backgroundColorConfiguration.getColor(self) - - return stack - } - - open func showToolTipView(){ - print("toolTip clicked: showToolTipView() called") - } - open override func reset() { super.reset() titleLabel.reset() errorLabel.reset() helperLabel.reset() - titleLabel.textPosition = .left - titleLabel.textStyle = .bodySmall + titleLabel.labelTextPosition = .left + titleLabel.labelTextStyle = .bodySmall errorLabel.textPosition = .left errorLabel.textStyle = .bodySmall helperLabel.textPosition = .left @@ -332,29 +291,12 @@ open class EntryField: Control, Changeable { updatedLabelText = "\(oldText) Optional" attributes.append(optionColorAttr) } - - //add the tool tip - if let view = getToolTipView(), let oldText = updatedLabelText { - tooltipView = view - let toolTipAction = PassthroughSubject() - 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: primaryColorConfig.getColor(self)) - updatedLabelText = toolTipUpdateText - attributes.append(toolTipAttribute) - toolTipAction.sink { [weak self] in - self?.showToolTipView() - }.store(in: &subscribers) - } else { - tooltipView = nil - } - + //set the titleLabel - titleLabel.text = updatedLabelText - titleLabel.attributes = attributes + titleLabel.labelText = updatedLabelText + titleLabel.labelAttributes = attributes + titleLabel.tooltipTitle = tooltipTitle ?? "" + titleLabel.tooltipContent = tooltipContent ?? "" titleLabel.surface = surface titleLabel.disabled = disabled diff --git a/VDS/Components/Tooltip/TrailingTooltipLabel.swift b/VDS/Components/Tooltip/TrailingTooltipLabel.swift index 7920c17d..206aa413 100644 --- a/VDS/Components/Tooltip/TrailingTooltipLabel.swift +++ b/VDS/Components/Tooltip/TrailingTooltipLabel.swift @@ -42,6 +42,7 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { open var tooltipContent: String = "" { didSet { didChange() } } + open var tooltipYOffset: CGFloat = 0 { didSet { didChange() } } //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- @@ -74,7 +75,7 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { //add the tool tip if let oldText = updatedLabelText, !tooltipTitle.isEmpty, !tooltipContent.isEmpty { let tooltipUpdateText = "\(oldText) " //create a little space between the final character and tooltip image - let frame = CGRect(x: 0, y: 0, width: tooltipSize.dimensions.width, height: tooltipSize.dimensions.width) + let frame = CGRect(x: 0, y: tooltipYOffset, width: tooltipSize.dimensions.width, height: tooltipSize.dimensions.width) let color = textColorConfiguration.getColor(self) let tooltipAttribute = ImageLabelAttribute(location: tooltipUpdateText.count - 2, imageName: "info", frame: frame, tintColor: color) let tooltipAction = ActionLabelAttribute(location: tooltipUpdateText.count - 3, length: 3, shouldUnderline: false, action: tooltipAction)