fixed attributes

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-08-25 10:18:00 -05:00
parent 7e061d28e5
commit f08f1672fb
3 changed files with 20 additions and 4 deletions

View File

@ -119,7 +119,7 @@ extension TextLinkCaret {
}
func setAttribute(on attributedString: NSMutableAttributedString) {
let imageAttr = ImageLabelAttribute(location: location, imageName: "\(position.rawValue)-caret-bold", frame: .init(x: 0, y: 0, width: caretSize.width, height: caretSize.height), tintColor: tintColor)
let imageAttr = ImageLabelAttribute(location: location, imageName: "\(position.rawValue)-caret-bold", frame: .init(x: 0, y: 0, width: caretSize.width, height: caretSize.height), tintColor: tintColor, accessibleText: "Caret")
let spacer = NSAttributedString.spacer(for: spacerWidth)
guard let image = try? imageAttr.getAttachment() else { return }

View File

@ -28,7 +28,8 @@ public struct ImageLabelAttribute: AttachmentLabelAttributeModel {
public var image: UIImage?
public var frame: CGRect?
public var tintColor: UIColor?
public var accessibleText: String?
//--------------------------------------------------
// MARK: - Equatable
//--------------------------------------------------
@ -40,11 +41,27 @@ public struct ImageLabelAttribute: AttachmentLabelAttributeModel {
return id == equatable.id && range == equatable.range && imageName == equatable.imageName
}
public init(id: UUID = UUID(), location: Int, imageName: String? = nil, image: UIImage? = nil, frame: CGRect? = nil, tintColor: UIColor? = nil, accessibleText: String? = nil) {
self.id = id
self.location = location
self.imageName = imageName
self.image = image
self.frame = frame
self.tintColor = tintColor
self.accessibleText = accessibleText
}
//--------------------------------------------------
// MARK: - Private Functions
//--------------------------------------------------
private func imageAttachment(image: UIImage) -> NSTextAttachment {
let attachment = NSTextAttachment()
if let accessibleText {
attachment.accessibilityLabel = accessibleText
attachment.isAccessibilityElement = true
} else {
attachment.isAccessibilityElement = false
}
attachment.image = tintColor != nil ? image.withTintColor(tintColor!) : image
if let frame {
attachment.bounds = frame

View File

@ -68,9 +68,8 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable
addHandler(on: attributedString)
}
public init(id: UUID = UUID(), action: PassthroughSubject<Void, Never> = PassthroughSubject<Void, Never>(), subscriber: AnyCancellable? = nil, surface: Surface, accessibleText: String? = nil, closeButtonText: String = "Close", title: String? = nil, content: String? = nil, contentView: UIView? = nil, presenter: UIView? = nil) {
public init(id: UUID = UUID(), subscriber: AnyCancellable? = nil, surface: Surface, accessibleText: String? = nil, closeButtonText: String = "Close", title: String? = nil, content: String? = nil, contentView: UIView? = nil, presenter: UIView? = nil) {
self.id = id
self.action = action
self.subscriber = subscriber
self.surface = surface
self.accessibleText = accessibleText