refactored to final fix, hopefully :D
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
5fcc59d8af
commit
289353a443
@ -44,6 +44,7 @@ open class TileContainer: TileContainerBase<TileContainer.Padding> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
open class TileContainerBase<PaddingType: DefaultValuing>: Control where PaddingType.ValueType == CGFloat {
|
open class TileContainerBase<PaddingType: DefaultValuing>: Control where PaddingType.ValueType == CGFloat {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -109,7 +110,16 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
|||||||
$0.clipsToBounds = true
|
$0.clipsToBounds = true
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var containerView = View()
|
open var containerView = View().with {
|
||||||
|
$0.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
||||||
|
$0.setContentHuggingPriority(.defaultLow, for: .vertical)
|
||||||
|
$0.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
||||||
|
$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
|
||||||
@ -180,12 +190,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 containerViewLeadingConstraint: NSLayoutConstraint?
|
|
||||||
internal var containerViewLeadingGreaterThanOrEqualConstraint: NSLayoutConstraint?
|
|
||||||
|
|
||||||
internal var containerViewTrailingConstraint: NSLayoutConstraint?
|
|
||||||
internal var containerViewTrailingLessThanOrEqualConstraint: NSLayoutConstraint?
|
|
||||||
|
|
||||||
internal var contentViewTopConstraint: NSLayoutConstraint?
|
internal var contentViewTopConstraint: NSLayoutConstraint?
|
||||||
internal var contentViewBottomConstraint: NSLayoutConstraint?
|
internal var contentViewBottomConstraint: NSLayoutConstraint?
|
||||||
internal var contentViewLeadingConstraint: NSLayoutConstraint?
|
internal var contentViewLeadingConstraint: NSLayoutConstraint?
|
||||||
@ -232,17 +236,6 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
|||||||
containerView.addSubview(contentView)
|
containerView.addSubview(contentView)
|
||||||
containerView.addSubview(highlightView)
|
containerView.addSubview(highlightView)
|
||||||
|
|
||||||
containerView
|
|
||||||
.pinTop()
|
|
||||||
.pinCenterX()
|
|
||||||
.pinBottom()
|
|
||||||
|
|
||||||
containerViewLeadingConstraint = containerView.pinLeading(anchor: leadingAnchor)?.deactivate()
|
|
||||||
containerViewLeadingGreaterThanOrEqualConstraint = containerView.pinLeadingGreaterThanOrEqualTo(anchor: leadingAnchor)?.deactivate()
|
|
||||||
|
|
||||||
containerViewTrailingConstraint = containerView.pinTrailing(anchor: trailingAnchor)?.deactivate()
|
|
||||||
containerViewTrailingLessThanOrEqualConstraint = containerView.pinTrailingLessThanOrEqualTo(anchor: trailingAnchor)?.deactivate()
|
|
||||||
|
|
||||||
backgroundImageView.pinToSuperView()
|
backgroundImageView.pinToSuperView()
|
||||||
|
|
||||||
widthConstraint = containerView.widthAnchor.constraint(equalToConstant: 0).deactivate()
|
widthConstraint = containerView.widthAnchor.constraint(equalToConstant: 0).deactivate()
|
||||||
@ -313,70 +306,10 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
|||||||
contentViewLeadingConstraint?.constant = padding.value
|
contentViewLeadingConstraint?.constant = padding.value
|
||||||
contentViewBottomConstraint?.constant = padding.value
|
contentViewBottomConstraint?.constant = padding.value
|
||||||
contentViewTrailingConstraint?.constant = padding.value
|
contentViewTrailingConstraint?.constant = padding.value
|
||||||
|
|
||||||
//deactivate everything
|
|
||||||
widthConstraint?.deactivate()
|
|
||||||
heightConstraint?.deactivate()
|
|
||||||
|
|
||||||
containerViewLeadingGreaterThanOrEqualConstraint?.deactivate()
|
updateContainerView()
|
||||||
containerViewLeadingConstraint?.deactivate()
|
|
||||||
|
|
||||||
containerViewTrailingLessThanOrEqualConstraint?.deactivate()
|
|
||||||
containerViewTrailingConstraint?.deactivate()
|
|
||||||
|
|
||||||
//run logic to determine which to activate
|
|
||||||
if let width, aspectRatio == .none && height == nil{
|
|
||||||
widthConstraint?.constant = width
|
|
||||||
widthConstraint?.activate()
|
|
||||||
containerViewLeadingGreaterThanOrEqualConstraint?.activate()
|
|
||||||
containerViewTrailingLessThanOrEqualConstraint?.activate()
|
|
||||||
|
|
||||||
} else if let height, aspectRatio == .none && width == nil{
|
|
||||||
heightConstraint?.constant = height
|
|
||||||
heightConstraint?.activate()
|
|
||||||
containerViewLeadingConstraint?.activate()
|
|
||||||
containerViewTrailingConstraint?.activate()
|
|
||||||
|
|
||||||
} else if let height, let width {
|
|
||||||
widthConstraint?.constant = width
|
|
||||||
heightConstraint?.constant = height
|
|
||||||
heightConstraint?.activate()
|
|
||||||
widthConstraint?.activate()
|
|
||||||
containerViewLeadingGreaterThanOrEqualConstraint?.activate()
|
|
||||||
containerViewTrailingLessThanOrEqualConstraint?.activate()
|
|
||||||
|
|
||||||
} else if let width {
|
|
||||||
let size = ratioSize(for: width)
|
|
||||||
widthConstraint?.constant = size.width
|
|
||||||
heightConstraint?.constant = size.height
|
|
||||||
widthConstraint?.activate()
|
|
||||||
heightConstraint?.activate()
|
|
||||||
containerViewLeadingGreaterThanOrEqualConstraint?.activate()
|
|
||||||
containerViewTrailingLessThanOrEqualConstraint?.activate()
|
|
||||||
|
|
||||||
} else if let height {
|
|
||||||
let size = ratioSize(for: height)
|
|
||||||
widthConstraint?.constant = size.width
|
|
||||||
heightConstraint?.constant = size.height
|
|
||||||
widthConstraint?.activate()
|
|
||||||
heightConstraint?.activate()
|
|
||||||
containerViewLeadingGreaterThanOrEqualConstraint?.activate()
|
|
||||||
containerViewTrailingLessThanOrEqualConstraint?.activate()
|
|
||||||
|
|
||||||
} else {
|
|
||||||
containerViewLeadingConstraint?.activate()
|
|
||||||
containerViewTrailingConstraint?.activate()
|
|
||||||
}
|
|
||||||
|
|
||||||
applyBackgroundEffects()
|
|
||||||
|
|
||||||
if showDropShadow, surface == .light {
|
|
||||||
containerView.addDropShadow(dropShadowConfiguration)
|
|
||||||
} else {
|
|
||||||
containerView.removeDropShadows()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open override var accessibilityElements: [Any]? {
|
open override var accessibilityElements: [Any]? {
|
||||||
get {
|
get {
|
||||||
var items = [Any]()
|
var items = [Any]()
|
||||||
@ -403,13 +336,6 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
|||||||
set {}
|
set {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used to update frames for the added CAlayers to our view
|
|
||||||
open override func layoutSubviews() {
|
|
||||||
super.layoutSubviews()
|
|
||||||
containerView.dropShadowLayers?.forEach { $0.frame = bounds }
|
|
||||||
containerView.gradientLayers?.forEach { $0.frame = bounds }
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Public Methods
|
// MARK: - Public Methods
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -485,7 +411,69 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
|
|||||||
|
|
||||||
return CGSize(width: width, height: height)
|
return CGSize(width: width, height: height)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func sizeContainerView(width: CGFloat? = nil, height: CGFloat? = nil) {
|
||||||
|
if let width, width > 0 {
|
||||||
|
widthConstraint?.constant = width
|
||||||
|
widthConstraint?.activate()
|
||||||
|
}
|
||||||
|
|
||||||
|
if let height, height > 0 {
|
||||||
|
heightConstraint?.constant = height
|
||||||
|
heightConstraint?.activate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func updateContainerView() {
|
||||||
|
applyBackgroundEffects()
|
||||||
|
|
||||||
|
widthConstraint?.deactivate()
|
||||||
|
heightConstraint?.deactivate()
|
||||||
|
|
||||||
|
if showDropShadow, surface == .light {
|
||||||
|
containerView.addDropShadow(dropShadowConfiguration)
|
||||||
|
} else {
|
||||||
|
containerView.removeDropShadows()
|
||||||
|
}
|
||||||
|
|
||||||
|
containerView.dropShadowLayers?.forEach { $0.frame = bounds }
|
||||||
|
containerView.gradientLayers?.forEach { $0.frame = bounds }
|
||||||
|
|
||||||
|
if width != nil || height != nil {
|
||||||
|
var containerViewWidth: CGFloat?
|
||||||
|
var containerViewHeight: CGFloat?
|
||||||
|
//run logic to determine which to activate
|
||||||
|
if let width, aspectRatio == .none && height == nil{
|
||||||
|
containerViewWidth = width
|
||||||
|
|
||||||
|
} else if let height, aspectRatio == .none && width == nil{
|
||||||
|
containerViewHeight = height
|
||||||
|
|
||||||
|
} else if let height, let width {
|
||||||
|
containerViewWidth = width
|
||||||
|
containerViewHeight = height
|
||||||
|
|
||||||
|
} else if let width {
|
||||||
|
let size = ratioSize(for: width)
|
||||||
|
containerViewWidth = size.width
|
||||||
|
containerViewHeight = size.height
|
||||||
|
|
||||||
|
} else if let height {
|
||||||
|
let size = ratioSize(for: height)
|
||||||
|
containerViewWidth = size.width
|
||||||
|
containerViewHeight = size.height
|
||||||
|
}
|
||||||
|
|
||||||
|
sizeContainerView(width: containerViewWidth, height: containerViewHeight)
|
||||||
|
containerView.applyAlignment(alignment)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
containerView.applyAlignment(distribution == .fill ? .fill : alignment)
|
||||||
|
if let superview, distribution == .fill, !isPinnedHorizontallyToSuperview() {
|
||||||
|
sizeContainerView(width: superview.frame.size.width)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension TileContainerBase {
|
extension TileContainerBase {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user