Merge branch 'develop' into refactor/textLinkCaret-images

Refactored to fix the issue with the contentSize of the Label

# Conflicts:
#	VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift


Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-03-19 09:49:42 -05:00
commit 9676e3b4d0
2 changed files with 20 additions and 12 deletions

View File

@ -146,7 +146,8 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable {
// 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 = []
if let text, !text.isEmpty { if let text, !text.isEmpty {

View File

@ -48,6 +48,9 @@ open class TextLinkCaret: ButtonBase {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties
//-------------------------------------------------- //--------------------------------------------------
// Property to specify the icon size
private var imageSize: CGSize = Icon.Size.xsmall.dimensions
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.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled) $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled)
@ -97,19 +100,26 @@ open class TextLinkCaret: ButtonBase {
iconPosition = .right iconPosition = .right
text = nil text = nil
} }
/// The natural size for the receiving view, considering only properties of the view itself. /// Retuns the correct CGSize since this could contain a Multiline Label.
// Property to specify the icon size open override var intrinsicContentSize: CGSize {
private var imageSize: CGSize = Icon.Size.xsmall.dimensions let labelSize = titleLabel?.sizeThatFits(CGSize(width: self.frame.width - (contentEdgeInsets.left + contentEdgeInsets.right + imageSize.width), height: CGFloat.greatestFiniteMagnitude)) ?? .zero
let contentWidth = labelSize.width + contentEdgeInsets.left + contentEdgeInsets.right + imageSize.width
let contentHeight = max(labelSize.height, imageSize.height) + contentEdgeInsets.top + contentEdgeInsets.bottom
return CGSize(width: contentWidth, height: contentHeight)
}
/// Layouts the correct positioning of the Caret Image within ``TextLinkCaret`` based of the `iconPosition`.
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
guard let titleLabel = titleLabel, let imageView = imageView else { return } guard let titleLabel = titleLabel, let imageView = imageView else { return }
// Adjust imageView size based on the imageSize property // Adjust imageView size based on the imageSize property
imageView.frame.size = imageSize imageView.frame.size = imageSize
titleLabel.preferredMaxLayoutWidth = self.frame.width - (contentEdgeInsets.left + contentEdgeInsets.right + imageSize.width)
let space: CGFloat = 5 // Space between the icon and the text
let space: CGFloat = VDSLayout.Spacing.space1X.value // Space between the icon and the text
// Adjust icon and text positions based on the iconPosition // Adjust icon and text positions based on the iconPosition
switch iconPosition { switch iconPosition {
@ -143,10 +153,7 @@ open class TextLinkCaret: ButtonBase {
} }
imageView.contentMode = .scaleAspectFit imageView.contentMode = .scaleAspectFit
}
private var space: CGFloat {
return 5 // Space between the icon and text, used in multiple places
} }
} }