updated action label
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
9c3fbe9a84
commit
7e061d28e5
@ -38,18 +38,17 @@ public struct ActionLabelAttribute: ActionLabelAttributeModel {
|
||||
public var length: Int
|
||||
public var shouldUnderline: Bool
|
||||
public var accessibleText: String?
|
||||
public var action: PassthroughSubject<Void, Never>
|
||||
public var action = PassthroughSubject<Void, Never>()
|
||||
public var subscriber: AnyCancellable?
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializer
|
||||
//--------------------------------------------------
|
||||
|
||||
public init(location: Int, length: Int, shouldUnderline: Bool = true, accessibleText: String? = nil, action: PassthroughSubject<Void, Never> = .init() ) {
|
||||
public init(location: Int, length: Int, shouldUnderline: Bool = true, accessibleText: String? = nil) {
|
||||
self.location = location
|
||||
self.length = length
|
||||
self.shouldUnderline = shouldUnderline
|
||||
self.accessibleText = accessibleText
|
||||
self.action = action
|
||||
}
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
@ -67,3 +66,19 @@ public struct ActionLabelAttribute: ActionLabelAttributeModel {
|
||||
extension NSAttributedString.Key {
|
||||
public static let action = NSAttributedString.Key(rawValue: "action")
|
||||
}
|
||||
|
||||
extension String {
|
||||
public func nsRange(of text: String) -> NSRange? {
|
||||
guard let found = range(of: text) else { return nil }
|
||||
return NSRange(found, in: self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension ActionLabelAttribute {
|
||||
|
||||
public init? (text: String, linkText: String, accessibleText: String? = nil) {
|
||||
guard let range = text.nsRange(of: linkText) else { return nil }
|
||||
self.init(location: range.location, length: range.length)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user