From d8108c5ea8140bd4192b83ddaa8087e15f97c0bf Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 29 Jun 2018 09:54:22 -0400 Subject: [PATCH] Tweak generic attachment view widths. --- .../Cells/OWSGenericAttachmentView.h | 2 +- .../Cells/OWSGenericAttachmentView.m | 35 ++++++++++--------- .../Cells/OWSMessageBubbleView.m | 9 +++-- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.h b/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.h index fac8da3f6..0ed2cf037 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.h +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.h @@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)createContents; -+ (CGFloat)bubbleHeight; +- (CGSize)measureSizeWithMaxMessageWidth:(CGFloat)maxMessageWidth; @end diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m index fbde10c75..80144480d 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m @@ -20,6 +20,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) TSAttachmentStream *attachmentStream; @property (nonatomic) BOOL isIncoming; +@property (nonatomic) UILabel *topLabel; +@property (nonatomic) UILabel *bottomLabel; @end @@ -51,38 +53,36 @@ NS_ASSUME_NONNULL_BEGIN return 8.f; } -+ (CGFloat)vMargin +- (CGFloat)vMargin { return 0.f; } -- (CGFloat)vMargin +- (CGSize)measureSizeWithMaxMessageWidth:(CGFloat)maxMessageWidth { - return [OWSGenericAttachmentView vMargin]; -} + CGSize result = CGSizeZero; -+ (CGFloat)bubbleHeight -{ - CGFloat iconHeight = self.iconHeight; CGFloat labelsHeight = ([OWSGenericAttachmentView topLabelFont].lineHeight + [OWSGenericAttachmentView bottomLabelFont].lineHeight + [OWSGenericAttachmentView labelVSpacing]); - CGFloat contentHeight = MAX(iconHeight, labelsHeight); - return contentHeight + self.vMargin * 2; -} + CGFloat contentHeight = MAX(self.iconHeight, labelsHeight); + result.height = contentHeight + self.vMargin * 2; -- (CGFloat)bubbleHeight -{ - return [OWSGenericAttachmentView bubbleHeight]; + CGFloat labelsWidth + = MAX([self.topLabel sizeThatFits:CGSizeZero].width, [self.bottomLabel sizeThatFits:CGSizeZero].width); + CGFloat contentWidth = (self.iconWidth + labelsWidth + self.hSpacing); + result.width = MIN(maxMessageWidth, contentWidth + self.hMargin * 2); + + return CGSizeCeil(result); } -+ (CGFloat)iconHeight +- (CGFloat)iconWidth { - return 48.f; + return 36.f; } - (CGFloat)iconHeight { - return [OWSGenericAttachmentView iconHeight]; + return 48.f; } - (UIColor *)bubbleBackgroundColor @@ -111,6 +111,7 @@ NS_ASSUME_NONNULL_BEGIN // attachment_file UIImage *image = [UIImage imageNamed:@"generic-attachment"]; OWSAssert(image); + OWSAssert(image.size.width == self.iconWidth); OWSAssert(image.size.height == self.iconHeight); UIImageView *imageView = [UIImageView new]; imageView.image = image; @@ -132,6 +133,7 @@ NS_ASSUME_NONNULL_BEGIN topText = NSLocalizedString(@"GENERIC_ATTACHMENT_LABEL", @"A label for generic attachments."); } UILabel *topLabel = [UILabel new]; + self.topLabel = topLabel; topLabel.text = topText; topLabel.textColor = textColor; topLabel.lineBreakMode = NSLineBreakByTruncatingMiddle; @@ -144,6 +146,7 @@ NS_ASSUME_NONNULL_BEGIN OWSAssert(!error); NSString *bottomText = [OWSFormat formatFileSize:fileSize]; UILabel *bottomLabel = [UILabel new]; + self.bottomLabel = bottomLabel; bottomLabel.text = bottomText; bottomLabel.textColor = [textColor colorWithAlphaComponent:0.85f]; bottomLabel.lineBreakMode = NSLineBreakByTruncatingMiddle; diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m index d79b6aec6..68c9cb572 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m @@ -1044,9 +1044,14 @@ NS_ASSUME_NONNULL_BEGIN case OWSMessageCellType_Audio: result = CGSizeMake(maxMessageWidth, OWSAudioMessageView.bubbleHeight); break; - case OWSMessageCellType_GenericAttachment: - result = CGSizeMake(maxMessageWidth, [OWSGenericAttachmentView bubbleHeight]); + case OWSMessageCellType_GenericAttachment: { + OWSAssert(self.viewItem.attachmentStream); + OWSGenericAttachmentView *attachmentView = + [[OWSGenericAttachmentView alloc] initWithAttachment:self.attachmentStream isIncoming:self.isIncoming]; + [attachmentView createContents]; + result = [attachmentView measureSizeWithMaxMessageWidth:maxMessageWidth]; break; + } case OWSMessageCellType_DownloadingAttachment: result = CGSizeMake(200, [AttachmentPointerView measureHeight]); break;