Merge branch 'bugfix/11_4_0' into 'release/11_4_0'
update for TitleLockup for label compression/hugging See merge request BPHV_MIPS/vds_ios!172
This commit is contained in:
commit
65da3ee8cd
@ -34,10 +34,17 @@ public final class SelfSizingCollectionView: UICollectionView {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private var contentSizeObservation: NSKeyValueObservation?
|
|
||||||
private var collectionViewHeight: NSLayoutConstraint?
|
private var collectionViewHeight: NSLayoutConstraint?
|
||||||
private var anyCancellable: AnyCancellable?
|
private var anyCancellable: AnyCancellable?
|
||||||
|
private var contentSizeSubject = CurrentValueSubject<CGSize, Never>(.zero)
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Public Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
public var contentSizePublisher: AnyPublisher<CGSize, Never> {
|
||||||
|
contentSizeSubject.eraseToAnyPublisher()
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -45,7 +52,6 @@ public final class SelfSizingCollectionView: UICollectionView {
|
|||||||
/// The natural size for the receiving view, considering only properties of the view itself.
|
/// The natural size for the receiving view, considering only properties of the view itself.
|
||||||
public override var intrinsicContentSize: CGSize {
|
public override var intrinsicContentSize: CGSize {
|
||||||
let contentSize = self.contentSize
|
let contentSize = self.contentSize
|
||||||
//print(#function, contentSize)
|
|
||||||
return CGSize(width: UIView.noIntrinsicMetric, height: contentSize.height)
|
return CGSize(width: UIView.noIntrinsicMetric, height: contentSize.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,17 +74,16 @@ public final class SelfSizingCollectionView: UICollectionView {
|
|||||||
setContentHuggingPriority(.required, for: .vertical)
|
setContentHuggingPriority(.required, for: .vertical)
|
||||||
setContentCompressionResistancePriority(.required, for: .vertical)
|
setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
collectionViewHeight = heightAnchor.constraint(equalToConstant: 0).activate()
|
collectionViewHeight = heightAnchor.constraint(equalToConstant: 0).activate()
|
||||||
|
|
||||||
// Observing the value of contentSize seems to be the only reliable way to get the contentSize after the collection view lays out its subviews.
|
anyCancellable = self.publisher(for: \.contentSize, options: [.new])
|
||||||
self.contentSizeObservation = self.observe(\.contentSize, options: [.old, .new]) { [weak self] _, change in
|
.sink { [weak self] compare in
|
||||||
// If we don't specify `options: [.old, .new]`, the change.oldValue and .newValue will always be `nil`.
|
guard let self else { return }
|
||||||
if change.newValue != change.oldValue {
|
if compare.height != self.collectionViewHeight?.constant {
|
||||||
self?.invalidateIntrinsicContentSize()
|
self.invalidateIntrinsicContentSize()
|
||||||
if let height = change.newValue?.height {
|
self.collectionViewHeight?.constant = compare.height
|
||||||
self?.collectionViewHeight?.constant = height
|
self.contentSizeSubject.send(compare)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import Foundation
|
|||||||
import UIKit
|
import UIKit
|
||||||
import VDSColorTokens
|
import VDSColorTokens
|
||||||
import VDSFormControlsTokens
|
import VDSFormControlsTokens
|
||||||
|
import Combine
|
||||||
|
|
||||||
/// A button group contains combinations of related CTAs including ``Button``, ``TextLink``, and ``TextLinkCaret``. This group component controls a combination's orientation, spacing, size and allowable size pairings.
|
/// A button group contains combinations of related CTAs including ``Button``, ``TextLink``, and ``TextLinkCaret``. This group component controls a combination's orientation, spacing, size and allowable size pairings.
|
||||||
@objc(VDSButtonGroup)
|
@objc(VDSButtonGroup)
|
||||||
@ -98,6 +99,8 @@ open class ButtonGroup: View {
|
|||||||
buttons.forEach { $0.surface = surface }
|
buttons.forEach { $0.surface = surface }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open var contentSizePublisher: AnyPublisher<CGSize, Never> { collectionView.contentSizePublisher }
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
@ -108,6 +111,7 @@ open class ButtonGroup: View {
|
|||||||
$0.delegate = self
|
$0.delegate = self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// CollectionView that renders the array of buttonBase obects.
|
||||||
fileprivate lazy var collectionView: SelfSizingCollectionView = {
|
fileprivate lazy var collectionView: SelfSizingCollectionView = {
|
||||||
|
|
||||||
return SelfSizingCollectionView(frame: .zero, collectionViewLayout: positionLayout).with {
|
return SelfSizingCollectionView(frame: .zero, collectionViewLayout: positionLayout).with {
|
||||||
|
|||||||
@ -68,6 +68,7 @@ open class TitleLockup: View {
|
|||||||
/// Label used to render the eyebrow model.
|
/// Label used to render the eyebrow model.
|
||||||
open var eyebrowLabel = Label().with {
|
open var eyebrowLabel = Label().with {
|
||||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
$0.setContentHuggingPriority(.required, for: .vertical)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Model used in rendering the eyebrow label.
|
/// Model used in rendering the eyebrow label.
|
||||||
@ -77,6 +78,7 @@ open class TitleLockup: View {
|
|||||||
/// Label used to render the title model.
|
/// Label used to render the title model.
|
||||||
open var titleLabel = Label().with {
|
open var titleLabel = Label().with {
|
||||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
$0.setContentHuggingPriority(.required, for: .vertical)
|
||||||
$0.accessibilityTraits.insert([.header])
|
$0.accessibilityTraits.insert([.header])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +89,7 @@ open class TitleLockup: View {
|
|||||||
/// Label used to render the subtitle model.
|
/// Label used to render the subtitle model.
|
||||||
open var subTitleLabel = Label().with {
|
open var subTitleLabel = Label().with {
|
||||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
$0.setContentHuggingPriority(.required, for: .vertical)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Model used in rendering the subtitle label.
|
/// Model used in rendering the subtitle label.
|
||||||
@ -380,7 +383,7 @@ open class TitleLockup: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//pin the last view to the bottom of this view
|
//pin the last view to the bottom of this view
|
||||||
previousView?.pinBottom(0, .defaultHigh)
|
previousView?.pinBottom(0)
|
||||||
|
|
||||||
//debugging for borders
|
//debugging for borders
|
||||||
eyebrowLabel.debugBorder(show: hasDebugBorder, color: .green)
|
eyebrowLabel.debugBorder(show: hasDebugBorder, color: .green)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user