Browse Source

quote preview image shall not occupy space if no image is set

cyberta 4 years ago
parent
commit
7aac1dea0b

+ 1 - 1
deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift

@@ -321,7 +321,7 @@ public class BaseMessageCell: UITableViewCell {
             quoteView.quote.text = quoteText
 
             if let quoteMsg = msg.quoteMessage {
-                quoteView.imagePreview.image = quoteMsg.image
+                quoteView.setImagePreview(quoteMsg.image)
                 if quoteMsg.isForwarded {
                     quoteView.senderTitle.text = String.localized("forwarded_message")
                     quoteView.senderTitle.textColor = DcColors.grayDateColor

+ 16 - 2
deltachat-ios/Chat/Views/QuoteView.swift

@@ -30,7 +30,7 @@ public class QuoteView: UIView {
         return view
     }()
 
-    public lazy var imagePreview: UIImageView = {
+    private lazy var imagePreview: UIImageView = {
         let view = UIImageView()
         view.translatesAutoresizingMaskIntoConstraints = false
         view.contentMode = .scaleAspectFill
@@ -39,6 +39,8 @@ public class QuoteView: UIView {
         return view
     }()
 
+    private var imageWidthConstraint: NSLayoutConstraint?
+
     init() {
         super.init(frame: .zero)
         setupSubviews()
@@ -58,7 +60,6 @@ public class QuoteView: UIView {
         addConstraints([
             imagePreview.constraintAlignTrailingTo(self, paddingTrailing: 16),
             imagePreview.constraintHeightTo(36),
-            imagePreview.constraintWidthTo(36),
             imagePreview.constraintCenterYTo(citeBar),
             imagePreview.constraintAlignTopMaxTo(self),
             senderTitle.constraintAlignTopTo(self),
@@ -73,6 +74,8 @@ public class QuoteView: UIView {
             citeBar.constraintAlignBottomTo(quote, paddingBottom: 2),
             citeBar.constraintWidthTo(3),
         ])
+        imageWidthConstraint = imagePreview.constraintWidthTo(0)
+        imageWidthConstraint?.isActive = true
     }
 
     public func configureAccessibilityLabel() -> String {
@@ -98,5 +101,16 @@ public class QuoteView: UIView {
         senderTitle.attributedText = nil
         citeBar.backgroundColor = DcColors.grayDateColor
         imagePreview.image = nil
+        imageWidthConstraint?.constant = 0
+    }
+
+    public func setImagePreview(_ image: UIImage?) {
+        if let image = image {
+            imageWidthConstraint?.constant = 36
+            imagePreview.image = image
+        } else {
+            imageWidthConstraint?.constant = 0
+        }
+
     }
 }