InputBarAccessoryView icon indicating copy to clipboard operation
InputBarAccessoryView copied to clipboard

How to communicate size from the `middleContentView`

Open AndrewSB opened this issue 3 years ago • 3 comments

Hey! I’m trying to add a constant height UICollectionView (that scrolls inline with the text) into the middleContentView of my input bar, but I'm confused on how to communicate the new height.

My new view is basically

let newContainer = UIScrollView()
let textAndAssetsStack = UIStackView() // axis = .vertical
textAndAssetsStack.addArrangedSubview(InputTextView())
textAndAssetsStack.addArrangedSubview(my100pxTallCollectionView)
// constrain edges of textAndAssetsStack to newContainer

setMiddleContentView(newContainer)

I've tried a couple things with constraints, and overridding calculateIntrinsicContentSize, but no matter what I do the height of the bar stays the initial 1-line-tall height. I imagine it's because my scroll view doesn't communicate it's height to the library properly. is there an expected way to override this? or was setMiddleContentView written only with constant height views (like the button, in the example project) in mind?

AndrewSB avatar Dec 22 '20 20:12 AndrewSB

Are you expecting the height to be dynamic? You should be able to set a height constraint on your scroll view to get it to appear.

Overriding the middle content is more of a hack that many had just requested. There could be issues.

nathantannar4 avatar Dec 24 '20 05:12 nathantannar4

ahh got it, I must be running up against those hacks. yes, the height is dynamic; the text field acts just like the default middleContentView, it breaks to become multiline as text is entered.

what constraint are you thinking? one that I invalidate & re-calculate by adding textView.frame.height + collectionViewHeightConstant100 each time my textViewDidChange, or something else? I'll give it a shot this week

AndrewSB avatar Dec 28 '20 07:12 AndrewSB

I thought you said the height was constant? Try giving the scroll view a height constraint.

nathantannar4 avatar Dec 28 '20 08:12 nathantannar4