refactored to remove height now the a hit area exists

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-12-15 11:47:08 -06:00
parent 1e44d9738d
commit 81f7341148
2 changed files with 9 additions and 20 deletions

View File

@ -17,7 +17,6 @@ open class TextLink: ButtonBase {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties
//-------------------------------------------------- //--------------------------------------------------
private var heightConstraint: NSLayoutConstraint?
private var lineHeightConstraint: NSLayoutConstraint? private var lineHeightConstraint: NSLayoutConstraint?
//-------------------------------------------------- //--------------------------------------------------
@ -83,9 +82,6 @@ open class TextLink: ButtonBase {
lineHeightConstraint = line.heightAnchor.constraint(equalToConstant: 1.0) lineHeightConstraint = line.heightAnchor.constraint(equalToConstant: 1.0)
lineHeightConstraint?.isActive = true lineHeightConstraint?.isActive = true
} }
heightConstraint = heightAnchor.constraint(equalToConstant: height)
heightConstraint?.isActive = true
} }
open override func reset() { open override func reset() {
@ -99,18 +95,15 @@ open class TextLink: ButtonBase {
// MARK: - Overrides // MARK: - Overrides
//-------------------------------------------------- //--------------------------------------------------
open override var intrinsicContentSize: CGSize { open override var intrinsicContentSize: CGSize {
let size = titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize
return CGSize(width: size.width, height: height)
} }
open override func updateView() { open override func updateView() {
//need to set the properties so the super class //need to set the properties so the super class
//can render out the label correctly //can render out the label correctly
heightConstraint?.constant = height
line.backgroundColor = textColor line.backgroundColor = textColor
//always call last so the label is rendered //always call last so the label is rendered
super.updateView() super.updateView()
} }
} }

View File

@ -21,12 +21,10 @@ open class TextLinkCaret: ButtonBase {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties
//-------------------------------------------------- //--------------------------------------------------
private var heightConstraint: NSLayoutConstraint?
open override var typograpicalStyle: TypographicalStyle { open override var typograpicalStyle: TypographicalStyle {
TypographicalStyle.BoldBodyLarge TypographicalStyle.BoldBodyLarge
} }
private var caretView = CaretView().with { private var caretView = CaretView().with {
$0.size = CaretView.CaretSize.small(.vertical) $0.size = CaretView.CaretSize.small(.vertical)
$0.lineWidth = 2 $0.lineWidth = 2
@ -64,7 +62,7 @@ open class TextLinkCaret: ButtonBase {
open override var textColor: UIColor { open override var textColor: UIColor {
textColorConfiguration.getColor(self) textColorConfiguration.getColor(self)
} }
private var textColorConfiguration = ControlColorConfiguration().with { private var textColorConfiguration = ControlColorConfiguration().with {
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal) $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal)
$0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forState: .disabled) $0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forState: .disabled)
@ -91,9 +89,7 @@ open class TextLinkCaret: ButtonBase {
//-------------------------------------------------- //--------------------------------------------------
open override func setup() { open override func setup() {
super.setup() super.setup()
//constraints
heightAnchor.constraint(greaterThanOrEqualToConstant: height).isActive = true
let size = caretView.size!.dimensions() let size = caretView.size!.dimensions()
caretView.frame = .init(x: 0, y: 0, width: size.width, height: size.height) caretView.frame = .init(x: 0, y: 0, width: size.width, height: size.height)
} }
@ -115,9 +111,9 @@ open class TextLinkCaret: ButtonBase {
if let caretWidth = caretView.size?.dimensions().width { if let caretWidth = caretView.size?.dimensions().width {
itemWidth += caretWidth itemWidth += caretWidth
} }
return CGSize(width: itemWidth, height: height) return CGSize(width: itemWidth, height: size.height)
} }
open override func updateView() { open override func updateView() {
let updatedText = text ?? "" let updatedText = text ?? ""
@ -129,9 +125,9 @@ open class TextLinkCaret: ButtonBase {
let location = iconPosition == .right ? updatedText.count : 0 let location = iconPosition == .right ? updatedText.count : 0
imageAttribute = ImageLabelAttribute(location: location, imageAttribute = ImageLabelAttribute(location: location,
image: image, image: image,
tintColor: textColor) tintColor: textColor)
super.updateView() super.updateView()
} }