diff --git a/VDS/Components/TileContainer/TileContainer.swift b/VDS/Components/TileContainer/TileContainer.swift index 40efde6d..154bc95c 100644 --- a/VDS/Components/TileContainer/TileContainer.swift +++ b/VDS/Components/TileContainer/TileContainer.swift @@ -76,14 +76,14 @@ open class TileContainer: Control { public var imageFallbackColor: Surface = .light { didSet{ didChange() } } - private var _width: CGFloat = 100 - public var width: CGFloat { + private var _width: CGFloat? + public var width: CGFloat? { get { return _width } set { - if newValue > 100 { + if let newValue, newValue > 100 { _width = newValue } else { - _width = 100 + _width = nil } didChange() } @@ -152,14 +152,12 @@ open class TileContainer: Control { addSubview(containerView) addSubview(highlightView) - widthConstraint = widthAnchor.constraint(equalToConstant: width) - widthConstraint?.isActive = true + widthConstraint = widthAnchor.constraint(equalToConstant: 0) heightGreaterThanConstraint = heightAnchor.constraint(greaterThanOrEqualToConstant: 44.0) heightGreaterThanConstraint?.isActive = false - heightConstraint = heightAnchor.constraint(equalToConstant: width) - heightConstraint?.isActive = true + heightConstraint = heightAnchor.constraint(equalToConstant: 0) backgroundImageView.pinToSuperView() backgroundImageView.isUserInteractionEnabled = false @@ -219,7 +217,7 @@ open class TileContainer: Control { //-------------------------------------------------- // MARK: - State //-------------------------------------------------- - var ratioSize: CGSize { + private func ratioSize(for width: CGFloat) -> CGSize { var height: CGFloat = width switch aspectRatio { @@ -272,21 +270,27 @@ open class TileContainer: Control { containerBottomConstraint?.constant = -padding containerTrailingConstraint?.constant = -padding - if aspectRatio == .none && height == nil{ + if let width, aspectRatio == .none && height == nil{ widthConstraint?.constant = width + widthConstraint?.isActive = true heightConstraint?.isActive = false heightGreaterThanConstraint?.isActive = true - } else if let height { + } else if let height, let width { widthConstraint?.constant = width heightConstraint?.constant = height heightConstraint?.isActive = true + widthConstraint?.isActive = true heightGreaterThanConstraint?.isActive = false - } else { - let size = ratioSize + } else if let width { + let size = ratioSize(for: width) widthConstraint?.constant = size.width heightConstraint?.constant = size.height + widthConstraint?.isActive = true heightConstraint?.isActive = true heightGreaterThanConstraint?.isActive = false + } else { + widthConstraint?.isActive = false + heightConstraint?.isActive = false } } diff --git a/VDS/Components/Tilet/Tilet.swift b/VDS/Components/Tilet/Tilet.swift index 0e6c954c..f395c04d 100644 --- a/VDS/Components/Tilet/Tilet.swift +++ b/VDS/Components/Tilet/Tilet.swift @@ -137,7 +137,7 @@ open class Tilet: TileContainer { open var textWidth: CGFloat? { get { _textWidth } set { - if let newValue, newValue > 44.0 && newValue <= width { + if let newValue, newValue > 44.0 { _textWidth = newValue if _textPercentage != nil { _textPercentage = nil