updated width

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-01-11 16:19:07 -06:00
parent 4e49a55d7d
commit e72c751842
2 changed files with 18 additions and 14 deletions

View File

@ -76,14 +76,14 @@ open class TileContainer: Control {
public var imageFallbackColor: Surface = .light { didSet{ didChange() } } public var imageFallbackColor: Surface = .light { didSet{ didChange() } }
private var _width: CGFloat = 100 private var _width: CGFloat?
public var width: CGFloat { public var width: CGFloat? {
get { return _width } get { return _width }
set { set {
if newValue > 100 { if let newValue, newValue > 100 {
_width = newValue _width = newValue
} else { } else {
_width = 100 _width = nil
} }
didChange() didChange()
} }
@ -152,14 +152,12 @@ open class TileContainer: Control {
addSubview(containerView) addSubview(containerView)
addSubview(highlightView) addSubview(highlightView)
widthConstraint = widthAnchor.constraint(equalToConstant: width) widthConstraint = widthAnchor.constraint(equalToConstant: 0)
widthConstraint?.isActive = true
heightGreaterThanConstraint = heightAnchor.constraint(greaterThanOrEqualToConstant: 44.0) heightGreaterThanConstraint = heightAnchor.constraint(greaterThanOrEqualToConstant: 44.0)
heightGreaterThanConstraint?.isActive = false heightGreaterThanConstraint?.isActive = false
heightConstraint = heightAnchor.constraint(equalToConstant: width) heightConstraint = heightAnchor.constraint(equalToConstant: 0)
heightConstraint?.isActive = true
backgroundImageView.pinToSuperView() backgroundImageView.pinToSuperView()
backgroundImageView.isUserInteractionEnabled = false backgroundImageView.isUserInteractionEnabled = false
@ -219,7 +217,7 @@ open class TileContainer: Control {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - State // MARK: - State
//-------------------------------------------------- //--------------------------------------------------
var ratioSize: CGSize { private func ratioSize(for width: CGFloat) -> CGSize {
var height: CGFloat = width var height: CGFloat = width
switch aspectRatio { switch aspectRatio {
@ -272,21 +270,27 @@ open class TileContainer: Control {
containerBottomConstraint?.constant = -padding containerBottomConstraint?.constant = -padding
containerTrailingConstraint?.constant = -padding containerTrailingConstraint?.constant = -padding
if aspectRatio == .none && height == nil{ if let width, aspectRatio == .none && height == nil{
widthConstraint?.constant = width widthConstraint?.constant = width
widthConstraint?.isActive = true
heightConstraint?.isActive = false heightConstraint?.isActive = false
heightGreaterThanConstraint?.isActive = true heightGreaterThanConstraint?.isActive = true
} else if let height { } else if let height, let width {
widthConstraint?.constant = width widthConstraint?.constant = width
heightConstraint?.constant = height heightConstraint?.constant = height
heightConstraint?.isActive = true heightConstraint?.isActive = true
widthConstraint?.isActive = true
heightGreaterThanConstraint?.isActive = false heightGreaterThanConstraint?.isActive = false
} else { } else if let width {
let size = ratioSize let size = ratioSize(for: width)
widthConstraint?.constant = size.width widthConstraint?.constant = size.width
heightConstraint?.constant = size.height heightConstraint?.constant = size.height
widthConstraint?.isActive = true
heightConstraint?.isActive = true heightConstraint?.isActive = true
heightGreaterThanConstraint?.isActive = false heightGreaterThanConstraint?.isActive = false
} else {
widthConstraint?.isActive = false
heightConstraint?.isActive = false
} }
} }

View File

@ -137,7 +137,7 @@ open class Tilet: TileContainer {
open var textWidth: CGFloat? { open var textWidth: CGFloat? {
get { _textWidth } get { _textWidth }
set { set {
if let newValue, newValue > 44.0 && newValue <= width { if let newValue, newValue > 44.0 {
_textWidth = newValue _textWidth = newValue
if _textPercentage != nil { if _textPercentage != nil {
_textPercentage = nil _textPercentage = nil