redo constraints

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-06-26 09:50:06 -05:00
parent 738dee681f
commit 9c32ea4870

View File

@ -179,11 +179,16 @@ 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 heightGreaterThanConstraint: NSLayoutConstraint?
internal var containerTopConstraint: NSLayoutConstraint? internal var containerViewBottomConstraint: NSLayoutConstraint?
internal var containerBottomConstraint: NSLayoutConstraint? internal var containerViewTrailingConstraint: NSLayoutConstraint?
internal var containerLeadingConstraint: NSLayoutConstraint? internal var containerViewBottomLessThanOrEqualConstraint: NSLayoutConstraint?
internal var containerTrailingConstraint: NSLayoutConstraint? internal var containerViewTrailingLessThanOrEqualConstraint: NSLayoutConstraint?
internal var contentViewTopConstraint: NSLayoutConstraint?
internal var contentViewBottomConstraint: NSLayoutConstraint?
internal var contentViewLeadingConstraint: NSLayoutConstraint?
internal var contentViewTrailingConstraint: NSLayoutConstraint?
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Configuration // MARK: - Configuration
@ -221,30 +226,26 @@ 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)
containerView.addSubview(backgroundImageView)
containerView.addSubview(contentView)
containerView.addSubview(highlightView)
let layoutGuide = UILayoutGuide() containerView
addLayoutGuide(layoutGuide)
layoutGuide
.pinTop() .pinTop()
.pinLeading() .pinLeading()
.pinTrailing(0, .defaultHigh)
.pinBottom(0, .defaultHigh)
addSubview(backgroundImageView)
addSubview(containerView)
containerView.addSubview(contentView)
addSubview(highlightView)
containerView.pinToSuperView() containerViewTrailingConstraint = containerView.pinTrailing(anchor: trailingAnchor)?.deactivate()
containerViewBottomConstraint = containerView.pinBottom(anchor: bottomAnchor)?.deactivate()
widthConstraint = layoutGuide.widthAnchor.constraint(equalToConstant: 0) containerViewTrailingLessThanOrEqualConstraint = containerView.pinTrailingLessThanOrEqualTo(anchor: trailingAnchor)?.deactivate()
containerViewBottomLessThanOrEqualConstraint = containerView.pinBottomLessThanOrEqualTo(anchor: bottomAnchor)?.deactivate()
heightGreaterThanConstraint = layoutGuide.heightAnchor.constraint(greaterThanOrEqualToConstant: 44.0)
heightGreaterThanConstraint?.isActive = false
heightConstraint = layoutGuide.heightAnchor.constraint(equalToConstant: 0)
backgroundImageView.pinToSuperView() backgroundImageView.pinToSuperView()
widthConstraint = containerView.widthAnchor.constraint(equalToConstant: 0).deactivate()
heightConstraint = containerView.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)
backgroundImageView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal) backgroundImageView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
@ -252,20 +253,20 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
backgroundImageView.isUserInteractionEnabled = false backgroundImageView.isUserInteractionEnabled = false
backgroundImageView.isHidden = true backgroundImageView.isHidden = true
containerTopConstraint = contentView.pinTop(anchor: layoutGuide.topAnchor, constant: padding.value) contentViewTopConstraint = contentView.pinTop(anchor: containerView.topAnchor, constant: padding.value)
containerBottomConstraint = layoutGuide.pinBottom(anchor: contentView.bottomAnchor, constant: padding.value) contentViewBottomConstraint = containerView.pinBottom(anchor: contentView.bottomAnchor, constant: padding.value)
containerLeadingConstraint = contentView.pinLeading(anchor: layoutGuide.leadingAnchor, constant: padding.value) contentViewLeadingConstraint = contentView.pinLeading(anchor: containerView.leadingAnchor, constant: padding.value)
containerTrailingConstraint = layoutGuide.pinTrailing(anchor: contentView.trailingAnchor, constant: padding.value) contentViewTrailingConstraint = containerView.pinTrailing(anchor: contentView.trailingAnchor, constant: padding.value)
highlightView.pin(layoutGuide) highlightView.pin(containerView)
highlightView.isHidden = true highlightView.isHidden = true
highlightView.backgroundColor = .clear highlightView.backgroundColor = .clear
//corner radius //corner radius
layer.cornerRadius = cornerRadius containerView.layer.cornerRadius = cornerRadius
backgroundImageView.layer.cornerRadius = cornerRadius backgroundImageView.layer.cornerRadius = cornerRadius
highlightView.layer.cornerRadius = cornerRadius highlightView.layer.cornerRadius = cornerRadius
clipsToBounds = true containerView.clipsToBounds = true
containerView.bridge_isAccessibilityElementBlock = { [weak self] in self?.onClickSubscriber != nil } containerView.bridge_isAccessibilityElementBlock = { [weak self] in self?.onClickSubscriber != nil }
containerView.accessibilityHint = "Double tap to open." containerView.accessibilityHint = "Double tap to open."
@ -303,43 +304,74 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
highlightView.backgroundColor = hightLightViewColorConfiguration.getColor(self) highlightView.backgroundColor = hightLightViewColorConfiguration.getColor(self)
highlightView.isHidden = !isHighlighted highlightView.isHidden = !isHighlighted
layer.borderColor = borderColorConfiguration.getColor(self).cgColor containerView.layer.borderColor = borderColorConfiguration.getColor(self).cgColor
layer.borderWidth = showBorder ? VDSFormControls.borderWidth : 0 containerView.layer.borderWidth = showBorder ? VDSFormControls.borderWidth : 0
containerTopConstraint?.constant = padding.value contentViewTopConstraint?.constant = padding.value
containerLeadingConstraint?.constant = padding.value contentViewLeadingConstraint?.constant = padding.value
containerBottomConstraint?.constant = padding.value contentViewBottomConstraint?.constant = padding.value
containerTrailingConstraint?.constant = padding.value contentViewTrailingConstraint?.constant = padding.value
//deactivate everything
widthConstraint?.deactivate()
heightConstraint?.deactivate()
containerViewTrailingLessThanOrEqualConstraint?.deactivate()
containerViewTrailingLessThanOrEqualConstraint?.deactivate()
containerViewBottomConstraint?.deactivate()
containerViewTrailingConstraint?.deactivate()
//run logic to determine which to activate
if let width, aspectRatio == .none && height == nil{ if let width, aspectRatio == .none && height == nil{
widthConstraint?.constant = width widthConstraint?.constant = width
widthConstraint?.isActive = true widthConstraint?.activate()
heightConstraint?.isActive = false containerViewTrailingConstraint?.activate()
heightGreaterThanConstraint?.isActive = true containerViewBottomConstraint?.activate()
} else if let height, aspectRatio == .none && width == nil{
heightConstraint?.constant = height
heightConstraint?.activate()
containerViewTrailingConstraint?.activate()
containerViewBottomConstraint?.activate()
} else if let height, let width { } else if let height, let width {
widthConstraint?.constant = width widthConstraint?.constant = width
heightConstraint?.constant = height heightConstraint?.constant = height
heightConstraint?.isActive = true heightConstraint?.activate()
widthConstraint?.isActive = true widthConstraint?.activate()
heightGreaterThanConstraint?.isActive = false containerViewTrailingLessThanOrEqualConstraint?.activate()
containerViewBottomLessThanOrEqualConstraint?.activate()
} else if let width { } else if let width {
let size = ratioSize(for: width) let size = ratioSize(for: width)
widthConstraint?.constant = size.width widthConstraint?.constant = size.width
heightConstraint?.constant = size.height heightConstraint?.constant = size.height
widthConstraint?.isActive = true widthConstraint?.activate()
heightConstraint?.isActive = true heightConstraint?.activate()
heightGreaterThanConstraint?.isActive = false containerViewTrailingLessThanOrEqualConstraint?.activate()
containerViewBottomLessThanOrEqualConstraint?.activate()
} else if let height {
let size = ratioSize(for: height)
//enforce exact height/width
widthConstraint?.constant = size.width
heightConstraint?.constant = size.height
widthConstraint?.activate()
heightConstraint?.activate()
containerViewTrailingLessThanOrEqualConstraint?.activate()
containerViewBottomLessThanOrEqualConstraint?.activate()
} else { } else {
widthConstraint?.isActive = false //set to the parent view
heightConstraint?.isActive = false containerViewBottomConstraint?.activate()
containerViewTrailingConstraint?.activate()
} }
applyBackgroundEffects() applyBackgroundEffects()
if showDropShadow, surface == .light { if showDropShadow, surface == .light {
addDropShadow(dropShadowConfiguration) containerView.addDropShadow(dropShadowConfiguration)
} else { } else {
removeDropShadows() containerView.removeDropShadows()
} }
} }
@ -372,8 +404,8 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
/// Used to update frames for the added CAlayers to our view /// Used to update frames for the added CAlayers to our view
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
dropShadowLayers?.forEach { $0.frame = bounds } containerView.dropShadowLayers?.forEach { $0.frame = bounds }
gradientLayers?.forEach { $0.frame = bounds } containerView.gradientLayers?.forEach { $0.frame = bounds }
} }
//-------------------------------------------------- //--------------------------------------------------
@ -400,25 +432,25 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
switch backgroundEffect { switch backgroundEffect {
case .transparency: case .transparency:
alphaConfiguration = 0.8 alphaConfiguration = 0.8
removeGradientLayer() containerView.removeGradientLayer()
case .gradient(let firstColor, let secondColor): case .gradient(let firstColor, let secondColor):
alphaConfiguration = 1.0 alphaConfiguration = 1.0
addGradientLayer(with: firstColor, secondColor: secondColor) containerView.addGradientLayer(with: firstColor, secondColor: secondColor)
backgroundImageView.isHidden = true backgroundImageView.isHidden = true
backgroundImageView.alpha = 1.0 backgroundImageView.alpha = 1.0
case .none: case .none:
alphaConfiguration = 1.0 alphaConfiguration = 1.0
removeGradientLayer() containerView.removeGradientLayer()
} }
if let backgroundImage { if let backgroundImage {
backgroundImageView.image = backgroundImage backgroundImageView.image = backgroundImage
backgroundImageView.isHidden = false backgroundImageView.isHidden = false
backgroundImageView.alpha = alphaConfiguration backgroundImageView.alpha = alphaConfiguration
backgroundColor = imageFallbackColor.withAlphaComponent(alphaConfiguration) containerView.backgroundColor = imageFallbackColor.withAlphaComponent(alphaConfiguration)
} else { } else {
backgroundImageView.isHidden = true backgroundImageView.isHidden = true
backgroundImageView.alpha = 1.0 backgroundImageView.alpha = 1.0
backgroundColor = color.withAlphaComponent(alphaConfiguration) containerView.backgroundColor = color.withAlphaComponent(alphaConfiguration)
} }
} }