Fix compose attachment description text view not expanding to fit text

This commit is contained in:
Shadowfacts 2020-06-19 19:43:01 -04:00
parent 920f926b48
commit ba3e9e7491
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 20 additions and 0 deletions

View File

@ -531,6 +531,12 @@ extension ComposeAttachmentsViewController: ComposeAttachmentTableViewCellDelega
func attachmentDescriptionChanged(_ cell: ComposeAttachmentTableViewCell) { func attachmentDescriptionChanged(_ cell: ComposeAttachmentTableViewCell) {
delegate?.composeRequiresAttachmentDescriptionsDidChange() delegate?.composeRequiresAttachmentDescriptionsDidChange()
} }
func composeAttachmentDescriptionHeightChanged(_ cell: ComposeAttachmentTableViewCell) {
tableView.performBatchUpdates(nil) { (_) in
self.updateHeightConstraint()
}
}
} }
extension ComposeAttachmentsViewController: ComposeDrawingViewControllerDelegate { extension ComposeAttachmentsViewController: ComposeDrawingViewControllerDelegate {

View File

@ -15,6 +15,7 @@ protocol ComposeAttachmentTableViewCellDelegate: class {
func composeAttachment(_ cell: ComposeAttachmentTableViewCell, present viewController: UIViewController, animated: Bool) func composeAttachment(_ cell: ComposeAttachmentTableViewCell, present viewController: UIViewController, animated: Bool)
func removeAttachment(_ cell: ComposeAttachmentTableViewCell) func removeAttachment(_ cell: ComposeAttachmentTableViewCell)
func attachmentDescriptionChanged(_ cell: ComposeAttachmentTableViewCell) func attachmentDescriptionChanged(_ cell: ComposeAttachmentTableViewCell)
func composeAttachmentDescriptionHeightChanged(_ cell: ComposeAttachmentTableViewCell)
} }
class ComposeAttachmentTableViewCell: UITableViewCell { class ComposeAttachmentTableViewCell: UITableViewCell {
@ -23,6 +24,7 @@ class ComposeAttachmentTableViewCell: UITableViewCell {
@IBOutlet weak var assetImageView: UIImageView! @IBOutlet weak var assetImageView: UIImageView!
@IBOutlet weak var descriptionTextView: UITextView! @IBOutlet weak var descriptionTextView: UITextView!
@IBOutlet weak var descriptionTextViewHeightConstraint: NSLayoutConstraint!
@IBOutlet weak var descriptionPlaceholderLabel: UILabel! @IBOutlet weak var descriptionPlaceholderLabel: UILabel!
@IBOutlet weak var removeButton: UIButton! @IBOutlet weak var removeButton: UIButton!
@IBOutlet weak var activityIndicator: UIActivityIndicatorView! @IBOutlet weak var activityIndicator: UIActivityIndicatorView!
@ -142,6 +144,7 @@ class ComposeAttachmentTableViewCell: UITableViewCell {
override func prepareForReuse() { override func prepareForReuse() {
super.prepareForReuse() super.prepareForReuse()
assetImageView.image = nil assetImageView.image = nil
descriptionTextViewHeightConstraint.constant = 80
} }
@IBAction func removeButtonPressed(_ sender: Any) { @IBAction func removeButtonPressed(_ sender: Any) {
@ -162,5 +165,12 @@ extension ComposeAttachmentTableViewCell: UITextViewDelegate {
attachment.attachmentDescription = textView.text attachment.attachmentDescription = textView.text
updateDescriptionPlaceholderLabel() updateDescriptionPlaceholderLabel()
delegate?.attachmentDescriptionChanged(self) 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)
}
} }
} }

View File

@ -36,6 +36,9 @@
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="cwP-Eh-5dJ"> <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="cwP-Eh-5dJ">
<rect key="frame" x="84" y="0.0" width="194" height="80"/> <rect key="frame" x="84" y="0.0" width="194" height="80"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="80" id="6aZ-w8-j9n"/>
</constraints>
<color key="textColor" systemColor="labelColor" cocoaTouchSystemColor="darkTextColor"/> <color key="textColor" systemColor="labelColor" cocoaTouchSystemColor="darkTextColor"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/> <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
@ -79,6 +82,7 @@
<outlet property="assetImageView" destination="GLY-o8-47z" id="hZH-ur-m4z"/> <outlet property="assetImageView" destination="GLY-o8-47z" id="hZH-ur-m4z"/>
<outlet property="descriptionPlaceholderLabel" destination="h6T-x4-yzl" id="jBe-R0-Sfn"/> <outlet property="descriptionPlaceholderLabel" destination="h6T-x4-yzl" id="jBe-R0-Sfn"/>
<outlet property="descriptionTextView" destination="cwP-Eh-5dJ" id="pxJ-zF-GKC"/> <outlet property="descriptionTextView" destination="cwP-Eh-5dJ" id="pxJ-zF-GKC"/>
<outlet property="descriptionTextViewHeightConstraint" destination="6aZ-w8-j9n" id="ees-sT-Trc"/>
<outlet property="removeButton" destination="Lvf-I9-aV3" id="3qk-Zr-je1"/> <outlet property="removeButton" destination="Lvf-I9-aV3" id="3qk-Zr-je1"/>
</connections> </connections>
<point key="canvasLocation" x="107" y="181"/> <point key="canvasLocation" x="107" y="181"/>