From c3f6fc1d10eb0b7528ed73b321779ac223f91348 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 17 Apr 2023 13:10:42 -0500 Subject: [PATCH] refactored class for init and Key Signed-off-by: Matt Bruce --- .../Label/Attributes/ActionLabelAttribute.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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") +}