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;
+ (CGFloat)bubbleHeight;
- (CGSize)measureSizeWithMaxMessageWidth:(CGFloat)maxMessageWidth;
@end

@ -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;

@ -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;

Loading…
Cancel
Save