From 026ef02ce5e81bf1838e7ea2c42235af0c87baec Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 31 Jul 2018 16:00:35 -0400 Subject: [PATCH 1/4] Refine 'new message' animations. --- .../Cells/OWSMessageBubbleView.m | 6 +++ .../ConversationViewController.m | 45 +++++++------------ .../ConversationView/ConversationViewLayout.m | 20 +++++++++ 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m index 199ed9033..19822ff7a 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m @@ -508,12 +508,18 @@ NS_ASSUME_NONNULL_BEGIN [self.bubbleView addPartnerView:shadowView]; [self.bubbleView addPartnerView:clipView]; + // Prevent the layer from animating changes. + [CATransaction begin]; + [CATransaction setDisableActions:YES]; + OWSAssert(buttonsView.backgroundColor); shadowView.fillColor = buttonsView.backgroundColor; shadowView.layer.shadowColor = [UIColor blackColor].CGColor; shadowView.layer.shadowOpacity = 0.12f; shadowView.layer.shadowOffset = CGSizeZero; shadowView.layer.shadowRadius = 1.f; + + [CATransaction commit]; } - (BOOL)contactShareHasSpacerTop diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 35e50c88a..a2f8eb578 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -3489,55 +3489,40 @@ typedef enum : NSUInteger { OWSAssert(rowChanges); // If user sends a new outgoing message, don't animate the change. - BOOL isOnlyInsertingNewOutgoingMessages = YES; - BOOL isOnlyUpdatingLastOutgoingMessage = YES; - NSNumber *_Nullable lastUpdateRow = nil; - NSNumber *_Nullable lastNonUpdateRow = nil; + BOOL isOnlyModifyingLastMessage = YES; for (YapDatabaseViewRowChange *rowChange in rowChanges) { switch (rowChange.type) { case YapDatabaseViewChangeDelete: - isOnlyInsertingNewOutgoingMessages = NO; - isOnlyUpdatingLastOutgoingMessage = NO; - if (!lastNonUpdateRow || lastNonUpdateRow.integerValue < rowChange.indexPath.row) { - lastNonUpdateRow = @(rowChange.indexPath.row); - } + isOnlyModifyingLastMessage = NO; break; case YapDatabaseViewChangeInsert: { - isOnlyUpdatingLastOutgoingMessage = NO; ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:(NSInteger)rowChange.finalIndex]; - if ([viewItem.interaction isKindOfClass:[TSOutgoingMessage class]] + if (([viewItem.interaction isKindOfClass:[TSIncomingMessage class]] || + [viewItem.interaction isKindOfClass:[TSOutgoingMessage class]]) && rowChange.finalIndex >= oldViewItemCount) { continue; } - if (!lastNonUpdateRow || lastNonUpdateRow.unsignedIntegerValue < rowChange.finalIndex) { - lastNonUpdateRow = @(rowChange.finalIndex); - } + isOnlyModifyingLastMessage = NO; } case YapDatabaseViewChangeMove: - isOnlyInsertingNewOutgoingMessages = NO; - isOnlyUpdatingLastOutgoingMessage = NO; - if (!lastNonUpdateRow || lastNonUpdateRow.integerValue < rowChange.indexPath.row) { - lastNonUpdateRow = @(rowChange.indexPath.row); - } - if (!lastNonUpdateRow || lastNonUpdateRow.unsignedIntegerValue < rowChange.finalIndex) { - lastNonUpdateRow = @(rowChange.finalIndex); - } + isOnlyModifyingLastMessage = NO; break; case YapDatabaseViewChangeUpdate: { - isOnlyInsertingNewOutgoingMessages = NO; - ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:(NSInteger)rowChange.finalIndex]; - if (![viewItem.interaction isKindOfClass:[TSOutgoingMessage class]] - || rowChange.indexPath.row != (NSInteger)(oldViewItemCount - 1)) { - isOnlyUpdatingLastOutgoingMessage = NO; + if (rowChange.changes == YapDatabaseViewChangedDependency) { + continue; } - if (!lastUpdateRow || lastUpdateRow.integerValue < rowChange.indexPath.row) { - lastUpdateRow = @(rowChange.indexPath.row); + ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:(NSInteger)rowChange.finalIndex]; + if (([viewItem.interaction isKindOfClass:[TSIncomingMessage class]] || + [viewItem.interaction isKindOfClass:[TSOutgoingMessage class]]) + && rowChange.finalIndex >= oldViewItemCount) { + continue; } + isOnlyModifyingLastMessage = NO; break; } } } - BOOL shouldAnimateRowUpdates = !(isOnlyInsertingNewOutgoingMessages || isOnlyUpdatingLastOutgoingMessage); + BOOL shouldAnimateRowUpdates = !isOnlyModifyingLastMessage; return shouldAnimateRowUpdates; } diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.m b/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.m index 305b9686b..a65bb8a31 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.m @@ -172,6 +172,26 @@ NS_ASSUME_NONNULL_BEGIN return self.collectionView.bounds.size.width != newBounds.size.width; } +- (nullable UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath: + (NSIndexPath *)indexPath +{ + UICollectionViewLayoutAttributes *_Nullable layoutAttributes = + [super initialLayoutAttributesForAppearingItemAtIndexPath:indexPath]; + // Don't fade in new cells. + layoutAttributes.alpha = 1.f; + return layoutAttributes; +} + +- (nullable UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath: + (NSIndexPath *)indexPath +{ + UICollectionViewLayoutAttributes *_Nullable layoutAttributes = + [super finalLayoutAttributesForDisappearingItemAtIndexPath:indexPath]; + // Don't fade in new cells. + layoutAttributes.alpha = 1.f; + return layoutAttributes; +} + @end NS_ASSUME_NONNULL_END From 24d85898e1be6436baaad05069ac5dc4e7dc9b6e Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 31 Jul 2018 16:02:39 -0400 Subject: [PATCH 2/4] Refine 'new message' animations. --- .../ConversationView/ConversationViewController.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index a2f8eb578..b63a84a02 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -3478,6 +3478,9 @@ typedef enum : NSUInteger { } else { [UIView performWithoutAnimation:^{ [self.collectionView performBatchUpdates:batchUpdates completion:batchUpdatesCompletion]; + if (scrollToBottom) { + [self scrollToBottomAnimated:NO]; + } }]; } self.lastReloadDate = [NSDate new]; From 995c2f2a2af997aef45ac5ebd7954d2a73dad3ba Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 31 Jul 2018 16:06:58 -0400 Subject: [PATCH 3/4] Refine 'new message' animations. --- .../ConversationView/ConversationViewController.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index b63a84a02..d7fdf01ee 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -3468,9 +3468,9 @@ typedef enum : NSUInteger { } [self updateLastVisibleTimestamp]; - - if (scrollToBottom) { - [self scrollToBottomAnimated:shouldAnimateScrollToBottom && shouldAnimateUpdates]; + + if (scrollToBottom && shouldAnimateUpdates) { + [self scrollToBottomAnimated:shouldAnimateScrollToBottom]; } }; if (shouldAnimateUpdates) { From cd6225c438ce614a3d56e7058342553c138576c5 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 31 Jul 2018 17:43:27 -0400 Subject: [PATCH 4/4] Respond to CR. --- .../ConversationView/ConversationViewLayout.m | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.m b/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.m index a65bb8a31..305b9686b 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewLayout.m @@ -172,26 +172,6 @@ NS_ASSUME_NONNULL_BEGIN return self.collectionView.bounds.size.width != newBounds.size.width; } -- (nullable UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath: - (NSIndexPath *)indexPath -{ - UICollectionViewLayoutAttributes *_Nullable layoutAttributes = - [super initialLayoutAttributesForAppearingItemAtIndexPath:indexPath]; - // Don't fade in new cells. - layoutAttributes.alpha = 1.f; - return layoutAttributes; -} - -- (nullable UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath: - (NSIndexPath *)indexPath -{ - UICollectionViewLayoutAttributes *_Nullable layoutAttributes = - [super finalLayoutAttributesForDisappearingItemAtIndexPath:indexPath]; - // Don't fade in new cells. - layoutAttributes.alpha = 1.f; - return layoutAttributes; -} - @end NS_ASSUME_NONNULL_END