From 273063e0aa86fc2ff7856028abcb63e846126eaa Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 22 Nov 2017 11:57:33 -0800 Subject: [PATCH] ConversationView first load avoids redundant layout We are laying out the collection view, invalidating the layout, and then laying out the collection view again on first appearance of the conversation view. This is quite expensive - removing it shaves off about 30% of load time. // FREEBIE --- .../ConversationView/ConversationViewController.m | 9 ++++++++- .../ConversationView/ConversationViewLayout.h | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index bdbc5e3b8..5280584f5 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -4461,7 +4461,14 @@ typedef enum : NSUInteger { // Snapshot the scroll state by measuring the "distance from top of view to // bottom of content"; if the mapping's "window" size grows, it will grow // _upward_. - CGFloat viewTopToContentBottom = self.safeContentHeight - self.collectionView.contentOffset.y; + CGFloat viewTopToContentBottom = 0; + if ([self.collectionView.collectionViewLayout isKindOfClass:[ConversationViewLayout class]]) { + ConversationViewLayout *conversationViewLayout + = (ConversationViewLayout *)self.collectionView.collectionViewLayout; + if (conversationViewLayout.hasLayout) { + viewTopToContentBottom = self.safeContentHeight - self.collectionView.contentOffset.y; + } + } NSUInteger oldCellCount = [self.messageMappings numberOfItemsInGroup:self.thread.uniqueId]; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.h b/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.h index 538192cf8..d617c7b6a 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.h +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.h @@ -37,7 +37,7 @@ typedef NS_ENUM(NSInteger, ConversationViewLayoutAlignment) { @interface ConversationViewLayout : UICollectionViewLayout @property (nonatomic, weak) id delegate; - +@property (nonatomic, readonly) BOOL hasLayout; @property (nonatomic, readonly) int contentWidth; @end