Tweak generic attachment view widths.

pull/1/head
Matthew Chen 7 years ago
parent 2559b7b8fd
commit d8108c5ea8

@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)createContents; - (void)createContents;
+ (CGFloat)bubbleHeight; - (CGSize)measureSizeWithMaxMessageWidth:(CGFloat)maxMessageWidth;
@end @end

@ -20,6 +20,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) TSAttachmentStream *attachmentStream; @property (nonatomic) TSAttachmentStream *attachmentStream;
@property (nonatomic) BOOL isIncoming; @property (nonatomic) BOOL isIncoming;
@property (nonatomic) UILabel *topLabel;
@property (nonatomic) UILabel *bottomLabel;
@end @end
@ -51,38 +53,36 @@ NS_ASSUME_NONNULL_BEGIN
return 8.f; return 8.f;
} }
+ (CGFloat)vMargin - (CGFloat)vMargin
{ {
return 0.f; 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 + CGFloat labelsHeight = ([OWSGenericAttachmentView topLabelFont].lineHeight +
[OWSGenericAttachmentView bottomLabelFont].lineHeight + [OWSGenericAttachmentView labelVSpacing]); [OWSGenericAttachmentView bottomLabelFont].lineHeight + [OWSGenericAttachmentView labelVSpacing]);
CGFloat contentHeight = MAX(iconHeight, labelsHeight); CGFloat contentHeight = MAX(self.iconHeight, labelsHeight);
return contentHeight + self.vMargin * 2; result.height = contentHeight + self.vMargin * 2;
}
- (CGFloat)bubbleHeight CGFloat labelsWidth
{ = MAX([self.topLabel sizeThatFits:CGSizeZero].width, [self.bottomLabel sizeThatFits:CGSizeZero].width);
return [OWSGenericAttachmentView bubbleHeight]; 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 - (CGFloat)iconHeight
{ {
return [OWSGenericAttachmentView iconHeight]; return 48.f;
} }
- (UIColor *)bubbleBackgroundColor - (UIColor *)bubbleBackgroundColor
@ -111,6 +111,7 @@ NS_ASSUME_NONNULL_BEGIN
// attachment_file // attachment_file
UIImage *image = [UIImage imageNamed:@"generic-attachment"]; UIImage *image = [UIImage imageNamed:@"generic-attachment"];
OWSAssert(image); OWSAssert(image);
OWSAssert(image.size.width == self.iconWidth);
OWSAssert(image.size.height == self.iconHeight); OWSAssert(image.size.height == self.iconHeight);
UIImageView *imageView = [UIImageView new]; UIImageView *imageView = [UIImageView new];
imageView.image = image; imageView.image = image;
@ -132,6 +133,7 @@ NS_ASSUME_NONNULL_BEGIN
topText = NSLocalizedString(@"GENERIC_ATTACHMENT_LABEL", @"A label for generic attachments."); topText = NSLocalizedString(@"GENERIC_ATTACHMENT_LABEL", @"A label for generic attachments.");
} }
UILabel *topLabel = [UILabel new]; UILabel *topLabel = [UILabel new];
self.topLabel = topLabel;
topLabel.text = topText; topLabel.text = topText;
topLabel.textColor = textColor; topLabel.textColor = textColor;
topLabel.lineBreakMode = NSLineBreakByTruncatingMiddle; topLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
@ -144,6 +146,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(!error); OWSAssert(!error);
NSString *bottomText = [OWSFormat formatFileSize:fileSize]; NSString *bottomText = [OWSFormat formatFileSize:fileSize];
UILabel *bottomLabel = [UILabel new]; UILabel *bottomLabel = [UILabel new];
self.bottomLabel = bottomLabel;
bottomLabel.text = bottomText; bottomLabel.text = bottomText;
bottomLabel.textColor = [textColor colorWithAlphaComponent:0.85f]; bottomLabel.textColor = [textColor colorWithAlphaComponent:0.85f];
bottomLabel.lineBreakMode = NSLineBreakByTruncatingMiddle; bottomLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;

@ -1044,9 +1044,14 @@ NS_ASSUME_NONNULL_BEGIN
case OWSMessageCellType_Audio: case OWSMessageCellType_Audio:
result = CGSizeMake(maxMessageWidth, OWSAudioMessageView.bubbleHeight); result = CGSizeMake(maxMessageWidth, OWSAudioMessageView.bubbleHeight);
break; break;
case OWSMessageCellType_GenericAttachment: case OWSMessageCellType_GenericAttachment: {
result = CGSizeMake(maxMessageWidth, [OWSGenericAttachmentView bubbleHeight]); OWSAssert(self.viewItem.attachmentStream);
OWSGenericAttachmentView *attachmentView =
[[OWSGenericAttachmentView alloc] initWithAttachment:self.attachmentStream isIncoming:self.isIncoming];
[attachmentView createContents];
result = [attachmentView measureSizeWithMaxMessageWidth:maxMessageWidth];
break; break;
}
case OWSMessageCellType_DownloadingAttachment: case OWSMessageCellType_DownloadingAttachment:
result = CGSizeMake(200, [AttachmentPointerView measureHeight]); result = CGSizeMake(200, [AttachmentPointerView measureHeight]);
break; break;

Loading…
Cancel
Save