Merge branch 'feature/tilet' into 'develop'

updated for attributes

See merge request BPHV_MIPS/vds_ios!36
This commit is contained in:
Bruce, Matt R 2023-01-27 16:15:52 +00:00
commit 8cdc77764f
6 changed files with 30 additions and 14 deletions

View File

@ -33,7 +33,7 @@ public struct ActionLabelAttribute: ActionLabelAttributeModel {
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?
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializer // MARK: - Initializer
//-------------------------------------------------- //--------------------------------------------------
@ -51,7 +51,7 @@ public struct ActionLabelAttribute: ActionLabelAttributeModel {
public func setAttribute(on attributedString: NSMutableAttributedString) { public func setAttribute(on attributedString: NSMutableAttributedString) {
if(shouldUnderline){ if(shouldUnderline){
attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single, range: range) UnderlineLabelAttribute(location: location, length: length).setAttribute(on: attributedString)
} }
} }
} }

View File

@ -27,14 +27,14 @@ public struct TextStyleLabelAttribute: LabelAttributeModel {
public var location: Int public var location: Int
public var length: Int public var length: Int
public var textStyle: TextStyle public var textStyle: TextStyle
public var textColor: UIColor public var textColor: UIColor?
public var textPosition: TextPosition public var textPosition: TextPosition
public var lineBreakMode: NSLineBreakMode public var lineBreakMode: NSLineBreakMode
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializer // MARK: - Initializer
//-------------------------------------------------- //--------------------------------------------------
public init(location: Int, length: Int, textStyle: TextStyle, textColor: UIColor = .black, textPosition: TextPosition = .left, lineBreakMode: NSLineBreakMode = .byWordWrapping) { public init(location: Int, length: Int, textStyle: TextStyle, textColor: UIColor? = nil, textPosition: TextPosition = .left, lineBreakMode: NSLineBreakMode = .byWordWrapping) {
self.location = location self.location = location
self.length = length self.length = length
self.textStyle = textStyle self.textStyle = textStyle
@ -45,9 +45,11 @@ public struct TextStyleLabelAttribute: LabelAttributeModel {
public func setAttribute(on attributedString: NSMutableAttributedString) { public func setAttribute(on attributedString: NSMutableAttributedString) {
attributedString.removeAttribute(.font, range: range) attributedString.removeAttribute(.font, range: range)
attributedString.removeAttribute(.foregroundColor, range: range)
attributedString.addAttribute(.font, value: textStyle.font, range: range) attributedString.addAttribute(.font, value: textStyle.font, range: range)
attributedString.addAttribute(.foregroundColor, value: textColor, range: range) if let textColor {
attributedString.removeAttribute(.foregroundColor, range: range)
attributedString.addAttribute(.foregroundColor, value: textColor, range: range)
}
setStyleAttributes(attributedString) setStyleAttributes(attributedString)
} }

View File

@ -12,7 +12,7 @@ import Combine
public struct ToolTipLabelAttribute: ActionLabelAttributeModel { public struct ToolTipLabelAttribute: ActionLabelAttributeModel {
public var id = UUID() public var id = UUID()
public var accessibleText: String? = "Tool Tip" public var accessibleText: String? = "Tool Tip"
public var action = PassthroughSubject<Void, Never>() public var action: PassthroughSubject<Void, Never>
public var location: Int public var location: Int
public var length: Int public var length: Int
public var tintColor: UIColor public var tintColor: UIColor
@ -28,6 +28,14 @@ public struct ToolTipLabelAttribute: ActionLabelAttributeModel {
} }
public init(action: PassthroughSubject<Void, Never> = .init(), location: Int, length: Int, tintColor: UIColor = .black, accessibleText: String? = nil){
self.action = action
self.location = location
self.length = length
self.tintColor = tintColor
self.accessibleText = accessibleText
}
public static func == (lhs: ToolTipLabelAttribute, rhs: ToolTipLabelAttribute) -> Bool { public static func == (lhs: ToolTipLabelAttribute, rhs: ToolTipLabelAttribute) -> Bool {
lhs.isEqual(rhs) lhs.isEqual(rhs)
} }

View File

@ -49,7 +49,7 @@ extension Tilelet {
public func toTitleLockupSubTitleModel() -> TitleLockup.SubTitleModel { public func toTitleLockupSubTitleModel() -> TitleLockup.SubTitleModel {
TitleLockup.SubTitleModel(text: text, TitleLockup.SubTitleModel(text: text,
textColor: textColor, textColor: textColor,
textAttributes: nil) textAttributes: textAttributes)
} }
} }
} }

View File

@ -48,7 +48,7 @@ extension Tilelet {
//-------------------------------------------------- //--------------------------------------------------
public func toTitleLockupTitleModel() -> TitleLockup.TitleModel { public func toTitleLockupTitleModel() -> TitleLockup.TitleModel {
TitleLockup.TitleModel(text: text, TitleLockup.TitleModel(text: text,
textAttributes: nil, textAttributes: textAttributes,
textStyle: textStyle.value) textStyle: textStyle.value)
} }
} }

View File

@ -65,10 +65,10 @@ public enum TextStyle: String, CaseIterable {
//MARK: FontCategory //MARK: FontCategory
extension TextStyle { extension TextStyle {
public enum FontCategory: String, CaseIterable { public enum FontCategory: String, CaseIterable {
case feature = "Feature" case feature
case title = "Title" case title
case body = "Body" case body
case micro = "micro" case micro
public var sizes: [FontSize] { public var sizes: [FontSize] {
switch self { switch self {
@ -84,7 +84,13 @@ extension TextStyle {
} }
public func style(for fontSize: FontSize?, isBold: Bool = false) -> TextStyle? { public func style(for fontSize: FontSize?, isBold: Bool = false) -> TextStyle? {
let styleName = "\(isBold ? "Bold" : "")\(self.rawValue)\(fontSize?.rawValue ?? "")" var styleName = ""
if isBold {
let newRaw = rawValue.prefix(1).description.uppercased() + rawValue.dropFirst()
styleName = "\(isBold ? "bold" : "")\(newRaw)\(fontSize?.rawValue ?? "")"
} else {
styleName = "\(rawValue)\(fontSize?.rawValue ?? "")"
}
guard let style = TextStyle(rawValue: styleName) else { guard let style = TextStyle(rawValue: styleName) else {
return nil return nil
} }