From 1125e2ac99a1052b2e0735058b040f920059d43b Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 16 Jun 2017 16:06:39 -0400 Subject: [PATCH] System messsages can show timestamp added the JSQCollectionViewCell cellTopLabel to the system message layout // FREEBIE --- .../ConversationView/MessagesViewController.m | 3 ++ Signal/src/views/OWSSystemMessageCell.m | 35 +++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m index 42cda74c6..d8d85c7f6 100644 --- a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m +++ b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m @@ -1723,6 +1723,9 @@ typedef enum : NSUInteger { [self.collectionView dequeueReusableCellWithReuseIdentifier:[OWSSystemMessageCell cellReuseIdentifier] forIndexPath:indexPath]; [cell configureWithInteraction:interaction]; + cell.cellTopLabel.attributedText = + [self collectionView:self.collectionView attributedTextForCellTopLabelAtIndexPath:indexPath]; + cell.systemMessageCellDelegate = self; return cell; diff --git a/Signal/src/views/OWSSystemMessageCell.m b/Signal/src/views/OWSSystemMessageCell.m index 0e72a5a88..43cf814e9 100644 --- a/Signal/src/views/OWSSystemMessageCell.m +++ b/Signal/src/views/OWSSystemMessageCell.m @@ -24,6 +24,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) UIImageView *imageView; @property (nonatomic) UILabel *titleLabel; +@property (nonatomic) UILabel *cellTopLabel; @end @@ -31,6 +32,9 @@ NS_ASSUME_NONNULL_BEGIN @implementation OWSSystemMessageCell +// override from JSQMessagesCollectionViewCell +@synthesize cellTopLabel = _cellTopLabel; + // `[UIView init]` invokes `[self initWithFrame:...]`. - (instancetype)initWithFrame:(CGRect)frame { @@ -49,6 +53,12 @@ NS_ASSUME_NONNULL_BEGIN self.backgroundColor = [UIColor whiteColor]; + self.cellTopLabel = [UILabel new]; + self.cellTopLabel.textAlignment = NSTextAlignmentCenter; + self.cellTopLabel.font = self.topLabelFont; + self.cellTopLabel.textColor = [UIColor lightGrayColor]; + [self.contentView addSubview:self.cellTopLabel]; + self.imageView = [UIImageView new]; [self.contentView addSubview:self.imageView]; @@ -84,6 +94,11 @@ NS_ASSUME_NONNULL_BEGIN [self setNeedsLayout]; } +- (UIFont *)topLabelFont +{ + return [UIFont boldSystemFontOfSize:12.0f]; +} + - (UIColor *)textColor { return [UIColor colorWithRGBHex:0x303030]; @@ -227,6 +242,12 @@ NS_ASSUME_NONNULL_BEGIN return 20.f; } +/// The default layout spacing for the top label (e.g. timestamp) feels a little too close for the system messages. +- (CGFloat)topLabelBottomMargin +{ + return 4.f; +} + - (void)layoutSubviews { [super layoutSubviews]; @@ -235,12 +256,19 @@ NS_ASSUME_NONNULL_BEGIN CGSize titleSize = [self.titleLabel sizeThatFits:CGSizeMake(maxTitleWidth, CGFLOAT_MAX)]; CGFloat contentWidth = ([self iconSize] + [self hSpacing] + titleSize.width); + + CGSize topLabelSize = [self.cellTopLabel sizeThatFits:CGSizeMake(self.contentView.width, CGFLOAT_MAX)]; + self.cellTopLabel.frame = CGRectMake(0, 0, self.contentView.frame.size.width, topLabelSize.height); + + CGFloat topLabelSpacing = topLabelSize.height + [self topLabelBottomMargin]; + self.imageView.frame = CGRectMake(round((self.contentView.width - contentWidth) * 0.5f), - round((self.contentView.height - [self iconSize]) * 0.5f), + round((self.contentView.height - [self iconSize] + topLabelSpacing) * 0.5f), [self iconSize], [self iconSize]); + self.titleLabel.frame = CGRectMake(round(self.imageView.right + [self hSpacing]), - round((self.contentView.height - titleSize.height) * 0.5f), + round((self.contentView.height - titleSize.height + topLabelSpacing) * 0.5f), ceil(titleSize.width + 1.f), ceil(titleSize.height + 1.f)); } @@ -254,9 +282,12 @@ NS_ASSUME_NONNULL_BEGIN [self applyTitleForInteraction:interaction label:self.titleLabel]; CGFloat maxTitleWidth = (collectionViewWidth - ([self hMargin] * 2.f + [self hSpacing] + [self iconSize])); CGSize titleSize = [self.titleLabel sizeThatFits:CGSizeMake(maxTitleWidth, CGFLOAT_MAX)]; + CGFloat contentHeight = ceil(MAX([self iconSize], titleSize.height)); result.height += contentHeight; + result.height += [self topLabelBottomMargin]; + return result; }