From c2c2bfeb4a1f61fbc5f2d88aeb1c6e94cd7ada2b Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 31 Jan 2024 10:05:36 -0600 Subject: [PATCH] more changes Signed-off-by: Matt Bruce --- .../Buttons/TextLinkCaret/TextLinkCaret.swift | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index b304a99a..fe7a0401 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -51,7 +51,9 @@ open class TextLinkCaret: ButtonBase { $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 @@ -81,19 +83,12 @@ open class TextLinkCaret: ButtonBase { super.setup() accessibilityTraits = .link 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. open override func updateView() { - if iconPosition == .right { - imageAttribute = CaretLabelAttribute(tintColor: textColor, position: iconPosition) - } else { - imageAttribute = nil - } - imageView?.isHidden = iconPosition == .right + setImage(iconPosition == .right ? nil : BundleManager.shared.image(for: Icon.Name.leftCaretBold.rawValue), for: .normal) + imageEdgeInsets = iconPosition == .right ? .zero : .init(top: 0, left: -spacing, bottom: 0, right: 0) super.updateView() } @@ -110,13 +105,14 @@ open class TextLinkCaret: ButtonBase { if iconPosition == .right { return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize } 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 return .init(width: width, height: height) } } private let imageSize = Icon.Size.xsmall.dimensions private let spacing = 4.0 + // private var activeConstraints: [NSLayoutConstraint] = [] // // private func setupConstraints() { @@ -159,21 +155,26 @@ open class TextLinkCaret: ButtonBase { 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) - } + imageView?.frame.size = imageSize + imageView?.frame.origin = .init(x: 0, y: spacing) } +// 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) +// } +// } }