From 370364c9369b369927a748ac64d8fc613f0df9ca Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 21 Nov 2017 11:42:11 -0500 Subject: [PATCH] Scroll down button scrolls to unread // FREEBIE --- .../ConversationViewController.m | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 909c8286b..d3c9f231e 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -2271,6 +2271,28 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { - (void)scrollDownButtonTapped { + NSIndexPath *indexPathOfUnreadMessagesIndicator = [self indexPathOfUnreadMessagesIndicator]; + if (indexPathOfUnreadMessagesIndicator != nil) { + NSInteger unreadRow = indexPathOfUnreadMessagesIndicator.row; + + BOOL isScrolledAboveUnreadIndicator = YES; + NSArray *visibleIndices = self.collectionView.indexPathsForVisibleItems; + for (NSIndexPath *indexPath in visibleIndices) { + if (indexPath.row > unreadRow) { + isScrolledAboveUnreadIndicator = NO; + break; + } + } + + if (isScrolledAboveUnreadIndicator) { + // Only scroll as far as the unread indicator if we're scrolled above the unread indicator. + [[self collectionView] scrollToItemAtIndexPath:indexPathOfUnreadMessagesIndicator + atScrollPosition:UICollectionViewScrollPositionTop + animated:YES]; + return; + } + } + [self scrollToBottomAnimated:YES]; }