vds_ios/VDS/Components/Label/Attributes/ActionLabelAttribute.swift
Matt Bruce 669e0d7625 refactored enums into class/structs that use them
also refactored models into class that are the parents

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-01-13 13:32:38 -06:00

58 lines
1.7 KiB
Swift

//
// LabelAttributeAction.swift
// VDS
//
// Created by Matt Bruce on 8/3/22.
//
import Foundation
import UIKit
import Combine
public protocol ActionLabelAttributeModel: LabelAttributeModel {
var accessibleText: String? { get set }
var action: PassthroughSubject<Void, Never> { get set }
}
public struct ActionLabelAttribute: ActionLabelAttributeModel {
public static func == (lhs: ActionLabelAttribute, rhs: ActionLabelAttribute) -> Bool {
lhs.isEqual(rhs)
}
public func isEqual(_ equatable: ActionLabelAttribute) -> Bool {
return id == equatable.id && range == equatable.range
}
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
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, shouldUnderline: Bool = true, accessibleText: String? = nil) {
self.location = location
self.length = length
self.shouldUnderline = shouldUnderline
self.accessibleText = accessibleText
}
private enum CodingKeys: String, CodingKey {
case location, length
}
public func setAttribute(on attributedString: NSMutableAttributedString) {
if(shouldUnderline){
attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single, range: range)
}
}
}