diff --git a/VDS/Components/Label/Attributes/ActionLabelAttribute.swift b/VDS/Components/Label/Attributes/ActionLabelAttribute.swift index cb3453ef..1b9ce53a 100644 --- a/VDS/Components/Label/Attributes/ActionLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/ActionLabelAttribute.swift @@ -32,17 +32,18 @@ public struct ActionLabelAttribute: ActionLabelAttributeModel { public var length: Int public var shouldUnderline: Bool public var accessibleText: String? - public var action = PassthroughSubject() + public var action: PassthroughSubject public var subscriber: AnyCancellable? //-------------------------------------------------- // MARK: - Initializer //-------------------------------------------------- - public init(location: Int, length: Int, shouldUnderline: Bool = true, accessibleText: String? = nil) { + public init(location: Int, length: Int, shouldUnderline: Bool = true, accessibleText: String? = nil, action: PassthroughSubject = .init() ) { self.location = location self.length = length self.shouldUnderline = shouldUnderline self.accessibleText = accessibleText + self.action = action } private enum CodingKeys: String, CodingKey { @@ -53,5 +54,10 @@ public struct ActionLabelAttribute: ActionLabelAttributeModel { if(shouldUnderline){ UnderlineLabelAttribute(location: location, length: length).setAttribute(on: attributedString) } + attributedString.addAttribute(NSAttributedString.Key.action, value: "handler", range: range) } } + +extension NSAttributedString.Key { + public static let action = NSAttributedString.Key(rawValue: "action") +}