From dab8ddb37d221cff61cc445349d75bf34c4eac04 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 31 May 2017 21:12:27 -0400 Subject: [PATCH] Rework appearance of the unread indicator. // FREEBIE --- .../ConversationView/MessagesViewController.m | 47 +++++++ Signal/src/views/OWSUnreadIndicatorCell.m | 119 +++++++++++------- 2 files changed, 123 insertions(+), 43 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m index 7e0b78ce1..a6fe96db9 100644 --- a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m +++ b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m @@ -59,6 +59,7 @@ #import #import #import +#import #import #import #import @@ -109,6 +110,40 @@ typedef enum : NSUInteger { kMediaTypeVideo, } kMediaTypes; +@protocol OWSMessagesCollectionViewFlowLayoutDelegate + +- (BOOL)isSpecialItemAtIndexPath:(NSIndexPath *)indexPath; + +@end + +#pragma mark - + +@interface OWSMessagesCollectionViewFlowLayout : JSQMessagesCollectionViewFlowLayout + +@property (nonatomic, weak) id delegate; + +@property (nonatomic) CGRect lastBounds; + +@end + +#pragma mark - + +@implementation OWSMessagesCollectionViewFlowLayout + +- (CGSize)sizeForItemAtIndexPath:(NSIndexPath *)indexPath +{ + // The unread indicator should be sized according to its desired size. + if ([self.delegate isSpecialItemAtIndexPath:indexPath]) { + CGSize messageBubbleSize = [self messageBubbleSizeForItemAtIndexPath:indexPath]; + CGFloat finalHeight = messageBubbleSize.height; + return CGSizeMake(CGRectGetWidth(self.collectionView.frame), ceilf((float)finalHeight)); + } else { + return [super sizeForItemAtIndexPath:indexPath]; + } +} + +@end + #pragma mark - @interface MessagesViewController () 0) { CGSize subtitleSize = [self.subtitleLabel sizeThatFits:CGSizeMake( self.contentView.width - [OWSUnreadIndicatorCell subtitleHMargin] * 2.f, CGFLOAT_MAX)]; - CGFloat contentHeight - = ceil(self.titleLabel.height) + OWSUnreadIndicatorCell.subtitleVSpacing + ceil(subtitleSize.height); - - self.titleLabel.frame = CGRectMake(round((self.titleLabel.superview.width - self.titleLabel.width) * 0.5f), - round((self.titleLabel.superview.height - contentHeight) * 0.5f), - ceil(self.titleLabel.width), - ceil(self.titleLabel.height)); self.subtitleLabel.frame = CGRectMake(round((self.titleLabel.superview.width - subtitleSize.width) * 0.5f), - round(self.titleLabel.bottom + OWSUnreadIndicatorCell.subtitleVSpacing), + round(self.titleBackgroundView.bottom + OWSUnreadIndicatorCell.subtitleVSpacing), ceil(subtitleSize.width), ceil(subtitleSize.height)); } - - self.leftPathView.frame = CGRectMake(0, self.titleLabel.top, self.titleLabel.left, self.titleLabel.height); - self.rightPathView.frame = CGRectMake( - self.titleLabel.right, self.titleLabel.top, self.width - self.titleLabel.right, self.titleLabel.height); } + (CGSize)cellSizeForInteraction:(TSUnreadIndicatorInteraction *)interaction collectionViewWidth:(CGFloat)collectionViewWidth { CGSize result = CGSizeMake(collectionViewWidth, 0); - result.height += self.vMargin * 2.f; + result.height += self.titleInnerVMargin * 2.f; + result.height += self.titleOuterVMargin * 2.f; + result.height += self.topVMargin; + result.height += self.bottomVMargin; NSString *title = [self titleForInteraction:interaction]; NSString *subtitle = [self subtitleForInteraction:interaction];