updated to work at 100% width of parent if not set as well as calculating height if there is an aspect ration.
This commit is contained in:
parent
16c2360324
commit
842bb6f0ad
@ -117,10 +117,6 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
||||
$0.setContentCompressionResistancePriority(.defaultHigh, for: .vertical)
|
||||
}
|
||||
|
||||
open var distribution: LayoutDistribution = .fill { didSet { setNeedsUpdate() } }
|
||||
|
||||
open var alignment: LayoutAlignment = .center { didSet { setNeedsUpdate() } }
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
@ -136,7 +132,7 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
||||
}
|
||||
|
||||
/// This controls the aspect ratio for the component.
|
||||
open var aspectRatio: AspectRatio = .none { didSet { setNeedsUpdate() } }
|
||||
open var aspectRatio: AspectRatio = .ratio1x1 { didSet { setNeedsUpdate() } }
|
||||
|
||||
/// Sets the background color for the component.
|
||||
open var color: BackgroundColor? { didSet { setNeedsUpdate() } }
|
||||
@ -190,11 +186,6 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
||||
internal var widthConstraint: NSLayoutConstraint?
|
||||
internal var heightConstraint: NSLayoutConstraint?
|
||||
|
||||
internal var contentViewTopConstraint: NSLayoutConstraint?
|
||||
internal var contentViewBottomConstraint: NSLayoutConstraint?
|
||||
internal var contentViewLeadingConstraint: NSLayoutConstraint?
|
||||
internal var contentViewTrailingConstraint: NSLayoutConstraint?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Configuration
|
||||
//--------------------------------------------------
|
||||
@ -231,15 +222,21 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
||||
open override func setup() {
|
||||
super.setup()
|
||||
isAccessibilityElement = false
|
||||
|
||||
addSubview(containerView)
|
||||
containerView.pinToSuperView()
|
||||
|
||||
containerView.addSubview(backgroundImageView)
|
||||
containerView.addSubview(contentView)
|
||||
containerView.addSubview(highlightView)
|
||||
|
||||
backgroundImageView.pinToSuperView()
|
||||
|
||||
widthConstraint = containerView.widthAnchor.constraint(equalToConstant: 0).deactivate()
|
||||
heightConstraint = containerView.heightAnchor.constraint(equalToConstant: 0).deactivate()
|
||||
containerView.addSubview(contentView)
|
||||
contentView.pinToSuperView()
|
||||
|
||||
containerView.addSubview(highlightView)
|
||||
highlightView.pinToSuperView()
|
||||
|
||||
widthConstraint = widthAnchor.constraint(equalToConstant: 0).deactivate()
|
||||
heightConstraint = heightAnchor.constraint(equalToConstant: 0).deactivate()
|
||||
|
||||
backgroundImageView.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
||||
backgroundImageView.setContentHuggingPriority(.defaultLow, for: .vertical)
|
||||
@ -248,19 +245,11 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
||||
backgroundImageView.isUserInteractionEnabled = false
|
||||
backgroundImageView.isHidden = true
|
||||
|
||||
contentViewTopConstraint = contentView.pinTop(anchor: containerView.topAnchor, constant: padding.value)
|
||||
contentViewBottomConstraint = containerView.pinBottom(anchor: contentView.bottomAnchor, constant: padding.value)
|
||||
contentViewLeadingConstraint = contentView.pinLeading(anchor: containerView.leadingAnchor, constant: padding.value)
|
||||
contentViewTrailingConstraint = containerView.pinTrailing(anchor: contentView.trailingAnchor, constant: padding.value)
|
||||
|
||||
highlightView.pin(containerView)
|
||||
highlightView.isHidden = true
|
||||
highlightView.backgroundColor = .clear
|
||||
|
||||
//corner radius
|
||||
containerView.layer.cornerRadius = cornerRadius
|
||||
backgroundImageView.layer.cornerRadius = cornerRadius
|
||||
highlightView.layer.cornerRadius = cornerRadius
|
||||
containerView.clipsToBounds = true
|
||||
|
||||
containerView.bridge_isAccessibilityElementBlock = { [weak self] in self?.onClickSubscriber != nil }
|
||||
@ -311,11 +300,9 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
||||
containerView.layer.borderColor = borderColorConfiguration.getColor(self).cgColor
|
||||
containerView.layer.borderWidth = showBorder ? VDSFormControls.borderWidth : 0
|
||||
|
||||
contentViewTopConstraint?.constant = padding.value
|
||||
contentViewLeadingConstraint?.constant = padding.value
|
||||
contentViewBottomConstraint?.constant = padding.value
|
||||
contentViewTrailingConstraint?.constant = padding.value
|
||||
|
||||
contentView.removeConstraints()
|
||||
contentView.pinToSuperView(.uniform(padding.value))
|
||||
|
||||
updateContainerView()
|
||||
}
|
||||
|
||||
@ -472,14 +459,22 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
||||
containerViewWidth = size.width
|
||||
containerViewHeight = size.height
|
||||
}
|
||||
|
||||
sizeContainerView(width: containerViewWidth, height: containerViewHeight)
|
||||
containerView.applyAlignment(alignment)
|
||||
|
||||
} else {
|
||||
containerView.applyAlignment(distribution == .fill ? .fill : alignment)
|
||||
if distribution == .fill, !isPinnedHorizontallyToSuperview(), let size = horizontalPinnedSize() {
|
||||
sizeContainerView(width: size.width)
|
||||
if let parentSize = horizontalPinnedSize() {
|
||||
|
||||
var containerViewWidth: CGFloat?
|
||||
var containerViewHeight: CGFloat?
|
||||
|
||||
let size = ratioSize(for: parentSize.width)
|
||||
if aspectRatio == .none {
|
||||
containerViewWidth = size.width
|
||||
} else {
|
||||
containerViewWidth = size.width
|
||||
containerViewHeight = size.height
|
||||
}
|
||||
|
||||
sizeContainerView(width: containerViewWidth, height: containerViewHeight)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -303,6 +303,8 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
|
||||
open override func setup() {
|
||||
super.setup()
|
||||
color = .black
|
||||
aspectRatio = .none
|
||||
|
||||
addContentView(stackView)
|
||||
|
||||
//badge
|
||||
@ -385,6 +387,8 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
|
||||
/// Resets to default settings.
|
||||
open override func reset() {
|
||||
shouldUpdateView = false
|
||||
super.reset()
|
||||
aspectRatio = .none
|
||||
color = .black
|
||||
//models
|
||||
badgeModel = nil
|
||||
|
||||
Loading…
Reference in New Issue
Block a user