Refine 'new message' animations.

pull/1/head
Matthew Chen 6 years ago committed by Michael Kirk
parent 2bb12e6fb4
commit 026ef02ce5

@ -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

@ -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;
}

@ -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

Loading…
Cancel
Save