nathantannar4 / InputBarAccessoryView

A simple and easily customizable InputAccessoryView for making powerful input bars with autocomplete and attachments
MIT License
1.17k stars 229 forks source link

How to communicate size from the `middleContentView` #183

Open AndrewSB opened 3 years ago

AndrewSB commented 3 years ago

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?

nathantannar4 commented 3 years ago

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.

AndrewSB commented 3 years ago

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

nathantannar4 commented 3 years ago

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