From 4f3278db1ee8c5b8e824cc0f9692a3b5494a613b Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 16 Jun 2017 17:18:09 -0400 Subject: [PATCH] Fix layout of timestamp for system messages Incorporate topLabelSize into cell size for system messages. We are using the term "bubble size" to describe the interaction specific views of a collection cell. It's a crappy name, but coincides with other usage. // FREEBIE --- Signal.xcodeproj/project.pbxproj | 10 +++++----- .../Models/OWSMessagesBubblesSizeCalculator.m | 8 ++++---- .../ConversationView/MessagesViewController.m | 19 ++++++++++--------- Signal/src/views/OWSSystemMessageCell.h | 2 +- Signal/src/views/OWSSystemMessageCell.m | 12 ++---------- Signal/src/views/OWSUnreadIndicatorCell.h | 4 ++-- Signal/src/views/OWSUnreadIndicatorCell.m | 4 ++-- 7 files changed, 26 insertions(+), 33 deletions(-) diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index ef4dce017..0706ac717 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -372,8 +372,8 @@ 340CB2231EAC155C0001CAA1 /* ContactsViewHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactsViewHelper.m; sourceTree = ""; }; 340CB2251EAC25820001CAA1 /* UpdateGroupViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UpdateGroupViewController.h; sourceTree = ""; }; 340CB2261EAC25820001CAA1 /* UpdateGroupViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UpdateGroupViewController.m; sourceTree = ""; }; - 341207251EE19F6A00463194 /* OWSSystemMessageCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSSystemMessageCell.h; sourceTree = ""; }; - 341207261EE19F6A00463194 /* OWSSystemMessageCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSSystemMessageCell.m; sourceTree = ""; }; + 341207251EE19F6A00463194 /* OWSSystemMessageCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = OWSSystemMessageCell.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + 341207261EE19F6A00463194 /* OWSSystemMessageCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = OWSSystemMessageCell.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; 341BB7471DB727EE001E2975 /* JSQMediaItem+OWS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JSQMediaItem+OWS.h"; sourceTree = ""; }; 341BB7481DB727EE001E2975 /* JSQMediaItem+OWS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "JSQMediaItem+OWS.m"; sourceTree = ""; }; 34330A591E7875FB00DF2FB9 /* fontawesome-webfont.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "fontawesome-webfont.ttf"; sourceTree = ""; }; @@ -502,8 +502,8 @@ 34E8BF3A1EEB208E00F5F4CA /* DebugUIVerification.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DebugUIVerification.m; sourceTree = ""; }; 34F3089A1ECA4CDB00BB7697 /* TSUnreadIndicatorInteraction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TSUnreadIndicatorInteraction.h; sourceTree = ""; }; 34F3089B1ECA4CDB00BB7697 /* TSUnreadIndicatorInteraction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSUnreadIndicatorInteraction.m; sourceTree = ""; }; - 34F3089D1ECA580B00BB7697 /* OWSUnreadIndicatorCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSUnreadIndicatorCell.h; sourceTree = ""; }; - 34F3089E1ECA580B00BB7697 /* OWSUnreadIndicatorCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSUnreadIndicatorCell.m; sourceTree = ""; }; + 34F3089D1ECA580B00BB7697 /* OWSUnreadIndicatorCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = OWSUnreadIndicatorCell.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + 34F3089E1ECA580B00BB7697 /* OWSUnreadIndicatorCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = OWSUnreadIndicatorCell.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; 34F308A01ECB469700BB7697 /* OWSBezierPathView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSBezierPathView.h; sourceTree = ""; }; 34F308A11ECB469700BB7697 /* OWSBezierPathView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSBezierPathView.m; sourceTree = ""; }; 34FD936E1E3BD43A00109093 /* OWSAnyTouchGestureRecognizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OWSAnyTouchGestureRecognizer.h; path = views/OWSAnyTouchGestureRecognizer.h; sourceTree = ""; }; @@ -542,7 +542,7 @@ 45387B031E36D650005D00B3 /* OWS102MoveLoggingPreferenceToUserDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWS102MoveLoggingPreferenceToUserDefaults.m; path = Migrations/OWS102MoveLoggingPreferenceToUserDefaults.m; sourceTree = ""; }; 453CC0361D08E1A60040EBA3 /* sn */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sn; path = translations/sn.lproj/Localizable.strings; sourceTree = ""; }; 453D28B81D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMessagesBubblesSizeCalculator.h; sourceTree = ""; }; - 453D28B91D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSMessagesBubblesSizeCalculator.m; sourceTree = ""; }; + 453D28B91D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = OWSMessagesBubblesSizeCalculator.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; 4542F0931EB9372700C7EE92 /* SystemContactsFetcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SystemContactsFetcher.swift; sourceTree = ""; }; 4542F0951EBB9E9A00C7EE92 /* Promise+retainUntilComplete.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Promise+retainUntilComplete.swift"; sourceTree = ""; }; 45464DBB1DFA041F001D3FD6 /* DataChannelMessage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataChannelMessage.swift; sourceTree = ""; }; diff --git a/Signal/src/Models/OWSMessagesBubblesSizeCalculator.m b/Signal/src/Models/OWSMessagesBubblesSizeCalculator.m index 3e48bb822..056ffd175 100644 --- a/Signal/src/Models/OWSMessagesBubblesSizeCalculator.m +++ b/Signal/src/Models/OWSMessagesBubblesSizeCalculator.m @@ -128,8 +128,8 @@ NS_ASSUME_NONNULL_BEGIN return [cachedSize CGSizeValue]; } - CGSize result = [self.referenceSystemMessageCell cellSizeForInteraction:interaction - collectionViewWidth:layout.collectionView.width]; + CGSize result = [self.referenceSystemMessageCell bubbleSizeForInteraction:interaction + collectionViewWidth:layout.collectionView.width]; [self.cache setObject:[NSValue valueWithCGSize:result] forKey:cacheKey]; @@ -148,8 +148,8 @@ NS_ASSUME_NONNULL_BEGIN return [cachedSize CGSizeValue]; } - CGSize result = [self.referenceUnreadIndicatorCell cellSizeForInteraction:interaction - collectionViewWidth:layout.collectionView.width]; + CGSize result = [self.referenceUnreadIndicatorCell bubbleSizeForInteraction:interaction + collectionViewWidth:layout.collectionView.width]; [self.cache setObject:[NSValue valueWithCGSize:result] forKey:cacheKey]; diff --git a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m index d8d85c7f6..d6c0f2d6d 100644 --- a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m +++ b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m @@ -111,8 +111,8 @@ typedef enum : NSUInteger { @protocol OWSMessagesCollectionViewFlowLayoutDelegate -// Returns YES for incoming and outgoing text and attachment messages. -- (BOOL)isUserMessageAtIndexPath:(NSIndexPath *)indexPath; +// Returns YES for all but the unread indicator +- (BOOL)shouldShowCellDecorationsAtIndexPath:(NSIndexPath *)indexPath; @end @@ -131,12 +131,12 @@ typedef enum : NSUInteger { - (CGSize)sizeForItemAtIndexPath:(NSIndexPath *)indexPath { // The unread indicator should be sized according to its desired size. - if (![self.delegate isUserMessageAtIndexPath:indexPath]) { + if ([self.delegate shouldShowCellDecorationsAtIndexPath:indexPath]) { + return [super sizeForItemAtIndexPath:indexPath]; + } else { CGSize messageBubbleSize = [self messageBubbleSizeForItemAtIndexPath:indexPath]; CGFloat finalHeight = messageBubbleSize.height; return CGSizeMake(CGRectGetWidth(self.collectionView.frame), ceilf((float)finalHeight)); - } else { - return [super sizeForItemAtIndexPath:indexPath]; } } @@ -4097,12 +4097,13 @@ typedef enum : NSUInteger { #pragma mark - OWSMessagesCollectionViewFlowLayoutDelegate -- (BOOL)isUserMessageAtIndexPath:(NSIndexPath *)indexPath; + +- (BOOL)shouldShowCellDecorationsAtIndexPath:(NSIndexPath *)indexPath { - // TODO: Eventually it'd be nice to this in a more performant way. TSInteraction *interaction = [self interactionAtIndexPath:indexPath]; - return ( - [interaction isKindOfClass:[TSIncomingMessage class]] || [interaction isKindOfClass:[TSOutgoingMessage class]]); + + // Show any top/bottom labels for all but the unread indicator + return ![interaction isKindOfClass:[TSUnreadIndicatorInteraction class]]; } #pragma mark - Class methods diff --git a/Signal/src/views/OWSSystemMessageCell.h b/Signal/src/views/OWSSystemMessageCell.h index 839c79804..60dfc1444 100644 --- a/Signal/src/views/OWSSystemMessageCell.h +++ b/Signal/src/views/OWSSystemMessageCell.h @@ -25,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)configureWithInteraction:(TSInteraction *)interaction; -- (CGSize)cellSizeForInteraction:(TSInteraction *)interaction collectionViewWidth:(CGFloat)collectionViewWidth; +- (CGSize)bubbleSizeForInteraction:(TSInteraction *)interaction collectionViewWidth:(CGFloat)collectionViewWidth; @end diff --git a/Signal/src/views/OWSSystemMessageCell.m b/Signal/src/views/OWSSystemMessageCell.m index 43cf814e9..1a59b3d36 100644 --- a/Signal/src/views/OWSSystemMessageCell.m +++ b/Signal/src/views/OWSSystemMessageCell.m @@ -242,12 +242,6 @@ 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]; @@ -260,7 +254,7 @@ NS_ASSUME_NONNULL_BEGIN 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]; + CGFloat topLabelSpacing = topLabelSize.height; self.imageView.frame = CGRectMake(round((self.contentView.width - contentWidth) * 0.5f), round((self.contentView.height - [self iconSize] + topLabelSpacing) * 0.5f), @@ -273,7 +267,7 @@ NS_ASSUME_NONNULL_BEGIN ceil(titleSize.height + 1.f)); } -- (CGSize)cellSizeForInteraction:(TSInteraction *)interaction collectionViewWidth:(CGFloat)collectionViewWidth +- (CGSize)bubbleSizeForInteraction:(TSInteraction *)interaction collectionViewWidth:(CGFloat)collectionViewWidth { CGSize result = CGSizeMake(collectionViewWidth, 0); result.height += self.topVMargin; @@ -286,8 +280,6 @@ NS_ASSUME_NONNULL_BEGIN CGFloat contentHeight = ceil(MAX([self iconSize], titleSize.height)); result.height += contentHeight; - result.height += [self topLabelBottomMargin]; - return result; } diff --git a/Signal/src/views/OWSUnreadIndicatorCell.h b/Signal/src/views/OWSUnreadIndicatorCell.h index 1d013bce5..1adaa9f1a 100644 --- a/Signal/src/views/OWSUnreadIndicatorCell.h +++ b/Signal/src/views/OWSUnreadIndicatorCell.h @@ -15,8 +15,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)configureWithInteraction:(TSUnreadIndicatorInteraction *)interaction; -- (CGSize)cellSizeForInteraction:(TSUnreadIndicatorInteraction *)interaction - collectionViewWidth:(CGFloat)collectionViewWidth; +- (CGSize)bubbleSizeForInteraction:(TSUnreadIndicatorInteraction *)interaction + collectionViewWidth:(CGFloat)collectionViewWidth; @end diff --git a/Signal/src/views/OWSUnreadIndicatorCell.m b/Signal/src/views/OWSUnreadIndicatorCell.m index 3abaa0e8c..cabd09b38 100644 --- a/Signal/src/views/OWSUnreadIndicatorCell.m +++ b/Signal/src/views/OWSUnreadIndicatorCell.m @@ -200,8 +200,8 @@ NS_ASSUME_NONNULL_BEGIN } } -- (CGSize)cellSizeForInteraction:(TSUnreadIndicatorInteraction *)interaction - collectionViewWidth:(CGFloat)collectionViewWidth +- (CGSize)bubbleSizeForInteraction:(TSUnreadIndicatorInteraction *)interaction + collectionViewWidth:(CGFloat)collectionViewWidth { CGSize result = CGSizeMake(collectionViewWidth, 0); result.height += self.titleVMargin * 2.f;