refactored this to use new attribute
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
d3c44cdf32
commit
8ecccbcecb
@ -64,31 +64,67 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
|
|||||||
|
|
||||||
open override func updateView() {
|
open override func updateView() {
|
||||||
super.updateView()
|
super.updateView()
|
||||||
|
|
||||||
var attributes: [any LabelAttributeModel] = []
|
label.text = labelText
|
||||||
if let labelAttributes {
|
|
||||||
attributes.append(contentsOf: labelAttributes)
|
|
||||||
}
|
|
||||||
|
|
||||||
var updatedLabelText = labelText
|
|
||||||
|
|
||||||
//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: 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)
|
|
||||||
updatedLabelText = tooltipUpdateText
|
|
||||||
attributes.append(tooltipAttribute)
|
|
||||||
attributes.append(tooltipAction)
|
|
||||||
}
|
|
||||||
//set the titleLabel
|
|
||||||
label.text = updatedLabelText
|
|
||||||
label.attributes = attributes
|
|
||||||
label.textStyle = labelTextStyle
|
label.textStyle = labelTextStyle
|
||||||
label.textPosition = labelTextPosition
|
label.textPosition = labelTextPosition
|
||||||
label.surface = surface
|
label.surface = surface
|
||||||
label.disabled = disabled
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
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
|
||||||
|
if type(of: attribute) != TooltipLabelAttribute.self {
|
||||||
|
newAttributes.append(attribute)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !newAttributes.isEmpty {
|
||||||
|
attributes = newAttributes
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user