No longer invalidateIntrinsicContentSize() invokes intrinsicContentSize for UICollectionViewCell/UITableViewCell in iOS 16?

I've used invalidateIntrinsicContentSize() in UICollectionViewCell to calculate custom UI. But it doesn't invoke intrinsicContentSize on iOS beta 16 devices..

class DynamicCell: UICollectionViewCell {
    func invokeResize() {
        cell.subviews.forEach { $0.resize() }

        // it doesn't invoke intrinsicContentSize from iOS 16 beta ?? 
        invalidateIntrinsicContentSize() 
    }

    override func intrinsicContentSize: CGSize { 
        return calculateDynamicCellSize()
    }
}

I don't know if it is a bug or a specification that occurred while implementing UICollectionView.selfSizingInvalidation property.

I could revise this code for iOS beta 16 using parent's( UICollectionReusableView | UIView ) methods like below.

class RevisedDynamicCell: UICollectionViewCell {
    func invokeResize() {
        cell.subviews.forEach { $0.resize() }

        if #available(iOS 16.0, *) {
            // It works because it called UIView.invalidateIntrinsicContentSize 
            invalidateUIViewIntrinsicContentSize()
        } else {
            invalidateIntrinsicContentSize() 
        }
    }

    override func intrinsicContentSize: CGSize { 
        return calculateDynamicCellSize()
    }
}

extension UICollectionReusableView {
    func invalidateUIViewIntrinsicContentSize() {
        super.invalidateIntrinsicContentSize()
    }
}```

Prior to iOS 16, calling invalidateIntrinsicContentSize() on a cell in a UICollectionView did not perform any supported behavior, because the layout of cells is manually managed by UICollectionView (via the geometry specified in layout attributes) and invalidateIntrinsicContentSize() is historically intended for views directly participating in Auto Layout.

From the small amount of code you shared, it's not clear why you are calling invalidateIntrinsicContentSize() and how you are using the intrinsicContentSize override on your UICollectionViewCell. Can you please submit feedback with a complete sample project that illustrates your use case? That will allow us to investigate what the problem is (and recommend a solution, if necessary).

No longer invalidateIntrinsicContentSize() invokes intrinsicContentSize for UICollectionViewCell/UITableViewCell in iOS 16?
 
 
Q