Refine 'new message' animations.

pull/1/head
Matthew Chen 7 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:shadowView];
[self.bubbleView addPartnerView:clipView]; [self.bubbleView addPartnerView:clipView];
// Prevent the layer from animating changes.
[CATransaction begin];
[CATransaction setDisableActions:YES];
OWSAssert(buttonsView.backgroundColor); OWSAssert(buttonsView.backgroundColor);
shadowView.fillColor = buttonsView.backgroundColor; shadowView.fillColor = buttonsView.backgroundColor;
shadowView.layer.shadowColor = [UIColor blackColor].CGColor; shadowView.layer.shadowColor = [UIColor blackColor].CGColor;
shadowView.layer.shadowOpacity = 0.12f; shadowView.layer.shadowOpacity = 0.12f;
shadowView.layer.shadowOffset = CGSizeZero; shadowView.layer.shadowOffset = CGSizeZero;
shadowView.layer.shadowRadius = 1.f; shadowView.layer.shadowRadius = 1.f;
[CATransaction commit];
} }
- (BOOL)contactShareHasSpacerTop - (BOOL)contactShareHasSpacerTop

@ -3489,55 +3489,40 @@ typedef enum : NSUInteger {
OWSAssert(rowChanges); OWSAssert(rowChanges);
// If user sends a new outgoing message, don't animate the change. // If user sends a new outgoing message, don't animate the change.
BOOL isOnlyInsertingNewOutgoingMessages = YES; BOOL isOnlyModifyingLastMessage = YES;
BOOL isOnlyUpdatingLastOutgoingMessage = YES;
NSNumber *_Nullable lastUpdateRow = nil;
NSNumber *_Nullable lastNonUpdateRow = nil;
for (YapDatabaseViewRowChange *rowChange in rowChanges) { for (YapDatabaseViewRowChange *rowChange in rowChanges) {
switch (rowChange.type) { switch (rowChange.type) {
case YapDatabaseViewChangeDelete: case YapDatabaseViewChangeDelete:
isOnlyInsertingNewOutgoingMessages = NO; isOnlyModifyingLastMessage = NO;
isOnlyUpdatingLastOutgoingMessage = NO;
if (!lastNonUpdateRow || lastNonUpdateRow.integerValue < rowChange.indexPath.row) {
lastNonUpdateRow = @(rowChange.indexPath.row);
}
break; break;
case YapDatabaseViewChangeInsert: { case YapDatabaseViewChangeInsert: {
isOnlyUpdatingLastOutgoingMessage = NO;
ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:(NSInteger)rowChange.finalIndex]; 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) { && rowChange.finalIndex >= oldViewItemCount) {
continue; continue;
} }
if (!lastNonUpdateRow || lastNonUpdateRow.unsignedIntegerValue < rowChange.finalIndex) { isOnlyModifyingLastMessage = NO;
lastNonUpdateRow = @(rowChange.finalIndex);
}
} }
case YapDatabaseViewChangeMove: case YapDatabaseViewChangeMove:
isOnlyInsertingNewOutgoingMessages = NO; isOnlyModifyingLastMessage = NO;
isOnlyUpdatingLastOutgoingMessage = NO;
if (!lastNonUpdateRow || lastNonUpdateRow.integerValue < rowChange.indexPath.row) {
lastNonUpdateRow = @(rowChange.indexPath.row);
}
if (!lastNonUpdateRow || lastNonUpdateRow.unsignedIntegerValue < rowChange.finalIndex) {
lastNonUpdateRow = @(rowChange.finalIndex);
}
break; break;
case YapDatabaseViewChangeUpdate: { case YapDatabaseViewChangeUpdate: {
isOnlyInsertingNewOutgoingMessages = NO; if (rowChange.changes == YapDatabaseViewChangedDependency) {
ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:(NSInteger)rowChange.finalIndex]; continue;
if (![viewItem.interaction isKindOfClass:[TSOutgoingMessage class]]
|| rowChange.indexPath.row != (NSInteger)(oldViewItemCount - 1)) {
isOnlyUpdatingLastOutgoingMessage = NO;
} }
if (!lastUpdateRow || lastUpdateRow.integerValue < rowChange.indexPath.row) { ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:(NSInteger)rowChange.finalIndex];
lastUpdateRow = @(rowChange.indexPath.row); if (([viewItem.interaction isKindOfClass:[TSIncomingMessage class]] ||
[viewItem.interaction isKindOfClass:[TSOutgoingMessage class]])
&& rowChange.finalIndex >= oldViewItemCount) {
continue;
} }
isOnlyModifyingLastMessage = NO;
break; break;
} }
} }
} }
BOOL shouldAnimateRowUpdates = !(isOnlyInsertingNewOutgoingMessages || isOnlyUpdatingLastOutgoingMessage); BOOL shouldAnimateRowUpdates = !isOnlyModifyingLastMessage;
return shouldAnimateRowUpdates; return shouldAnimateRowUpdates;
} }

@ -172,6 +172,26 @@ NS_ASSUME_NONNULL_BEGIN
return self.collectionView.bounds.size.width != newBounds.size.width; 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 @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

Loading…
Cancel
Save