From 81ed045718bead7333505a3746b24207dd830bf0 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 15 Mar 2017 14:46:03 -0300 Subject: [PATCH] Disable the "scroll to new message" animation. // FREEBIE --- .../view controllers/MessagesViewController.m | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Signal/src/view controllers/MessagesViewController.m b/Signal/src/view controllers/MessagesViewController.m index ec57dfa9c..3d2b555f4 100644 --- a/Signal/src/view controllers/MessagesViewController.m +++ b/Signal/src/view controllers/MessagesViewController.m @@ -2177,12 +2177,21 @@ typedef enum : NSUInteger { forNotifications:notifications withMappings:self.messageMappings]; - __block BOOL scrollToBottom = NO; - if ([sectionChanges count] == 0 & [messageRowChanges count] == 0) { return; } - + + __block BOOL scrollToBottom = NO; + const CGFloat kIsAtBottomTolerancePts = 5; + BOOL wasAtBottom = (self.collectionView.contentOffset.y + + self.collectionView.bounds.size.height + + kIsAtBottomTolerancePts >= + self.collectionView.contentSize.height); + // We want sending messages to feel snappy. So, if the only + // update is a new outgoing message AND we're already scrolled to + // the bottom of the conversation, skip the scroll animation. + __block BOOL shouldAnimateScrollToBottom = !wasAtBottom; + [self.collectionView performBatchUpdates:^{ for (YapDatabaseViewRowChange *rowChange in messageRowChanges) { switch (rowChange.type) { @@ -2193,11 +2202,17 @@ typedef enum : NSUInteger { if (collectionKey.key) { [self.messageAdapterCache removeObjectForKey:collectionKey.key]; } + break; } case YapDatabaseViewChangeInsert: { [self.collectionView insertItemsAtIndexPaths:@[ rowChange.newIndexPath ]]; scrollToBottom = YES; + + TSInteraction *interaction = [self interactionAtIndexPath:rowChange.newIndexPath]; + if (![interaction isKindOfClass:[TSOutgoingMessage class]]) { + shouldAnimateScrollToBottom = YES; + } break; } case YapDatabaseViewChangeMove: { @@ -2223,7 +2238,7 @@ typedef enum : NSUInteger { [self.collectionView reloadData]; } if (scrollToBottom) { - [self scrollToBottomAnimated:YES]; + [self scrollToBottomAnimated:shouldAnimateScrollToBottom]; } }]; }