From 59a3d736bfa8476c6a89d0adeef83cf4a978a9cb Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 13 Apr 2018 15:10:16 -0400 Subject: [PATCH] Respond to CR. --- .../ConversationView/Cells/OWSMessageBubbleView.m | 1 + .../ConversationView/Cells/OWSMessageCell.m | 1 + .../ConversationView/Cells/OWSQuotedMessageView.m | 1 + Signal/src/views/QuotedReplyPreview.swift | 15 ++++++++++++--- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m index 0fefa6f29..0a678bf2e 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m @@ -54,6 +54,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)commontInit { + // Ensure only called once. OWSAssert(!self.bodyTextView); _viewConstraints = [NSMutableArray new]; diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m index c2f741518..cd4171307 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m @@ -48,6 +48,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)commontInit { + // Ensure only called once. OWSAssert(!self.messageBubbleView); _viewConstraints = [NSMutableArray new]; diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSQuotedMessageView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSQuotedMessageView.m index b2866144a..b9dc4aeb9 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSQuotedMessageView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSQuotedMessageView.m @@ -112,6 +112,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)createContents { + // Ensure only called once. OWSAssert(!self.boundsStrokeView); self.backgroundColor = [UIColor whiteColor]; diff --git a/Signal/src/views/QuotedReplyPreview.swift b/Signal/src/views/QuotedReplyPreview.swift index 0608b5636..21f1b7b8e 100644 --- a/Signal/src/views/QuotedReplyPreview.swift +++ b/Signal/src/views/QuotedReplyPreview.swift @@ -14,7 +14,7 @@ class QuotedReplyPreview: UIView { public weak var delegate: QuotedReplyPreviewDelegate? private let quotedReply: OWSQuotedReplyModel - private var quotedMessageView: OWSQuotedMessageView + private var quotedMessageView: OWSQuotedMessageView? private var heightConstraint: NSLayoutConstraint! required init?(coder aDecoder: NSCoder) { @@ -23,7 +23,6 @@ class QuotedReplyPreview: UIView { init(quotedReply: OWSQuotedReplyModel) { self.quotedReply = quotedReply - self.quotedMessageView = OWSQuotedMessageView(forPreview: quotedReply) super.init(frame: .zero) @@ -37,6 +36,12 @@ class QuotedReplyPreview: UIView { func updateContents() { subviews.forEach { $0.removeFromSuperview() } + // We instantiate quotedMessageView late to ensure that it is updated + // every time contentSizeCategoryDidChange (i.e. when dynamic type + // sizes changes). + let quotedMessageView = OWSQuotedMessageView(forPreview: quotedReply) + self.quotedMessageView = quotedMessageView + quotedMessageView.backgroundColor = .clear let cancelButton: UIButton = UIButton(type: .custom) @@ -70,7 +75,11 @@ class QuotedReplyPreview: UIView { // MARK: Sizing func updateHeight() { - let size = self.quotedMessageView.size(forMaxWidth: CGFloat.infinity) + guard let quotedMessageView = quotedMessageView else { + owsFail("\(logTag) missing quotedMessageView") + return + } + let size = quotedMessageView.size(forMaxWidth: CGFloat.infinity) self.heightConstraint.constant = size.height }