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