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 ea79ed7b64
commit 0f2c045add

View File

@ -10,6 +10,7 @@ import UIKit
import Combine
public protocol LabelAttributeActionable: LabelAttributeModel {
var accessibleText: String? { get set }
var action: PassthroughSubject<Void, Never> { get set }
}
@ -29,15 +30,19 @@ public struct LabelAttributeActionModel: LabelAttributeActionable {
public var id = UUID()
public var location: Int
public var length: Int
public var shouldUnderline: Bool
public var accessibleText: String?
public var action = PassthroughSubject<Void, Never>()
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
public init(location: Int, length: Int) {
public init(location: Int, length: Int, shouldUnderline: Bool = true, accessibleText: String? = nil) {
self.location = location
self.length = length
self.shouldUnderline = shouldUnderline
self.accessibleText = accessibleText
}
private enum CodingKeys: String, CodingKey {
@ -45,6 +50,8 @@ public struct LabelAttributeActionModel: LabelAttributeActionable {
}
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)
}
}
}