Эх сурвалжийг харах

add fullMessageButton to BaseMessageCell

cyberta 4 жил өмнө
parent
commit
7731398677

+ 15 - 0
DcCore/DcCore/Extensions/UIView+Extensions.swift

@@ -180,6 +180,21 @@ public extension UIView {
         return constraint
         return constraint
     }
     }
 
 
+    func constraintToTopOf(_ view: UIView, paddingBottom: CGFloat = 0.0, priority: UILayoutPriority? = .none) -> NSLayoutConstraint {
+        let constraint = NSLayoutConstraint(
+            item: self,
+            attribute: .bottom,
+            relatedBy: .equal,
+            toItem: view,
+            attribute: .top,
+            multiplier: 1.0,
+            constant: -paddingBottom)
+        if let priority = priority {
+            constraint.priority = priority
+        }
+        return constraint
+    }
+
     func constraintToTrailingOf(_ view: UIView, paddingLeading: CGFloat = 0.0, priority: UILayoutPriority? = .none) -> NSLayoutConstraint {
     func constraintToTrailingOf(_ view: UIView, paddingLeading: CGFloat = 0.0, priority: UILayoutPriority? = .none) -> NSLayoutConstraint {
         let constraint = NSLayoutConstraint(
         let constraint = NSLayoutConstraint(
             item: self,
             item: self,

+ 35 - 5
deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift

@@ -10,10 +10,11 @@ public class BaseMessageCell: UITableViewCell {
     private var trailingConstraintCurrentSender: NSLayoutConstraint?
     private var trailingConstraintCurrentSender: NSLayoutConstraint?
     private var mainContentBelowTopLabelConstraint: NSLayoutConstraint?
     private var mainContentBelowTopLabelConstraint: NSLayoutConstraint?
     private var mainContentUnderTopLabelConstraint: NSLayoutConstraint?
     private var mainContentUnderTopLabelConstraint: NSLayoutConstraint?
-    private var mainContentAboveBottomLabelConstraint: NSLayoutConstraint?
+    private var mainContentAboveFullMessageBtnConstraint: NSLayoutConstraint?
     private var mainContentUnderBottomLabelConstraint: NSLayoutConstraint?
     private var mainContentUnderBottomLabelConstraint: NSLayoutConstraint?
     private var mainContentViewLeadingConstraint: NSLayoutConstraint?
     private var mainContentViewLeadingConstraint: NSLayoutConstraint?
     private var mainContentViewTrailingConstraint: NSLayoutConstraint?
     private var mainContentViewTrailingConstraint: NSLayoutConstraint?
+    private var fullMessageZeroHeightConstraint: NSLayoutConstraint?
 
 
     public var mainContentViewHorizontalPadding: CGFloat {
     public var mainContentViewHorizontalPadding: CGFloat {
         set {
         set {
@@ -42,7 +43,7 @@ public class BaseMessageCell: UITableViewCell {
     // if set to true bottomLabel overlaps the main content
     // if set to true bottomLabel overlaps the main content
     public var bottomCompactView: Bool {
     public var bottomCompactView: Bool {
         set {
         set {
-            mainContentAboveBottomLabelConstraint?.isActive = !newValue
+            mainContentAboveFullMessageBtnConstraint?.isActive = !newValue
             mainContentUnderBottomLabelConstraint?.isActive = newValue
             mainContentUnderBottomLabelConstraint?.isActive = newValue
             bottomLabel.backgroundColor = newValue ?
             bottomLabel.backgroundColor = newValue ?
                 UIColor(alpha: 200, red: 50, green: 50, blue: 50) :
                 UIColor(alpha: 200, red: 50, green: 50, blue: 50) :
@@ -53,6 +54,18 @@ public class BaseMessageCell: UITableViewCell {
         }
         }
     }
     }
 
 
+    public var isFullMessageButtonHidden: Bool {
+        set {
+            mainContentAboveFullMessageBtnConstraint?.constant = newValue ? -2 : 8
+            fullMessageButton.setTitle(newValue ? "" : String.localized("show_full_message"), for: .normal)
+            fullMessageZeroHeightConstraint?.isActive = newValue
+            fullMessageButton.isHidden = newValue
+        }
+        get {
+            return fullMessageButton.isHidden
+        }
+    }
+
     public weak var baseDelegate: BaseMessageCellDelegate?
     public weak var baseDelegate: BaseMessageCellDelegate?
 
 
     public lazy var quoteView: QuoteView = {
     public lazy var quoteView: QuoteView = {
@@ -113,6 +126,16 @@ public class BaseMessageCell: UITableViewCell {
         return view
         return view
     }()
     }()
 
 
+    lazy var fullMessageButton: UIButton = {
+        let button = UIButton()
+        button.translatesAutoresizingMaskIntoConstraints = false
+        button.setTitleColor(.systemBlue, for: .normal)
+        button.setTitleColor(.gray, for: .highlighted)
+        button.titleLabel?.lineBreakMode = .byWordWrapping
+        button.titleLabel?.textAlignment = .center
+        return button
+    }()
+
     lazy var bottomLabel: PaddingTextView = {
     lazy var bottomLabel: PaddingTextView = {
         let label = PaddingTextView()
         let label = PaddingTextView()
         label.translatesAutoresizingMaskIntoConstraints = false
         label.translatesAutoresizingMaskIntoConstraints = false
@@ -154,6 +177,7 @@ public class BaseMessageCell: UITableViewCell {
         contentView.addSubview(messageBackgroundContainer)
         contentView.addSubview(messageBackgroundContainer)
         messageBackgroundContainer.addSubview(mainContentView)
         messageBackgroundContainer.addSubview(mainContentView)
         messageBackgroundContainer.addSubview(topLabel)
         messageBackgroundContainer.addSubview(topLabel)
+        messageBackgroundContainer.addSubview(fullMessageButton)
         messageBackgroundContainer.addSubview(bottomLabel)
         messageBackgroundContainer.addSubview(bottomLabel)
         contentView.addSubview(avatarView)
         contentView.addSubview(avatarView)
 
 
@@ -165,11 +189,14 @@ public class BaseMessageCell: UITableViewCell {
             topLabel.constraintAlignTopTo(messageBackgroundContainer, paddingTop: 6),
             topLabel.constraintAlignTopTo(messageBackgroundContainer, paddingTop: 6),
             topLabel.constraintAlignLeadingTo(messageBackgroundContainer, paddingLeading: 8),
             topLabel.constraintAlignLeadingTo(messageBackgroundContainer, paddingLeading: 8),
             topLabel.constraintAlignTrailingMaxTo(messageBackgroundContainer, paddingTrailing: 8),
             topLabel.constraintAlignTrailingMaxTo(messageBackgroundContainer, paddingTrailing: 8),
-            bottomLabel.constraintAlignBottomTo(messageBackgroundContainer, paddingBottom: 6),
             messageBackgroundContainer.constraintAlignTopTo(contentView, paddingTop: 3),
             messageBackgroundContainer.constraintAlignTopTo(contentView, paddingTop: 3),
             messageBackgroundContainer.constraintAlignBottomTo(contentView, paddingBottom: 3),
             messageBackgroundContainer.constraintAlignBottomTo(contentView, paddingBottom: 3),
+            fullMessageButton.constraintAlignLeadingTo(messageBackgroundContainer, paddingLeading: 12),
+            fullMessageButton.constraintAlignTrailingTo(messageBackgroundContainer, paddingTrailing: 12),
             bottomLabel.constraintAlignLeadingMaxTo(messageBackgroundContainer, paddingLeading: 8),
             bottomLabel.constraintAlignLeadingMaxTo(messageBackgroundContainer, paddingLeading: 8),
-            bottomLabel.constraintAlignTrailingTo(messageBackgroundContainer, paddingTrailing: 8)
+            bottomLabel.constraintAlignTrailingTo(messageBackgroundContainer, paddingTrailing: 8),
+            bottomLabel.constraintToBottomOf(fullMessageButton, priority: .defaultHigh),
+            bottomLabel.constraintAlignBottomTo(messageBackgroundContainer, paddingBottom: 6)
         ])
         ])
 
 
         leadingConstraint = messageBackgroundContainer.constraintAlignLeadingTo(contentView, paddingLeading: 6)
         leadingConstraint = messageBackgroundContainer.constraintAlignLeadingTo(contentView, paddingLeading: 6)
@@ -185,11 +212,14 @@ public class BaseMessageCell: UITableViewCell {
 
 
         mainContentBelowTopLabelConstraint = mainContentView.constraintToBottomOf(topLabel, paddingTop: 6)
         mainContentBelowTopLabelConstraint = mainContentView.constraintToBottomOf(topLabel, paddingTop: 6)
         mainContentUnderTopLabelConstraint = mainContentView.constraintAlignTopTo(messageBackgroundContainer)
         mainContentUnderTopLabelConstraint = mainContentView.constraintAlignTopTo(messageBackgroundContainer)
-        mainContentAboveBottomLabelConstraint = bottomLabel.constraintToBottomOf(mainContentView, paddingTop: -2, priority: .defaultHigh)
+        mainContentAboveFullMessageBtnConstraint = fullMessageButton.constraintToBottomOf(mainContentView, paddingTop: 8, priority: .defaultHigh)
         mainContentUnderBottomLabelConstraint = mainContentView.constraintAlignBottomTo(messageBackgroundContainer, paddingBottom: 0, priority: .defaultHigh)
         mainContentUnderBottomLabelConstraint = mainContentView.constraintAlignBottomTo(messageBackgroundContainer, paddingBottom: 0, priority: .defaultHigh)
 
 
+        fullMessageZeroHeightConstraint = fullMessageButton.constraintHeightTo(0)
+
         topCompactView = false
         topCompactView = false
         bottomCompactView = false
         bottomCompactView = false
+        isFullMessageButtonHidden = false
         
         
 
 
         let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(onAvatarTapped))
         let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(onAvatarTapped))