refactored class for init and Key
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
1d3431da2c
commit
c3f6fc1d10
@ -32,17 +32,18 @@ public struct ActionLabelAttribute: ActionLabelAttributeModel {
|
|||||||
public var length: Int
|
public var length: Int
|
||||||
public var shouldUnderline: Bool
|
public var shouldUnderline: Bool
|
||||||
public var accessibleText: String?
|
public var accessibleText: String?
|
||||||
public var action = PassthroughSubject<Void, Never>()
|
public var action: PassthroughSubject<Void, Never>
|
||||||
public var subscriber: AnyCancellable?
|
public var subscriber: AnyCancellable?
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializer
|
// 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<Void, Never> = .init() ) {
|
||||||
self.location = location
|
self.location = location
|
||||||
self.length = length
|
self.length = length
|
||||||
self.shouldUnderline = shouldUnderline
|
self.shouldUnderline = shouldUnderline
|
||||||
self.accessibleText = accessibleText
|
self.accessibleText = accessibleText
|
||||||
|
self.action = action
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
@ -53,5 +54,10 @@ public struct ActionLabelAttribute: ActionLabelAttributeModel {
|
|||||||
if(shouldUnderline){
|
if(shouldUnderline){
|
||||||
UnderlineLabelAttribute(location: location, length: length).setAttribute(on: attributedString)
|
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")
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user