From ba3e9e749102db0889d0c0b01f4916a8572ac2bb Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Fri, 19 Jun 2020 19:43:01 -0400 Subject: [PATCH] Fix compose attachment description text view not expanding to fit text --- .../Compose/ComposeAttachmentsViewController.swift | 6 ++++++ .../ComposeAttachmentTableViewCell.swift | 10 ++++++++++ .../ComposeAttachmentTableViewCell.xib | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/Tusker/Screens/Compose/ComposeAttachmentsViewController.swift b/Tusker/Screens/Compose/ComposeAttachmentsViewController.swift index f6990866..d24b91e6 100644 --- a/Tusker/Screens/Compose/ComposeAttachmentsViewController.swift +++ b/Tusker/Screens/Compose/ComposeAttachmentsViewController.swift @@ -531,6 +531,12 @@ extension ComposeAttachmentsViewController: ComposeAttachmentTableViewCellDelega func attachmentDescriptionChanged(_ cell: ComposeAttachmentTableViewCell) { delegate?.composeRequiresAttachmentDescriptionsDidChange() } + + func composeAttachmentDescriptionHeightChanged(_ cell: ComposeAttachmentTableViewCell) { + tableView.performBatchUpdates(nil) { (_) in + self.updateHeightConstraint() + } + } } extension ComposeAttachmentsViewController: ComposeDrawingViewControllerDelegate { diff --git a/Tusker/Views/Attachment Cells/ComposeAttachmentTableViewCell.swift b/Tusker/Views/Attachment Cells/ComposeAttachmentTableViewCell.swift index 95d797df..49b237c2 100644 --- a/Tusker/Views/Attachment Cells/ComposeAttachmentTableViewCell.swift +++ b/Tusker/Views/Attachment Cells/ComposeAttachmentTableViewCell.swift @@ -15,6 +15,7 @@ protocol ComposeAttachmentTableViewCellDelegate: class { func composeAttachment(_ cell: ComposeAttachmentTableViewCell, present viewController: UIViewController, animated: Bool) func removeAttachment(_ cell: ComposeAttachmentTableViewCell) func attachmentDescriptionChanged(_ cell: ComposeAttachmentTableViewCell) + func composeAttachmentDescriptionHeightChanged(_ cell: ComposeAttachmentTableViewCell) } class ComposeAttachmentTableViewCell: UITableViewCell { @@ -23,6 +24,7 @@ class ComposeAttachmentTableViewCell: UITableViewCell { @IBOutlet weak var assetImageView: UIImageView! @IBOutlet weak var descriptionTextView: UITextView! + @IBOutlet weak var descriptionTextViewHeightConstraint: NSLayoutConstraint! @IBOutlet weak var descriptionPlaceholderLabel: UILabel! @IBOutlet weak var removeButton: UIButton! @IBOutlet weak var activityIndicator: UIActivityIndicatorView! @@ -142,6 +144,7 @@ class ComposeAttachmentTableViewCell: UITableViewCell { override func prepareForReuse() { super.prepareForReuse() assetImageView.image = nil + descriptionTextViewHeightConstraint.constant = 80 } @IBAction func removeButtonPressed(_ sender: Any) { @@ -162,5 +165,12 @@ extension ComposeAttachmentTableViewCell: UITextViewDelegate { attachment.attachmentDescription = textView.text updateDescriptionPlaceholderLabel() delegate?.attachmentDescriptionChanged(self) + let smallestSize = textView.sizeThatFits(CGSize(width: textView.bounds.width, height: .greatestFiniteMagnitude)) + let old = descriptionTextViewHeightConstraint.constant + descriptionTextViewHeightConstraint.constant = max(80, smallestSize.height) + if old != descriptionTextViewHeightConstraint.constant { + delegate?.composeAttachmentDescriptionHeightChanged(self) + } + } } diff --git a/Tusker/Views/Attachment Cells/ComposeAttachmentTableViewCell.xib b/Tusker/Views/Attachment Cells/ComposeAttachmentTableViewCell.xib index 7f6264f1..b84fe629 100644 --- a/Tusker/Views/Attachment Cells/ComposeAttachmentTableViewCell.xib +++ b/Tusker/Views/Attachment Cells/ComposeAttachmentTableViewCell.xib @@ -36,6 +36,9 @@ + + + @@ -79,6 +82,7 @@ +