Merge branch 'develop' of https://gitlab.verizon.com/BPHV_MIPS/vds_ios into vasavk/carouselScrollbar
This commit is contained in:
commit
939465f7bc
@ -142,20 +142,11 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable {
|
|||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Overrides
|
|
||||||
//--------------------------------------------------
|
|
||||||
override open var intrinsicContentSize: CGSize {
|
|
||||||
let intrinsicContentSize = super.intrinsicContentSize
|
|
||||||
let adjustedWidth = intrinsicContentSize.width + titleEdgeInsets.left + titleEdgeInsets.right
|
|
||||||
let adjustedHeight = intrinsicContentSize.height + titleEdgeInsets.top + titleEdgeInsets.bottom
|
|
||||||
return CGSize(width: adjustedWidth, height: adjustedHeight)
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Methods
|
// MARK: - Private Methods
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private func updateLabel() {
|
private func updateLabel() {
|
||||||
|
defer { invalidateIntrinsicContentSize() }
|
||||||
|
|
||||||
//clear the arrays holding actions
|
//clear the arrays holding actions
|
||||||
accessibilityCustomActions = []
|
accessibilityCustomActions = []
|
||||||
|
|||||||
@ -75,7 +75,13 @@ open class TextLink: ButtonBase {
|
|||||||
|
|
||||||
/// The natural size for the receiving view, considering only properties of the view itself.
|
/// The natural size for the receiving view, considering only properties of the view itself.
|
||||||
open override var intrinsicContentSize: CGSize {
|
open override var intrinsicContentSize: CGSize {
|
||||||
return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize
|
guard let titleLabel else { return super.intrinsicContentSize }
|
||||||
|
// Calculate the titleLabel's intrinsic content size
|
||||||
|
let labelSize = titleLabel.sizeThatFits(CGSize(width: self.frame.width, height: CGFloat.greatestFiniteMagnitude))
|
||||||
|
// Adjust the size if needed (add any additional padding if your design requires)
|
||||||
|
let adjustedSize = CGSize(width: labelSize.width + contentEdgeInsets.left + contentEdgeInsets.right,
|
||||||
|
height: labelSize.height + contentEdgeInsets.top + contentEdgeInsets.bottom)
|
||||||
|
return adjustedSize
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -87,6 +93,10 @@ open class TextLink: ButtonBase {
|
|||||||
isAccessibilityElement = true
|
isAccessibilityElement = true
|
||||||
accessibilityTraits = .link
|
accessibilityTraits = .link
|
||||||
|
|
||||||
|
//left align titleLabel in case this is pinned leading/trailing
|
||||||
|
//default is always set to center
|
||||||
|
contentHorizontalAlignment = .left
|
||||||
|
|
||||||
if let titleLabel {
|
if let titleLabel {
|
||||||
addSubview(line)
|
addSubview(line)
|
||||||
line.pinLeading(titleLabel.leadingAnchor)
|
line.pinLeading(titleLabel.leadingAnchor)
|
||||||
|
|||||||
@ -79,6 +79,11 @@ open class TextLinkCaret: ButtonBase {
|
|||||||
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
|
|
||||||
|
//left align titleLabel in case this is pinned leading/trailing
|
||||||
|
//default is always set to center
|
||||||
|
contentHorizontalAlignment = .left
|
||||||
|
|
||||||
accessibilityTraits = .link
|
accessibilityTraits = .link
|
||||||
titleLabel?.numberOfLines = 0
|
titleLabel?.numberOfLines = 0
|
||||||
titleLabel?.lineBreakMode = .byWordWrapping
|
titleLabel?.lineBreakMode = .byWordWrapping
|
||||||
@ -98,10 +103,23 @@ open class TextLinkCaret: ButtonBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The natural size for the receiving view, considering only properties of the view itself.
|
/// The natural size for the receiving view, considering only properties of the view itself.
|
||||||
override open var intrinsicContentSize: CGSize {
|
open override var intrinsicContentSize: CGSize {
|
||||||
//get the labels size, if not the button
|
guard let titleLabel else { return super.intrinsicContentSize }
|
||||||
return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize
|
// Calculate the titleLabel's intrinsic content size
|
||||||
|
let labelSize = titleLabel.sizeThatFits(CGSize(width: self.frame.width - (contentEdgeInsets.left + contentEdgeInsets.right), height: CGFloat.greatestFiniteMagnitude))
|
||||||
|
// Adjust the size if needed (add any additional padding if your design requires)
|
||||||
|
let adjustedSize = CGSize(width: labelSize.width + contentEdgeInsets.left + contentEdgeInsets.right,
|
||||||
|
height: labelSize.height + contentEdgeInsets.top + contentEdgeInsets.bottom)
|
||||||
|
return adjustedSize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open override func layoutSubviews() {
|
||||||
|
super.layoutSubviews()
|
||||||
|
// This ensures the titleLabel is correctly positioned within the button
|
||||||
|
titleLabel?.preferredMaxLayoutWidth = self.frame.width - (contentEdgeInsets.left + contentEdgeInsets.right)
|
||||||
|
super.layoutSubviews() // Calling super again to ensure layout is updated with preferredMaxLayoutWidth
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension TextLinkCaret {
|
extension TextLinkCaret {
|
||||||
|
|||||||
@ -56,6 +56,8 @@ public struct ActionLabelAttribute: ActionLabelAttributeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
||||||
|
guard isValidRange(on: attributedString) else { return }
|
||||||
|
|
||||||
if(shouldUnderline){
|
if(shouldUnderline){
|
||||||
UnderlineLabelAttribute(location: location, length: length).setAttribute(on: attributedString)
|
UnderlineLabelAttribute(location: location, length: length).setAttribute(on: attributedString)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,8 @@ public protocol AttachmentLabelAttributeModel: LabelAttributeModel {
|
|||||||
|
|
||||||
extension AttachmentLabelAttributeModel {
|
extension AttachmentLabelAttributeModel {
|
||||||
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
||||||
|
guard isValidRange(on: attributedString) else { return }
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let mutableString = NSMutableAttributedString()
|
let mutableString = NSMutableAttributedString()
|
||||||
let attachment = try getAttachment()
|
let attachment = try getAttachment()
|
||||||
|
|||||||
@ -31,11 +31,21 @@ extension LabelAttributeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func isValidRange(on attributedString: NSMutableAttributedString) -> Bool {
|
public func isValidRange(on attributedString: NSMutableAttributedString) -> Bool {
|
||||||
range.location + range.length <= attributedString.string.count
|
attributedString.isValid(range: range)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public extension String {
|
||||||
|
func isValid(range: NSRange) -> Bool {
|
||||||
|
range.location >= 0 && range.length > 0 && range.location + range.length <= count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension NSAttributedString {
|
public extension NSAttributedString {
|
||||||
|
func isValid(range: NSRange) -> Bool {
|
||||||
|
range.location >= 0 && range.length > 0 && range.location + range.length <= length
|
||||||
|
}
|
||||||
|
|
||||||
func createAttributeModels() -> [(any LabelAttributeModel)] {
|
func createAttributeModels() -> [(any LabelAttributeModel)] {
|
||||||
var attributes: [any VDS.LabelAttributeModel] = []
|
var attributes: [any VDS.LabelAttributeModel] = []
|
||||||
enumerateAttributes(in: NSMakeRange(0, length)) { attributeMap, range, stop in
|
enumerateAttributes(in: NSMakeRange(0, length)) { attributeMap, range, stop in
|
||||||
@ -61,6 +71,7 @@ public extension NSAttributedString {
|
|||||||
|
|
||||||
extension NSMutableAttributedString {
|
extension NSMutableAttributedString {
|
||||||
public func apply(attribute: any LabelAttributeModel) {
|
public func apply(attribute: any LabelAttributeModel) {
|
||||||
|
guard isValid(range: attribute.range) else { return }
|
||||||
attribute.setAttribute(on: self)
|
attribute.setAttribute(on: self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,6 +24,8 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable
|
|||||||
public var presenter: UIView?
|
public var presenter: UIView?
|
||||||
|
|
||||||
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
||||||
|
guard isValidRange(on: attributedString) else { return }
|
||||||
|
|
||||||
//update the location
|
//update the location
|
||||||
location = attributedString.string.count - 1
|
location = attributedString.string.count - 1
|
||||||
|
|
||||||
|
|||||||
@ -344,7 +344,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
|
|||||||
for attribute in attributes {
|
for attribute in attributes {
|
||||||
|
|
||||||
//see if the attribute is Actionable
|
//see if the attribute is Actionable
|
||||||
if let actionable = attribute as? any ActionLabelAttributeModel{
|
if let actionable = attribute as? any ActionLabelAttributeModel, mutableAttributedString.isValid(range: actionable.range) {
|
||||||
//create a accessibleAction
|
//create a accessibleAction
|
||||||
let customAccessibilityAction = customAccessibilityAction(text: mutableAttributedString.string, range: actionable.range, accessibleText: actionable.accessibleText)
|
let customAccessibilityAction = customAccessibilityAction(text: mutableAttributedString.string, range: actionable.range, accessibleText: actionable.accessibleText)
|
||||||
|
|
||||||
@ -379,7 +379,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
|
|||||||
|
|
||||||
guard let text = text, let attributedText else { return nil }
|
guard let text = text, let attributedText else { return nil }
|
||||||
|
|
||||||
let actionText = accessibleText ?? NSString(string:text).substring(with: range)
|
let actionText = accessibleText ?? (text.isValid(range: range) ? NSString(string:text).substring(with: range) : text)
|
||||||
|
|
||||||
// Calculate the frame of the substring
|
// Calculate the frame of the substring
|
||||||
let layoutManager = NSLayoutManager()
|
let layoutManager = NSLayoutManager()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user