From 0847c0bafb8a1e7a14a76fb3e543d2ff9bc80baf Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 13 Jul 2018 10:50:18 -0600 Subject: [PATCH] ScrollToBottom accounts for top inset // FREEBIE --- .../ConversationViewController.m | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index fb8c89142..2ec8df729 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -4286,13 +4286,27 @@ typedef enum : NSUInteger { // we use the collectionView bounds to determine where the "bottom" is. [self.view layoutIfNeeded]; - CGFloat contentHeight = self.safeContentHeight; + const CGFloat topInset = ^{ + if (@available(iOS 11, *)) { + return -self.collectionView.adjustedContentInset.top; + } else { + return -self.collectionView.contentInset.top; + } + }(); - // bottomLayoutGuide accounts for extra offset needed on iPhoneX + const CGFloat bottomInset = ^{ + if (@available(iOS 11, *)) { + return -self.collectionView.adjustedContentInset.bottom; + } else { + return -self.collectionView.contentInset.bottom; + } + }(); - CGFloat dstY = MAX(0, - contentHeight + self.collectionView.contentInset.bottom + self.bottomLayoutGuide.length - - self.collectionView.bounds.size.height); + const CGFloat firstContentPageTop = topInset; + const CGFloat collectionViewUnobscuredHeight = self.collectionView.bounds.size.height + bottomInset; + const CGFloat lastContentPageTop = self.safeContentHeight - collectionViewUnobscuredHeight; + + CGFloat dstY = MAX(firstContentPageTop, lastContentPageTop); [self.collectionView setContentOffset:CGPointMake(0, dstY) animated:NO]; [self didScrollToBottom];