diff --git a/VDS/Components/Buttons/ButtonBase.swift b/VDS/Components/Buttons/ButtonBase.swift index e8a379d9..46f72c55 100644 --- a/VDS/Components/Buttons/ButtonBase.swift +++ b/VDS/Components/Buttons/ButtonBase.swift @@ -146,7 +146,8 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable { // MARK: - Private Methods //-------------------------------------------------- private func updateLabel() { - + defer { invalidateIntrinsicContentSize() } + //clear the arrays holding actions accessibilityCustomActions = [] if let text, !text.isEmpty { diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index f476f40b..addbdaad 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -48,6 +48,9 @@ open class TextLinkCaret: ButtonBase { //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- + // Property to specify the icon size + private var imageSize: CGSize = Icon.Size.xsmall.dimensions + private var textColorConfiguration = ControlColorConfiguration().with { $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal) $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled) @@ -97,19 +100,26 @@ open class TextLinkCaret: ButtonBase { iconPosition = .right text = nil } - - /// The natural size for the receiving view, considering only properties of the view itself. - // Property to specify the icon size - private var imageSize: CGSize = Icon.Size.xsmall.dimensions - + + /// Retuns the correct CGSize since this could contain a Multiline Label. + open override var intrinsicContentSize: CGSize { + 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() { super.layoutSubviews() guard let titleLabel = titleLabel, let imageView = imageView else { return } // Adjust imageView size based on the imageSize property imageView.frame.size = imageSize - - let space: CGFloat = 5 // Space between the icon and the text + titleLabel.preferredMaxLayoutWidth = self.frame.width - (contentEdgeInsets.left + contentEdgeInsets.right + imageSize.width) + + let space: CGFloat = VDSLayout.Spacing.space1X.value // Space between the icon and the text // Adjust icon and text positions based on the iconPosition switch iconPosition { @@ -143,10 +153,7 @@ open class TextLinkCaret: ButtonBase { } imageView.contentMode = .scaleAspectFit - } - - private var space: CGFloat { - return 5 // Space between the icon and text, used in multiple places + } }