From 074c1bf43f4718241acc18e744229cbb08b601d0 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 11 Feb 2021 09:53:27 +1100 Subject: [PATCH] Fix constraint issues --- Session/Conversations V2/ConversationVC.swift | 1 - .../Message Cells/Content Views/QuoteView.swift | 9 ++++++--- .../Message Cells/VisibleMessageCell.swift | 9 ++++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Session/Conversations V2/ConversationVC.swift b/Session/Conversations V2/ConversationVC.swift index 16ab9e5e5..bbffc9b03 100644 --- a/Session/Conversations V2/ConversationVC.swift +++ b/Session/Conversations V2/ConversationVC.swift @@ -9,7 +9,6 @@ // • Resending failed messages // • Linkification // • Link previews -// • Fix constraints and warnings final class ConversationVC : BaseVC, ConversationViewModelDelegate, UITableViewDataSource, UITableViewDelegate { let thread: TSThread diff --git a/Session/Conversations V2/Message Cells/Content Views/QuoteView.swift b/Session/Conversations V2/Message Cells/Content Views/QuoteView.swift index ad8d1416c..d28cae013 100644 --- a/Session/Conversations V2/Message Cells/Content Views/QuoteView.swift +++ b/Session/Conversations V2/Message Cells/Content Views/QuoteView.swift @@ -188,6 +188,7 @@ final class QuoteView : UIView { } let bodyLabelSize = bodyLabel.systemLayoutSizeFitting(availableSpace) // Label stack view + var authorLabelHeight: CGFloat? if isGroupThread { let authorLabel = UILabel() authorLabel.lineBreakMode = .byTruncatingTail @@ -195,6 +196,8 @@ final class QuoteView : UIView { authorLabel.textColor = textColor authorLabel.font = .boldSystemFont(ofSize: Values.smallFontSize) let authorLabelSize = authorLabel.systemLayoutSizeFitting(availableSpace) + authorLabel.set(.height, to: authorLabelSize.height) + authorLabelHeight = authorLabelSize.height let labelStackView = UIStackView(arrangedSubviews: [ authorLabel, bodyLabel ]) labelStackView.axis = .vertical labelStackView.spacing = labelStackViewSpacing @@ -207,7 +210,8 @@ final class QuoteView : UIView { } // Cancel button let cancelButton = UIButton(type: .custom) - cancelButton.setImage(UIImage(named: "X")?.withTint(Colors.text), for: UIControl.State.normal) + let tint: UIColor = isLightMode ? .black : .white + cancelButton.setImage(UIImage(named: "X")?.withTint(tint), for: UIControl.State.normal) cancelButton.set(.width, to: cancelButtonSize) cancelButton.set(.height, to: cancelButtonSize) cancelButton.addTarget(self, action: #selector(cancel), for: UIControl.Event.touchUpInside) @@ -218,12 +222,11 @@ final class QuoteView : UIView { bodyLabel.set(.width, to: bodyLabelSize.width) } let bodyLabelHeight = bodyLabelSize.height.clamp(0, maxBodyLabelHeight) - let authorLabelHeight: CGFloat = 14.33 let contentViewHeight: CGFloat if hasAttachments { contentViewHeight = thumbnailSize + 8 // Add a small amount of spacing above and below the thumbnail } else { - if isGroupThread { + if let authorLabelHeight = authorLabelHeight { // Group thread contentViewHeight = bodyLabelHeight + (authorLabelHeight + labelStackViewSpacing) + 2 * labelStackViewVMargin } else { contentViewHeight = bodyLabelHeight + 2 * smallSpacing diff --git a/Session/Conversations V2/Message Cells/VisibleMessageCell.swift b/Session/Conversations V2/Message Cells/VisibleMessageCell.swift index b81d62f6e..9af8ae482 100644 --- a/Session/Conversations V2/Message Cells/VisibleMessageCell.swift +++ b/Session/Conversations V2/Message Cells/VisibleMessageCell.swift @@ -5,6 +5,7 @@ final class VisibleMessageCell : MessageCell { var mediaTextOverlayView: MediaTextOverlayView? // Constraints private lazy var headerViewTopConstraint = headerView.pin(.top, to: .top, of: self, withInset: 1) + private lazy var authorLabelHeightConstraint = authorLabel.set(.height, to: 0) private lazy var profilePictureViewLeftConstraint = profilePictureView.pin(.left, to: .left, of: self, withInset: VisibleMessageCell.groupThreadHSpacing) private lazy var profilePictureViewWidthConstraint = profilePictureView.set(.width, to: Values.verySmallProfilePictureSize) private lazy var bubbleViewLeftConstraint1 = bubbleView.pin(.left, to: .right, of: profilePictureView, withInset: VisibleMessageCell.groupThreadHSpacing) @@ -79,6 +80,7 @@ final class VisibleMessageCell : MessageCell { private static let authorLabelBottomSpacing: CGFloat = 4 private static let groupThreadHSpacing: CGFloat = 12 private static let profilePictureSize = Values.verySmallProfilePictureSize + private static let authorLabelInset: CGFloat = 12 static let smallCornerRadius: CGFloat = 4 static let largeCornerRadius: CGFloat = 18 static let contactThreadHSpacing = Values.mediumSpacing @@ -108,6 +110,7 @@ final class VisibleMessageCell : MessageCell { headerView.pin([ UIView.HorizontalEdge.left, UIView.HorizontalEdge.right ], to: self) // Author label addSubview(authorLabel) + authorLabelHeightConstraint.isActive = true authorLabel.pin(.top, to: .bottom, of: headerView) // Profile picture view addSubview(profilePictureView) @@ -130,7 +133,7 @@ final class VisibleMessageCell : MessageCell { messageStatusImageViewWidthConstraint.isActive = true messageStatusImageViewHeightConstraint.isActive = true // Remaining constraints - authorLabel.pin(.left, to: .left, of: bubbleView, withInset: 12) + authorLabel.pin(.left, to: .left, of: bubbleView, withInset: VisibleMessageCell.authorLabelInset) } override func setUpGestureRecognizers() { @@ -179,6 +182,10 @@ final class VisibleMessageCell : MessageCell { authorLabel.textColor = Colors.text authorLabel.isHidden = (viewItem.senderName == nil) authorLabel.text = viewItem.senderName?.string // Will only be set if it should be shown + let authorLabelAvailableWidth = VisibleMessageCell.getMaxWidth(for: viewItem) - 2 * VisibleMessageCell.authorLabelInset + let authorLabelAvailableSpace = CGSize(width: authorLabelAvailableWidth, height: .greatestFiniteMagnitude) + let authorLabelSize = authorLabel.sizeThatFits(authorLabelAvailableSpace) + authorLabelHeightConstraint.constant = (viewItem.senderName != nil) ? authorLabelSize.height : 0 // Message status image view let (image, backgroundColor) = getMessageStatusImage(for: message) messageStatusImageView.image = image