From 5807ba69ca2de628d00fe3ad2ed81468e9da6e99 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 9 Apr 2018 17:00:44 -0400 Subject: [PATCH] attempt 1: QMV doesn't have intrinsic content size, and requires a fixed width to compute it's size, which we don't currently have. // FREEBIE --- Signal/src/Signal-Bridging-Header.h | 1 + Signal/src/views/QuotedReplyPreview.swift | 122 +++++++++++----------- 2 files changed, 64 insertions(+), 59 deletions(-) diff --git a/Signal/src/Signal-Bridging-Header.h b/Signal/src/Signal-Bridging-Header.h index ac4265c58..a7775a9da 100644 --- a/Signal/src/Signal-Bridging-Header.h +++ b/Signal/src/Signal-Bridging-Header.h @@ -29,6 +29,7 @@ #import "OWSMessageCell.h" #import "OWSNavigationController.h" #import "OWSProgressView.h" +#import "OWSQuotedMessageView.h" #import "OWSWebRTCDataProtos.pb.h" #import "PinEntryView.h" #import "PrivacySettingsTableViewController.h" diff --git a/Signal/src/views/QuotedReplyPreview.swift b/Signal/src/views/QuotedReplyPreview.swift index dbe9ee0fe..34588b8de 100644 --- a/Signal/src/views/QuotedReplyPreview.swift +++ b/Signal/src/views/QuotedReplyPreview.swift @@ -20,6 +20,8 @@ class QuotedReplyPreview: UIView { init(quotedReply: OWSQuotedReplyModel) { super.init(frame: .zero) + let quotedMessageView = OWSQuotedMessageView(forPreview: quotedReply) + let isQuotingSelf = quotedReply.authorId == TSAccountManager.localNumber() // used for stripe and author @@ -29,40 +31,40 @@ class QuotedReplyPreview: UIView { // used for text and cancel let foregroundColor: UIColor = .darkGray - let authorLabel: UILabel = UILabel() - authorLabel.textColor = authorColor - if isQuotingSelf { - authorLabel.text = NSLocalizedString("MEDIA_GALLERY_SENDER_NAME_YOU", comment: "") - } else { - authorLabel.text = Environment.current().contactsManager.displayName(forPhoneIdentifier: quotedReply.authorId) - } - authorLabel.font = .ows_dynamicTypeHeadline - - let bodyLabel: UILabel = UILabel() - bodyLabel.textColor = foregroundColor - bodyLabel.font = .ows_dynamicTypeFootnote - - bodyLabel.text = { - if let contentType = quotedReply.contentType { - let emoji = TSAttachmentStream.emoji(forMimeType: contentType) - return "\(emoji) \(quotedReply.body ?? "")" - } else { - return quotedReply.body - } - }() - - let thumbnailView: UIView? = { - if let image = quotedReply.thumbnailImage { - let imageView = UIImageView(image: image) - imageView.contentMode = .scaleAspectFill - imageView.autoPinToSquareAspectRatio() - imageView.layer.cornerRadius = 3.0 - imageView.clipsToBounds = true - - return imageView - } - return nil - }() +// let authorLabel: UILabel = UILabel() +// authorLabel.textColor = authorColor +// if isQuotingSelf { +// authorLabel.text = NSLocalizedString("MEDIA_GALLERY_SENDER_NAME_YOU", comment: "") +// } else { +// authorLabel.text = Environment.current().contactsManager.displayName(forPhoneIdentifier: quotedReply.authorId) +// } +// authorLabel.font = .ows_dynamicTypeHeadline +// +// let bodyLabel: UILabel = UILabel() +// bodyLabel.textColor = foregroundColor +// bodyLabel.font = .ows_dynamicTypeFootnote +// +// bodyLabel.text = { +// if let contentType = quotedReply.contentType { +// let emoji = TSAttachmentStream.emoji(forMimeType: contentType) +// return "\(emoji) \(quotedReply.body ?? "")" +// } else { +// return quotedReply.body +// } +// }() +// +// let thumbnailView: UIView? = { +// if let image = quotedReply.thumbnailImage { +// let imageView = UIImageView(image: image) +// imageView.contentMode = .scaleAspectFill +// imageView.autoPinToSquareAspectRatio() +// imageView.layer.cornerRadius = 3.0 +// imageView.clipsToBounds = true +// +// return imageView +// } +// return nil +// }() let cancelButton: UIButton = UIButton(type: .custom) // FIXME proper image asset/size @@ -71,35 +73,37 @@ class QuotedReplyPreview: UIView { cancelButton.imageView?.tintColor = foregroundColor cancelButton.addTarget(self, action: #selector(didTapCancel), for: .touchUpInside) - let quoteStripe: UIView = UIView() - quoteStripe.backgroundColor = authorColor - - let textColumn = UIView.container() - textColumn.addSubview(authorLabel) - textColumn.addSubview(bodyLabel) - - authorLabel.autoPinEdges(toSuperviewMarginsExcludingEdge: .bottom) - authorLabel.autoPinEdge(.bottom, to: .top, of: bodyLabel) - bodyLabel.autoPinEdges(toSuperviewMarginsExcludingEdge: .top) +// let quoteStripe: UIView = UIView() +// quoteStripe.backgroundColor = authorColor +// +// let textColumn = UIView.container() +// textColumn.addSubview(authorLabel) +// textColumn.addSubview(bodyLabel) +// +// authorLabel.autoPinEdges(toSuperviewMarginsExcludingEdge: .bottom) +// authorLabel.autoPinEdge(.bottom, to: .top, of: bodyLabel) +// bodyLabel.autoPinEdges(toSuperviewMarginsExcludingEdge: .top) +// +// let contentViews: [UIView] = [textColumn, thumbnailView, cancelButton].flatMap { return $0 } - let contentViews: [UIView] = [textColumn, thumbnailView, cancelButton].flatMap { return $0 } + let contentViews: [UIView] = [quotedMessageView, cancelButton] let contentRow = UIStackView(arrangedSubviews: contentViews) contentRow.axis = .horizontal self.addSubview(contentRow) - self.addSubview(quoteStripe) - - // Layout - - let kQuoteStripeWidth: CGFloat = 4 - self.layoutMargins = UIEdgeInsets(top: 6, - left: kQuoteStripeWidth + 8, - bottom: 2, - right: 4) - - quoteStripe.autoPinEdge(toSuperviewEdge: .leading) - quoteStripe.autoPinHeightToSuperview() - quoteStripe.autoSetDimension(.width, toSize: kQuoteStripeWidth) - +// self.addSubview(quoteStripe) +// +// // Layout +// +// let kQuoteStripeWidth: CGFloat = 4 +// self.layoutMargins = UIEdgeInsets(top: 6, +// left: kQuoteStripeWidth + 8, +// bottom: 2, +// right: 4) +// +// quoteStripe.autoPinEdge(toSuperviewEdge: .leading) +// quoteStripe.autoPinHeightToSuperview() +// quoteStripe.autoSetDimension(.width, toSize: kQuoteStripeWidth) +// contentRow.autoPinEdgesToSuperviewMargins() cancelButton.autoSetDimensions(to: CGSize(width: 40, height: 40))