added contentHugging and compressionResistance

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-01-24 16:50:58 -06:00
parent 22f156d461
commit b58cfbe175

View File

@ -60,6 +60,10 @@ public final class SelfSizingCollectionView: UICollectionView {
// MARK: - Private Methods
//--------------------------------------------------
private func setupContentSizeObservation() {
//ensure autoLayout uses intrinsic height
setContentHuggingPriority(.required, for: .vertical)
setContentCompressionResistancePriority(.required, for: .vertical)
// Observing the value of contentSize seems to be the only reliable way to get the contentSize after the collection view lays out its subviews.
self.contentSizeObservation = self.observe(\.contentSize, options: [.old, .new]) { [weak self] _, change in
// If we don't specify `options: [.old, .new]`, the change.oldValue and .newValue will always be `nil`.