From c9f6caa680eba24d5693cd9bb3e030b43d258d56 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 21 Aug 2023 13:54:36 -0500 Subject: [PATCH] went to intrinsic size Signed-off-by: Matt Bruce --- VDS/Components/Icon/Icon.swift | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/VDS/Components/Icon/Icon.swift b/VDS/Components/Icon/Icon.swift index 68ba7f97..58a515db 100644 --- a/VDS/Components/Icon/Icon.swift +++ b/VDS/Components/Icon/Icon.swift @@ -16,9 +16,6 @@ open class Icon: View { //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- - private var widthConstraint: NSLayoutConstraint? - private var heightConstraint: NSLayoutConstraint? - private var dimensions: CGSize { guard let customSize else { return size.dimensions } return .init(width: customSize, height: customSize) @@ -29,10 +26,6 @@ open class Icon: View { //-------------------------------------------------- open var imageView = UIImageView().with { $0.translatesAutoresizingMaskIntoConstraints = false - $0.setContentCompressionResistancePriority(.required, for: .vertical) - $0.setContentHuggingPriority(.required, for: .vertical) - $0.setContentCompressionResistancePriority(.required, for: .horizontal) - $0.setContentHuggingPriority(.required, for: .horizontal) $0.contentMode = .scaleAspectFill $0.clipsToBounds = true } @@ -57,14 +50,14 @@ open class Icon: View { open override func setup() { super.setup() + setContentCompressionResistancePriority(.required, for: .vertical) + setContentHuggingPriority(.required, for: .vertical) + setContentCompressionResistancePriority(.required, for: .horizontal) + setContentHuggingPriority(.required, for: .horizontal) + addSubview(imageView) imageView.pinToSuperView() - heightConstraint = imageView.heightAnchor.constraint(equalToConstant: size.dimensions.height) - heightConstraint?.isActive = true - widthConstraint = imageView.widthAnchor.constraint(equalToConstant: size.dimensions.width) - widthConstraint?.isActive = true - backgroundColor = .clear isAccessibilityElement = true @@ -77,6 +70,10 @@ open class Icon: View { color = VDSColor.paletteBlack imageView.image = nil } + + open override var intrinsicContentSize: CGSize { + dimensions + } /// Function used to make changes to the View based off a change events or from local properties. open override func updateView() { @@ -90,11 +87,7 @@ open class Icon: View { } else if surface == .light && color == VDSColor.paletteBlack { imageColor = VDSColor.elementsPrimaryOnlight } - - //set the icon dimensions - heightConstraint?.constant = dimensions.height - widthConstraint?.constant = dimensions.width - + //get the image name //set the image if let name, let image = getImage(for: name.rawValue) { @@ -102,7 +95,8 @@ open class Icon: View { } else { imageView.image = nil } - + + invalidateIntrinsicContentSize() } private func getImage(for imageName: String) -> UIImage? {