InputBarAccessoryView icon indicating copy to clipboard operation
InputBarAccessoryView copied to clipboard

Attachment Plugin Breaks After Invalidation if TextView size Changed

Open mdstone06 opened this issue 5 years ago • 7 comments

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.

Simulator Screen Shot - iPhone 11 - 2019-11-13 at 10 27 05

mdstone06 avatar Nov 13 '19 15:11 mdstone06

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

nathantannar4 avatar Nov 14 '19 19:11 nathantannar4

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.

mdstone06 avatar Nov 14 '19 19:11 mdstone06

@nathantannar4 Hi, can you please bring an example of how to handle this kind of behavior? I'm having the same issue with attachmentView.

Yulia8294 avatar Dec 12 '19 07:12 Yulia8294

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
}

mdstone06 avatar Dec 12 '19 14:12 mdstone06

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.

nathantannar4 avatar Mar 02 '20 07:03 nathantannar4

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?

hovaks avatar Sep 24 '20 01:09 hovaks

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() } }

hovaks avatar Sep 25 '20 10:09 hovaks

This issue has become stale/outdated. Please re-open if desired.

nathantannar4 avatar Oct 05 '22 07:10 nathantannar4