went to intrinsic size
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
6f7fb965e5
commit
c9f6caa680
@ -16,9 +16,6 @@ open class Icon: View {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private var widthConstraint: NSLayoutConstraint?
|
|
||||||
private var heightConstraint: NSLayoutConstraint?
|
|
||||||
|
|
||||||
private var dimensions: CGSize {
|
private var dimensions: CGSize {
|
||||||
guard let customSize else { return size.dimensions }
|
guard let customSize else { return size.dimensions }
|
||||||
return .init(width: customSize, height: customSize)
|
return .init(width: customSize, height: customSize)
|
||||||
@ -29,10 +26,6 @@ open class Icon: View {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
open var imageView = UIImageView().with {
|
open var imageView = UIImageView().with {
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$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.contentMode = .scaleAspectFill
|
||||||
$0.clipsToBounds = true
|
$0.clipsToBounds = true
|
||||||
}
|
}
|
||||||
@ -57,14 +50,14 @@ open class Icon: View {
|
|||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
|
|
||||||
|
setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
setContentHuggingPriority(.required, for: .vertical)
|
||||||
|
setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||||
|
setContentHuggingPriority(.required, for: .horizontal)
|
||||||
|
|
||||||
addSubview(imageView)
|
addSubview(imageView)
|
||||||
imageView.pinToSuperView()
|
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
|
backgroundColor = .clear
|
||||||
|
|
||||||
isAccessibilityElement = true
|
isAccessibilityElement = true
|
||||||
@ -77,6 +70,10 @@ open class Icon: View {
|
|||||||
color = VDSColor.paletteBlack
|
color = VDSColor.paletteBlack
|
||||||
imageView.image = nil
|
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.
|
/// Function used to make changes to the View based off a change events or from local properties.
|
||||||
open override func updateView() {
|
open override func updateView() {
|
||||||
@ -90,11 +87,7 @@ open class Icon: View {
|
|||||||
} else if surface == .light && color == VDSColor.paletteBlack {
|
} else if surface == .light && color == VDSColor.paletteBlack {
|
||||||
imageColor = VDSColor.elementsPrimaryOnlight
|
imageColor = VDSColor.elementsPrimaryOnlight
|
||||||
}
|
}
|
||||||
|
|
||||||
//set the icon dimensions
|
|
||||||
heightConstraint?.constant = dimensions.height
|
|
||||||
widthConstraint?.constant = dimensions.width
|
|
||||||
|
|
||||||
//get the image name
|
//get the image name
|
||||||
//set the image
|
//set the image
|
||||||
if let name, let image = getImage(for: name.rawValue) {
|
if let name, let image = getImage(for: name.rawValue) {
|
||||||
@ -102,7 +95,8 @@ open class Icon: View {
|
|||||||
} else {
|
} else {
|
||||||
imageView.image = nil
|
imageView.image = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
invalidateIntrinsicContentSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getImage(for imageName: String) -> UIImage? {
|
private func getImage(for imageName: String) -> UIImage? {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user