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 @@ +