more changes

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-01-31 10:05:36 -06:00
parent d8f3819063
commit c2c2bfeb4a

View File

@ -51,7 +51,9 @@ open class TextLinkCaret: ButtonBase {
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted) $0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted)
} }
private var imageAttribute: CaretLabelAttribute? private var imageAttribute: CaretLabelAttribute? {
iconPosition == .right ? CaretLabelAttribute(tintColor: textColor, position: iconPosition) : nil
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Public Properties // MARK: - Public Properties
@ -81,19 +83,12 @@ open class TextLinkCaret: ButtonBase {
super.setup() super.setup()
accessibilityTraits = .link accessibilityTraits = .link
titleLabel?.numberOfLines = 0 titleLabel?.numberOfLines = 0
if let caret = BundleManager.shared.image(for: Icon.Name.leftCaretBold.rawValue) {
setImage(caret, for: .normal)
}
} }
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.
open override func updateView() { open override func updateView() {
if iconPosition == .right { setImage(iconPosition == .right ? nil : BundleManager.shared.image(for: Icon.Name.leftCaretBold.rawValue), for: .normal)
imageAttribute = CaretLabelAttribute(tintColor: textColor, position: iconPosition) imageEdgeInsets = iconPosition == .right ? .zero : .init(top: 0, left: -spacing, bottom: 0, right: 0)
} else {
imageAttribute = nil
}
imageView?.isHidden = iconPosition == .right
super.updateView() super.updateView()
} }
@ -110,13 +105,14 @@ open class TextLinkCaret: ButtonBase {
if iconPosition == .right { if iconPosition == .right {
return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize
} else { } else {
let width = imageSize.width + 4.0 + (titleLabel?.intrinsicContentSize.width ?? super.intrinsicContentSize.width) let width = imageSize.width + spacing + (titleLabel?.intrinsicContentSize.width ?? super.intrinsicContentSize.width)
let height = titleLabel?.intrinsicContentSize.height ?? super.intrinsicContentSize.height let height = titleLabel?.intrinsicContentSize.height ?? super.intrinsicContentSize.height
return .init(width: width, height: height) return .init(width: width, height: height)
} }
} }
private let imageSize = Icon.Size.xsmall.dimensions private let imageSize = Icon.Size.xsmall.dimensions
private let spacing = 4.0 private let spacing = 4.0
// private var activeConstraints: [NSLayoutConstraint] = [] // private var activeConstraints: [NSLayoutConstraint] = []
// //
// private func setupConstraints() { // private func setupConstraints() {
@ -159,21 +155,26 @@ open class TextLinkCaret: ButtonBase {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
imageView?.frame.size = imageSize
guard let imageView, let titleLabel else { return } imageView?.frame.origin = .init(x: 0, y: spacing)
if imageView.isHidden {
titleLabel.frame.origin.x = 0
contentEdgeInsets = .zero
} else {
imageView.frame.origin.x = 0
titleLabel.frame.origin.x = imageSize.width + spacing
let totalWidth = titleLabel.frame.maxX
let leftInset = (bounds.width - totalWidth) / 2
contentEdgeInsets = .init(top: 0, left: leftInset, bottom: 0, right: leftInset)
}
} }
// open override func layoutSubviews() {
// super.layoutSubviews()
//
// guard let imageView, let titleLabel else { return }
//
// if imageView.isHidden {
// titleLabel.frame.origin.x = 0
// contentEdgeInsets = .zero
// } else {
// imageView.frame.origin.x = 0
// titleLabel.frame.origin.x = imageSize.width + spacing
//
// let totalWidth = titleLabel.frame.maxX
// let leftInset = (bounds.width - totalWidth) / 2
// contentEdgeInsets = .init(top: 0, left: leftInset, bottom: 0, right: leftInset)
// }
// }
} }