InputBarAccessoryView
InputBarAccessoryView copied to clipboard
Attachment Plugin Breaks After Invalidation if TextView size Changed
If you are using the attachment plugin and you add an attachment, if the text view container size changes after attaching, then the plugin does not get removed properly when the attachments are removed. I have reproduced this with the sample project's Slack style bar.
Attach an image, and then type in multiple lines of text, and then remove the image. A large swath of whitespace remains where the attachment plugin was.
That is by design. You need to manage the show/hide state. There are delegate methods that tell you when the plugin wants to hide or show.
Sent with GitHawk
I would disagree. The sample project looks at these delegate methods and tells the top stack view to redraw, but it does not have any effect on the container's size. The resizing works fine if there is only a single line of text, OR if the attachment was made after the text container's size changes. But in the event that you add an attachment, and then resize the text container with multiple lines of text, and then attempt to remove the attachment, the top container view does not go away despite the same lines of code being executed by the delegate.
@nathantannar4 Hi, can you please bring an example of how to handle this kind of behavior? I'm having the same issue with attachmentView.
To fix it, you just have to change or set the text in the inputTextView
after the attachment has been removed. In the AttachmentManagerDelegate
method:
func attachmentManager(_ manager: AttachmentManager, didRemove attachment: AttachmentManager.Attachment, at index: Int) {
inputBar.inputTextView.text = inputBar.inputTextView.text
}
Oh if you have to set the text then that is a bug, I thought that you were not removing the AttachmentCollectionView from the topStackView.
The issue is still actual in version 5.2.0 on iOS14 and inputBar.inputTextView.text = inputBar.inputTextView.text doesn't seem to help. Any news on this issue?
This solved the issue:
private func setAttachmentManager(active: Bool) { if active, !topStackView.arrangedSubviews.contains(attachmentManager.attachmentView) { topStackView.insertArrangedSubview( attachmentManager.attachmentView, at: topStackView.arrangedSubviews.count ) topStackView.layoutIfNeeded() } else if !active, topStackView.arrangedSubviews.contains(attachmentManager.attachmentView) { attachmentManager.attachmentView.removeFromSuperview() invalidateIntrinsicContentSize() inputTextView.layoutIfNeeded() topStackView.layoutIfNeeded() } }
This issue has become stale/outdated. Please re-open if desired.