added new properties for accessible and for actions that aren't text

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-10-04 11:38:20 -05:00
parent 7d007e0391
commit be71919ccf

View File

@ -10,6 +10,7 @@ import UIKit
import Combine import Combine
public protocol LabelAttributeActionable: LabelAttributeModel { public protocol LabelAttributeActionable: LabelAttributeModel {
var accessibleText: String? { get set }
var action: PassthroughSubject<Void, Never> { get set } var action: PassthroughSubject<Void, Never> { get set }
} }
@ -29,15 +30,19 @@ public struct LabelAttributeActionModel: LabelAttributeActionable {
public var id = UUID() public var id = UUID()
public var location: Int public var location: Int
public var length: Int public var length: Int
public var shouldUnderline: Bool
public var accessibleText: String?
public var action = PassthroughSubject<Void, Never>() public var action = PassthroughSubject<Void, Never>()
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializer // MARK: - Initializer
//-------------------------------------------------- //--------------------------------------------------
public init(location: Int, length: Int) { public init(location: Int, length: Int, shouldUnderline: Bool = true, accessibleText: String? = nil) {
self.location = location self.location = location
self.length = length self.length = length
self.shouldUnderline = shouldUnderline
self.accessibleText = accessibleText
} }
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
@ -45,6 +50,8 @@ public struct LabelAttributeActionModel: LabelAttributeActionable {
} }
public func setAttribute(on attributedString: NSMutableAttributedString) { public func setAttribute(on attributedString: NSMutableAttributedString) {
attributedString.addAttribute(.underlineStyle, value: UnderlineStyle.single.value(), range: range) if(shouldUnderline){
attributedString.addAttribute(.underlineStyle, value: UnderlineStyle.single.value(), range: range)
}
} }
} }