From f08f1672fb87d015c888103c5b6a3b1ffb1bf546 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 10:18:00 -0500 Subject: [PATCH] fixed attributes Signed-off-by: Matt Bruce --- .../Buttons/TextLinkCaret/TextLinkCaret.swift | 2 +- .../Attributes/ImageLabelAttribute.swift | 19 ++++++++++++++++++- .../Attributes/TooltipLabelAttribute.swift | 3 +-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index a41ebfb0..2e75e6a3 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -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 } diff --git a/VDS/Components/Label/Attributes/ImageLabelAttribute.swift b/VDS/Components/Label/Attributes/ImageLabelAttribute.swift index dcd98629..7cc2f224 100644 --- a/VDS/Components/Label/Attributes/ImageLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/ImageLabelAttribute.swift @@ -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 diff --git a/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift b/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift index d77e03fe..26867749 100644 --- a/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift @@ -68,9 +68,8 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable addHandler(on: attributedString) } - public init(id: UUID = UUID(), action: PassthroughSubject = PassthroughSubject(), 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