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)
|
$0.setContentCompressionResistancePriority(.defaultHigh, for: .vertical)
|
||||||
}
|
}
|
||||||
|
|
||||||
open var distribution: LayoutDistribution = .fill { didSet { setNeedsUpdate() } }
|
|
||||||
|
|
||||||
open var alignment: LayoutAlignment = .center { didSet { setNeedsUpdate() } }
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Public Properties
|
// MARK: - Public Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -136,7 +132,7 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This controls the aspect ratio for the component.
|
/// 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.
|
/// Sets the background color for the component.
|
||||||
open var color: BackgroundColor? { didSet { setNeedsUpdate() } }
|
open var color: BackgroundColor? { didSet { setNeedsUpdate() } }
|
||||||
@ -190,11 +186,6 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
|||||||
internal var widthConstraint: NSLayoutConstraint?
|
internal var widthConstraint: NSLayoutConstraint?
|
||||||
internal var heightConstraint: NSLayoutConstraint?
|
internal var heightConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
internal var contentViewTopConstraint: NSLayoutConstraint?
|
|
||||||
internal var contentViewBottomConstraint: NSLayoutConstraint?
|
|
||||||
internal var contentViewLeadingConstraint: NSLayoutConstraint?
|
|
||||||
internal var contentViewTrailingConstraint: NSLayoutConstraint?
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Configuration
|
// MARK: - Configuration
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -231,15 +222,21 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
|||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
isAccessibilityElement = false
|
isAccessibilityElement = false
|
||||||
|
|
||||||
addSubview(containerView)
|
addSubview(containerView)
|
||||||
|
containerView.pinToSuperView()
|
||||||
|
|
||||||
containerView.addSubview(backgroundImageView)
|
containerView.addSubview(backgroundImageView)
|
||||||
containerView.addSubview(contentView)
|
|
||||||
containerView.addSubview(highlightView)
|
|
||||||
|
|
||||||
backgroundImageView.pinToSuperView()
|
backgroundImageView.pinToSuperView()
|
||||||
|
|
||||||
widthConstraint = containerView.widthAnchor.constraint(equalToConstant: 0).deactivate()
|
containerView.addSubview(contentView)
|
||||||
heightConstraint = containerView.heightAnchor.constraint(equalToConstant: 0).deactivate()
|
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: .horizontal)
|
||||||
backgroundImageView.setContentHuggingPriority(.defaultLow, for: .vertical)
|
backgroundImageView.setContentHuggingPriority(.defaultLow, for: .vertical)
|
||||||
@ -248,19 +245,11 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
|||||||
backgroundImageView.isUserInteractionEnabled = false
|
backgroundImageView.isUserInteractionEnabled = false
|
||||||
backgroundImageView.isHidden = true
|
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.isHidden = true
|
||||||
highlightView.backgroundColor = .clear
|
highlightView.backgroundColor = .clear
|
||||||
|
|
||||||
//corner radius
|
//corner radius
|
||||||
containerView.layer.cornerRadius = cornerRadius
|
containerView.layer.cornerRadius = cornerRadius
|
||||||
backgroundImageView.layer.cornerRadius = cornerRadius
|
|
||||||
highlightView.layer.cornerRadius = cornerRadius
|
|
||||||
containerView.clipsToBounds = true
|
containerView.clipsToBounds = true
|
||||||
|
|
||||||
containerView.bridge_isAccessibilityElementBlock = { [weak self] in self?.onClickSubscriber != nil }
|
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.borderColor = borderColorConfiguration.getColor(self).cgColor
|
||||||
containerView.layer.borderWidth = showBorder ? VDSFormControls.borderWidth : 0
|
containerView.layer.borderWidth = showBorder ? VDSFormControls.borderWidth : 0
|
||||||
|
|
||||||
contentViewTopConstraint?.constant = padding.value
|
contentView.removeConstraints()
|
||||||
contentViewLeadingConstraint?.constant = padding.value
|
contentView.pinToSuperView(.uniform(padding.value))
|
||||||
contentViewBottomConstraint?.constant = padding.value
|
|
||||||
contentViewTrailingConstraint?.constant = padding.value
|
|
||||||
|
|
||||||
updateContainerView()
|
updateContainerView()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,14 +459,22 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
|||||||
containerViewWidth = size.width
|
containerViewWidth = size.width
|
||||||
containerViewHeight = size.height
|
containerViewHeight = size.height
|
||||||
}
|
}
|
||||||
|
|
||||||
sizeContainerView(width: containerViewWidth, height: containerViewHeight)
|
sizeContainerView(width: containerViewWidth, height: containerViewHeight)
|
||||||
containerView.applyAlignment(alignment)
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
containerView.applyAlignment(distribution == .fill ? .fill : alignment)
|
if let parentSize = horizontalPinnedSize() {
|
||||||
if distribution == .fill, !isPinnedHorizontallyToSuperview(), let size = horizontalPinnedSize() {
|
|
||||||
sizeContainerView(width: size.width)
|
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() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
color = .black
|
color = .black
|
||||||
|
aspectRatio = .none
|
||||||
|
|
||||||
addContentView(stackView)
|
addContentView(stackView)
|
||||||
|
|
||||||
//badge
|
//badge
|
||||||
@ -385,6 +387,8 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
|
|||||||
/// Resets to default settings.
|
/// Resets to default settings.
|
||||||
open override func reset() {
|
open override func reset() {
|
||||||
shouldUpdateView = false
|
shouldUpdateView = false
|
||||||
|
super.reset()
|
||||||
|
aspectRatio = .none
|
||||||
color = .black
|
color = .black
|
||||||
//models
|
//models
|
||||||
badgeModel = nil
|
badgeModel = nil
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user