refactored to use new TrailingTooltip
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
8a5b828a84
commit
c3992be682
@ -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 = "<group>"; };
|
||||
EA985C7C297DAED300F2FF2E /* Primitive.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Primitive.swift; sourceTree = "<group>"; };
|
||||
EAA5EEB428ECBFB4003B3210 /* ImageLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageLabelAttribute.swift; sourceTree = "<group>"; };
|
||||
EAA5EEB628ECC03A003B3210 /* ToolTipLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolTipLabelAttribute.swift; sourceTree = "<group>"; };
|
||||
EAA5EEB828ECD24B003B3210 /* Icons.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Icons.xcassets; sourceTree = "<group>"; };
|
||||
EAA5EEDF28F49DB3003B3210 /* Colorable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colorable.swift; sourceTree = "<group>"; };
|
||||
EAA5EEE328F5B855003B3210 /* VerizonNHGDS-Light.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "VerizonNHGDS-Light.otf"; sourceTree = "<group>"; };
|
||||
@ -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 */,
|
||||
|
||||
@ -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<Void, Never>
|
||||
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<Void, Never> = .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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<Void, Never>()
|
||||
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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user