How to embed UITextView in a ContentView if I use UICollectionViewCompositionalLayout.list.

Hello!

Description

I have a ContentView which contains UITextView. I would like to use this ContentView in UICollectionViewCell.

View Hierarchy

Code Block
UICollectionView {
MyContentView {
UIStackView {
UITextView
}
}
}


As you see I add additional UIStackView that embraces UITextView.

Problem

When I typing in UITextView, it doesn't grow at all. But if I press on cell and apply configuration is applied to content view, everything works fine and I get correct size of textView.

Code

Code Block
class CustomConfigurationCell: UICollectionViewCell {
override func updateConfiguration(using state: UICellConfigurationState) {
super.updateConfiguration(using: state)
backgroundConfiguration = CustomBackgroundConfiguration.configuration(for: state)
}
}
class MyContentView {
private var appliedConfiguration: CustomContentConfiguration!
private func apply(configuration: CustomContentConfiguration) {
guard appliedConfiguration != configuration else { return }
appliedConfiguration = configuration
}
}


What have I tried so far?


I added listeners for textViewDidChange and call all setNeedsUpdateConstraints, setNeedsLayout and other layout methods on both self ( ContentView ) and self.superview ( CustomConfigurationCell ).

The CustomListCell class of Implementing Modern Collection Views shows a way to customize a list cell.
It doesn't help.
Could you show an example where CustomListCell with embedded UITextView expanding on typing with any layout in UICollectionView?
How to embed UITextView in a ContentView if I use UICollectionViewCompositionalLayout.list.
 
 
Q