Fix constraint issues

pull/347/head
Niels Andriesse 4 years ago
parent 1dc75f3a1d
commit 074c1bf43f

@ -9,7 +9,6 @@
// Resending failed messages // Resending failed messages
// Linkification // Linkification
// Link previews // Link previews
// Fix constraints and warnings
final class ConversationVC : BaseVC, ConversationViewModelDelegate, UITableViewDataSource, UITableViewDelegate { final class ConversationVC : BaseVC, ConversationViewModelDelegate, UITableViewDataSource, UITableViewDelegate {
let thread: TSThread let thread: TSThread

@ -188,6 +188,7 @@ final class QuoteView : UIView {
} }
let bodyLabelSize = bodyLabel.systemLayoutSizeFitting(availableSpace) let bodyLabelSize = bodyLabel.systemLayoutSizeFitting(availableSpace)
// Label stack view // Label stack view
var authorLabelHeight: CGFloat?
if isGroupThread { if isGroupThread {
let authorLabel = UILabel() let authorLabel = UILabel()
authorLabel.lineBreakMode = .byTruncatingTail authorLabel.lineBreakMode = .byTruncatingTail
@ -195,6 +196,8 @@ final class QuoteView : UIView {
authorLabel.textColor = textColor authorLabel.textColor = textColor
authorLabel.font = .boldSystemFont(ofSize: Values.smallFontSize) authorLabel.font = .boldSystemFont(ofSize: Values.smallFontSize)
let authorLabelSize = authorLabel.systemLayoutSizeFitting(availableSpace) let authorLabelSize = authorLabel.systemLayoutSizeFitting(availableSpace)
authorLabel.set(.height, to: authorLabelSize.height)
authorLabelHeight = authorLabelSize.height
let labelStackView = UIStackView(arrangedSubviews: [ authorLabel, bodyLabel ]) let labelStackView = UIStackView(arrangedSubviews: [ authorLabel, bodyLabel ])
labelStackView.axis = .vertical labelStackView.axis = .vertical
labelStackView.spacing = labelStackViewSpacing labelStackView.spacing = labelStackViewSpacing
@ -207,7 +210,8 @@ final class QuoteView : UIView {
} }
// Cancel button // Cancel button
let cancelButton = UIButton(type: .custom) 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(.width, to: cancelButtonSize)
cancelButton.set(.height, to: cancelButtonSize) cancelButton.set(.height, to: cancelButtonSize)
cancelButton.addTarget(self, action: #selector(cancel), for: UIControl.Event.touchUpInside) cancelButton.addTarget(self, action: #selector(cancel), for: UIControl.Event.touchUpInside)
@ -218,12 +222,11 @@ final class QuoteView : UIView {
bodyLabel.set(.width, to: bodyLabelSize.width) bodyLabel.set(.width, to: bodyLabelSize.width)
} }
let bodyLabelHeight = bodyLabelSize.height.clamp(0, maxBodyLabelHeight) let bodyLabelHeight = bodyLabelSize.height.clamp(0, maxBodyLabelHeight)
let authorLabelHeight: CGFloat = 14.33
let contentViewHeight: CGFloat let contentViewHeight: CGFloat
if hasAttachments { if hasAttachments {
contentViewHeight = thumbnailSize + 8 // Add a small amount of spacing above and below the thumbnail contentViewHeight = thumbnailSize + 8 // Add a small amount of spacing above and below the thumbnail
} else { } else {
if isGroupThread { if let authorLabelHeight = authorLabelHeight { // Group thread
contentViewHeight = bodyLabelHeight + (authorLabelHeight + labelStackViewSpacing) + 2 * labelStackViewVMargin contentViewHeight = bodyLabelHeight + (authorLabelHeight + labelStackViewSpacing) + 2 * labelStackViewVMargin
} else { } else {
contentViewHeight = bodyLabelHeight + 2 * smallSpacing contentViewHeight = bodyLabelHeight + 2 * smallSpacing

@ -5,6 +5,7 @@ final class VisibleMessageCell : MessageCell {
var mediaTextOverlayView: MediaTextOverlayView? var mediaTextOverlayView: MediaTextOverlayView?
// Constraints // Constraints
private lazy var headerViewTopConstraint = headerView.pin(.top, to: .top, of: self, withInset: 1) 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 profilePictureViewLeftConstraint = profilePictureView.pin(.left, to: .left, of: self, withInset: VisibleMessageCell.groupThreadHSpacing)
private lazy var profilePictureViewWidthConstraint = profilePictureView.set(.width, to: Values.verySmallProfilePictureSize) private lazy var profilePictureViewWidthConstraint = profilePictureView.set(.width, to: Values.verySmallProfilePictureSize)
private lazy var bubbleViewLeftConstraint1 = bubbleView.pin(.left, to: .right, of: profilePictureView, withInset: VisibleMessageCell.groupThreadHSpacing) 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 authorLabelBottomSpacing: CGFloat = 4
private static let groupThreadHSpacing: CGFloat = 12 private static let groupThreadHSpacing: CGFloat = 12
private static let profilePictureSize = Values.verySmallProfilePictureSize private static let profilePictureSize = Values.verySmallProfilePictureSize
private static let authorLabelInset: CGFloat = 12
static let smallCornerRadius: CGFloat = 4 static let smallCornerRadius: CGFloat = 4
static let largeCornerRadius: CGFloat = 18 static let largeCornerRadius: CGFloat = 18
static let contactThreadHSpacing = Values.mediumSpacing static let contactThreadHSpacing = Values.mediumSpacing
@ -108,6 +110,7 @@ final class VisibleMessageCell : MessageCell {
headerView.pin([ UIView.HorizontalEdge.left, UIView.HorizontalEdge.right ], to: self) headerView.pin([ UIView.HorizontalEdge.left, UIView.HorizontalEdge.right ], to: self)
// Author label // Author label
addSubview(authorLabel) addSubview(authorLabel)
authorLabelHeightConstraint.isActive = true
authorLabel.pin(.top, to: .bottom, of: headerView) authorLabel.pin(.top, to: .bottom, of: headerView)
// Profile picture view // Profile picture view
addSubview(profilePictureView) addSubview(profilePictureView)
@ -130,7 +133,7 @@ final class VisibleMessageCell : MessageCell {
messageStatusImageViewWidthConstraint.isActive = true messageStatusImageViewWidthConstraint.isActive = true
messageStatusImageViewHeightConstraint.isActive = true messageStatusImageViewHeightConstraint.isActive = true
// Remaining constraints // Remaining constraints
authorLabel.pin(.left, to: .left, of: bubbleView, withInset: 12) authorLabel.pin(.left, to: .left, of: bubbleView, withInset: VisibleMessageCell.authorLabelInset)
} }
override func setUpGestureRecognizers() { override func setUpGestureRecognizers() {
@ -179,6 +182,10 @@ final class VisibleMessageCell : MessageCell {
authorLabel.textColor = Colors.text authorLabel.textColor = Colors.text
authorLabel.isHidden = (viewItem.senderName == nil) authorLabel.isHidden = (viewItem.senderName == nil)
authorLabel.text = viewItem.senderName?.string // Will only be set if it should be shown 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 // Message status image view
let (image, backgroundColor) = getMessageStatusImage(for: message) let (image, backgroundColor) = getMessageStatusImage(for: message)
messageStatusImageView.image = image messageStatusImageView.image = image

Loading…
Cancel
Save