From 1fa8f485f8a92e5dc9ba8bf8e8eb5fb52ce092d2 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 11 Mar 2024 15:43:55 -0500 Subject: [PATCH 1/7] updated constraint to defaultHigh Signed-off-by: Matt Bruce --- VDS/Classes/SelfSizingCollectionView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VDS/Classes/SelfSizingCollectionView.swift b/VDS/Classes/SelfSizingCollectionView.swift index 6f4de7d0..ad5d5661 100644 --- a/VDS/Classes/SelfSizingCollectionView.swift +++ b/VDS/Classes/SelfSizingCollectionView.swift @@ -73,7 +73,7 @@ public final class SelfSizingCollectionView: UICollectionView { //ensure autoLayout uses intrinsic height setContentHuggingPriority(.required, for: .vertical) setContentCompressionResistancePriority(.required, for: .vertical) - collectionViewHeight = heightAnchor.constraint(equalToConstant: 0).activate() + collectionViewHeight = height(constant: 0, priority: .defaultHigh) anyCancellable = self.publisher(for: \.contentSize, options: [.new]) .sink { [weak self] compare in From 42dccb47805276eb88f37431f139143ca9ee0e5d Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 12 Mar 2024 09:55:02 -0500 Subject: [PATCH 2/7] add image helper Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 4 ++++ VDS/Extensions/UIImage+Helper.swift | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 VDS/Extensions/UIImage+Helper.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index b6a3d192..63549b92 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -132,6 +132,7 @@ EAD068922A560B65002E3A2D /* LoaderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD068912A560B65002E3A2D /* LoaderViewController.swift */; }; EAD068942A560C13002E3A2D /* LoaderLaunchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD068932A560C13002E3A2D /* LoaderLaunchable.swift */; }; EAD8D2C128BFDE8B006EB6A6 /* UIGestureRecognizer+Publisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD8D2C028BFDE8B006EB6A6 /* UIGestureRecognizer+Publisher.swift */; }; + EAE785312BA0A438009428EA /* UIImage+Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAE785302BA0A438009428EA /* UIImage+Helper.swift */; }; EAEEEC922B1F807300531FC2 /* BadgeChangeLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = EAEEEC912B1F807300531FC2 /* BadgeChangeLog.txt */; }; EAEEEC962B1F893B00531FC2 /* ButtonChangeLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = EAEEEC952B1F893B00531FC2 /* ButtonChangeLog.txt */; }; EAEEEC982B1F8DD100531FC2 /* LineChangeLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = EAEEEC972B1F8DD100531FC2 /* LineChangeLog.txt */; }; @@ -303,6 +304,7 @@ EAD068912A560B65002E3A2D /* LoaderViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoaderViewController.swift; sourceTree = ""; }; EAD068932A560C13002E3A2D /* LoaderLaunchable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoaderLaunchable.swift; sourceTree = ""; }; EAD8D2C028BFDE8B006EB6A6 /* UIGestureRecognizer+Publisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIGestureRecognizer+Publisher.swift"; sourceTree = ""; }; + EAE785302BA0A438009428EA /* UIImage+Helper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Helper.swift"; sourceTree = ""; }; EAEEEC912B1F807300531FC2 /* BadgeChangeLog.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = BadgeChangeLog.txt; sourceTree = ""; }; EAEEEC952B1F893B00531FC2 /* ButtonChangeLog.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = ButtonChangeLog.txt; sourceTree = ""; }; EAEEEC972B1F8DD100531FC2 /* LineChangeLog.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = LineChangeLog.txt; sourceTree = ""; }; @@ -536,6 +538,7 @@ EA81410F2A127066004F60D2 /* UIColor+VDSColor.swift */, EA33623D2892EE950071C351 /* UIDevice.swift */, EA0B18092AA78F9000F2D0CD /* UIEdgeInsets.swift */, + EAE785302BA0A438009428EA /* UIImage+Helper.swift */, EAF7F0B6289C12A600B287F5 /* UITapGestureRecognizer.swift */, EA8E40902A7D3F6300934ED3 /* UIView+Accessibility.swift */, EAB5FED329267EB300998C17 /* UIView+NSLayoutConstraint.swift */, @@ -1025,6 +1028,7 @@ EAF7F0AF289B144C00B287F5 /* UnderlineLabelAttribute.swift in Sources */, EA0D1C412A6AD61C00E5C127 /* Typography+Additional.swift in Sources */, EAC925842911C63100091998 /* Colorable.swift in Sources */, + EAE785312BA0A438009428EA /* UIImage+Helper.swift in Sources */, EAB5FEF5292D371F00998C17 /* ButtonBase.swift in Sources */, EA978EC5291D6AFE00ACC883 /* AnyLabelAttribute.swift in Sources */, EAC71A1F2A2E173D00E47A9F /* RadioButton.swift in Sources */, diff --git a/VDS/Extensions/UIImage+Helper.swift b/VDS/Extensions/UIImage+Helper.swift new file mode 100644 index 00000000..c8f103dc --- /dev/null +++ b/VDS/Extensions/UIImage+Helper.swift @@ -0,0 +1,26 @@ +// +// UIImage+Icon.swift +// VDS +// +// Created by Matt Bruce on 3/11/24. +// + +import Foundation +import UIKit + +extension UIImage { + + /// UIImage helper for finding images based on the Icon.Name which uses the internal BundleManager. + /// - Parameters: + /// - name: RawRepresentable. + /// - color: Color to Tint the image with + /// - renderingMode: UIImage Rendering mode. + /// - Returns: UIImage for this proecess + public static func image(representing representable: T, color: UIColor? = nil, renderingMode: UIImage.RenderingMode = .alwaysOriginal) -> UIImage? where T.RawValue == String { + guard let image = BundleManager.shared.image(for: representable.rawValue) else { return nil } + + guard let color else { return image } + + return image.withTintColor(color, renderingMode: renderingMode) + } +} From 8369403cbe9737f6b679c089752d21ddddb80101 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 12 Mar 2024 09:57:42 -0500 Subject: [PATCH 3/7] refactored for the iconName image helper Signed-off-by: Matt Bruce --- VDS/Components/Icon/Icon.swift | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/VDS/Components/Icon/Icon.swift b/VDS/Components/Icon/Icon.swift index 5ac143f6..f52279f1 100644 --- a/VDS/Components/Icon/Icon.swift +++ b/VDS/Components/Icon/Icon.swift @@ -44,7 +44,7 @@ open class Icon: View { //-------------------------------------------------- /// UIImageView used to render the icon. open var imageView = UIImageView().with { - $0.isAccessibilityElement = false + $0.isAccessibilityElement = false $0.translatesAutoresizingMaskIntoConstraints = false $0.contentMode = .scaleAspectFill $0.clipsToBounds = true @@ -109,8 +109,8 @@ open class Icon: View { //get the image name //set the image - if let name, let image = getImage(for: name.rawValue) { - setImage(image: image, imageColor: imageColor) + if let name, let image = UIImage.image(for: name, color: imageColor) { + imageView.image = image } else { imageView.image = nil } @@ -129,17 +129,17 @@ open class Icon: View { super.updateAccessibility() accessibilityLabel = name?.rawValue ?? "icon" } - - //-------------------------------------------------- - // MARK: - Private Methods - //-------------------------------------------------- - private func getImage(for imageName: String) -> UIImage? { - - return BundleManager.shared.image(for: imageName) - } - - private func setImage(image: UIImage, imageColor: UIColor) { - imageView.image = image.withTintColor(imageColor) - } } +extension UIImage { + + /// UIImage helper for finding images based on the Icon.Name which uses the internal BundleManager. + /// - Parameters: + /// - name: Icon.Name rawRepresentable. + /// - color: Color to Tint the image with + /// - renderingMode: UIImage Rendering mode. + /// - Returns: UIImage for this proecess + public static func image(for iconName: Icon.Name, color: UIColor? = nil, renderingMode: UIImage.RenderingMode = .alwaysOriginal) -> UIImage? { + image(representing: iconName, color: color, renderingMode: renderingMode) + } +} From b4765bf0b4da433734205edc0b457550359598d2 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 13 Mar 2024 10:41:06 -0500 Subject: [PATCH 4/7] fixed bug for the Label Signed-off-by: Matt Bruce --- VDS/Components/Label/Label.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 60e88740..db9804d0 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -133,10 +133,12 @@ open class Label: UILabel, ViewProtocol, UserInfoable { open override var lineBreakMode: NSLineBreakMode { didSet { setNeedsUpdate() }} /// Text that will be used in the label. + private var _text: String! override open var text: String! { - get { super.text } + get { _text } set { textSetMode = .text + _text = newValue styleText(newValue) } } @@ -278,7 +280,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable { //-------------------------------------------------- private func restyleText() { if textSetMode == .text { - styleText(text) + styleText(_text) } else { styleAttributedText(attributedText) } @@ -304,10 +306,9 @@ open class Label: UILabel, ViewProtocol, UserInfoable { lineBreakMode: lineBreakMode) applyAttributes(mutableText) - + // Set attributed text to match typography super.attributedText = mutableText - } private func styleAttributedText(_ newValue: NSAttributedString?) { From 6290a4300404c9d7726dde2af2d4d4b8445931d3 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 18 Mar 2024 10:53:13 -0500 Subject: [PATCH 5/7] removed intrinsic size Signed-off-by: Matt Bruce --- VDS/Components/Buttons/ButtonBase.swift | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/VDS/Components/Buttons/ButtonBase.swift b/VDS/Components/Buttons/ButtonBase.swift index cc096d41..e8a379d9 100644 --- a/VDS/Components/Buttons/ButtonBase.swift +++ b/VDS/Components/Buttons/ButtonBase.swift @@ -141,17 +141,7 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable { shouldUpdateView = true setNeedsUpdate() } - - //-------------------------------------------------- - // MARK: - Overrides - //-------------------------------------------------- - override open var intrinsicContentSize: CGSize { - let intrinsicContentSize = super.intrinsicContentSize - let adjustedWidth = intrinsicContentSize.width + titleEdgeInsets.left + titleEdgeInsets.right - let adjustedHeight = intrinsicContentSize.height + titleEdgeInsets.top + titleEdgeInsets.bottom - return CGSize(width: adjustedWidth, height: adjustedHeight) - } - + //-------------------------------------------------- // MARK: - Private Methods //-------------------------------------------------- From 2e0d0be8b68786b9be98add64b9576be1771a139 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 18 Mar 2024 10:53:42 -0500 Subject: [PATCH 6/7] left aligned content for scenarios to where the container is stretched. Signed-off-by: Matt Bruce --- VDS/Components/Buttons/TextLink/TextLink.swift | 4 ++++ VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index dcb4a46d..1b1f79e8 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -87,6 +87,10 @@ open class TextLink: ButtonBase { isAccessibilityElement = true accessibilityTraits = .link + //left align titleLabel in case this is pinned leading/trailing + //default is always set to center + contentHorizontalAlignment = .left + if let titleLabel { addSubview(line) line.pinLeading(titleLabel.leadingAnchor) diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index aaa9f3cb..eb3776ea 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -79,6 +79,11 @@ open class TextLinkCaret: ButtonBase { /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. open override func setup() { super.setup() + + //left align titleLabel in case this is pinned leading/trailing + //default is always set to center + contentHorizontalAlignment = .left + accessibilityTraits = .link titleLabel?.numberOfLines = 0 titleLabel?.lineBreakMode = .byWordWrapping From 51562aa58900977d168ece15e20d5c9a3627cec6 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 18 Mar 2024 11:13:23 -0500 Subject: [PATCH 7/7] fixed issues for intrinsicSize Signed-off-by: Matt Bruce --- VDS/Components/Buttons/TextLink/TextLink.swift | 8 +++++++- .../Buttons/TextLinkCaret/TextLinkCaret.swift | 11 ++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index 1b1f79e8..51221b34 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -75,7 +75,13 @@ open class TextLink: ButtonBase { /// The natural size for the receiving view, considering only properties of the view itself. open override var intrinsicContentSize: CGSize { - return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize + guard let titleLabel else { return super.intrinsicContentSize } + // Calculate the titleLabel's intrinsic content size + let labelSize = titleLabel.sizeThatFits(CGSize(width: self.frame.width, height: CGFloat.greatestFiniteMagnitude)) + // Adjust the size if needed (add any additional padding if your design requires) + let adjustedSize = CGSize(width: labelSize.width + contentEdgeInsets.left + contentEdgeInsets.right, + height: labelSize.height + contentEdgeInsets.top + contentEdgeInsets.bottom) + return adjustedSize } //-------------------------------------------------- diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index eb3776ea..f02d2b10 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -103,9 +103,14 @@ open class TextLinkCaret: ButtonBase { } /// The natural size for the receiving view, considering only properties of the view itself. - override open var intrinsicContentSize: CGSize { - //get the labels size, if not the button - return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize + open override var intrinsicContentSize: CGSize { + guard let titleLabel else { return super.intrinsicContentSize } + // Calculate the titleLabel's intrinsic content size + let labelSize = titleLabel.sizeThatFits(CGSize(width: self.frame.width, height: CGFloat.greatestFiniteMagnitude)) + // Adjust the size if needed (add any additional padding if your design requires) + let adjustedSize = CGSize(width: labelSize.width + contentEdgeInsets.left + contentEdgeInsets.right, + height: labelSize.height + contentEdgeInsets.top + contentEdgeInsets.bottom) + return adjustedSize } }