Skip to content

Commit 8acf85e

Browse files
committed
animate new cells even when springiness is disabled. close jessesquires#448.
1 parent e83b02a commit 8acf85e

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

JSQMessagesViewController/Layout/JSQMessagesCollectionViewFlowLayout.m

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -363,31 +363,32 @@ - (void)prepareForCollectionViewUpdates:(NSArray *)updateItems
363363
{
364364
[super prepareForCollectionViewUpdates:updateItems];
365365

366-
if (self.springinessEnabled) {
367-
[updateItems enumerateObjectsUsingBlock:^(UICollectionViewUpdateItem *updateItem, NSUInteger index, BOOL *stop) {
368-
if (updateItem.updateAction == UICollectionUpdateActionInsert) {
369-
370-
if ([self.dynamicAnimator layoutAttributesForCellAtIndexPath:updateItem.indexPathAfterUpdate]) {
371-
*stop = YES;
372-
}
373-
374-
CGSize size = self.collectionView.bounds.size;
375-
JSQMessagesCollectionViewLayoutAttributes *attributes = [JSQMessagesCollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:updateItem.indexPathAfterUpdate];
376-
377-
if (attributes.representedElementCategory == UICollectionElementCategoryCell) {
378-
[self jsq_configureMessageCellLayoutAttributes:attributes];
379-
}
380-
381-
attributes.frame = CGRectMake(0.0f,
382-
size.height - size.width,
383-
size.width,
384-
size.width);
385-
366+
[updateItems enumerateObjectsUsingBlock:^(UICollectionViewUpdateItem *updateItem, NSUInteger index, BOOL *stop) {
367+
if (updateItem.updateAction == UICollectionUpdateActionInsert) {
368+
369+
if (self.springinessEnabled && [self.dynamicAnimator layoutAttributesForCellAtIndexPath:updateItem.indexPathAfterUpdate]) {
370+
*stop = YES;
371+
}
372+
373+
CGFloat collectionViewHeight = CGRectGetHeight(self.collectionView.bounds);
374+
375+
JSQMessagesCollectionViewLayoutAttributes *attributes = [JSQMessagesCollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:updateItem.indexPathAfterUpdate];
376+
377+
if (attributes.representedElementCategory == UICollectionElementCategoryCell) {
378+
[self jsq_configureMessageCellLayoutAttributes:attributes];
379+
}
380+
381+
attributes.frame = CGRectMake(0.0f,
382+
collectionViewHeight + CGRectGetHeight(attributes.frame),
383+
CGRectGetWidth(attributes.frame),
384+
CGRectGetHeight(attributes.frame));
385+
386+
if (self.springinessEnabled) {
386387
UIAttachmentBehavior *springBehaviour = [self jsq_springBehaviorWithLayoutAttributesItem:attributes];
387388
[self.dynamicAnimator addBehavior:springBehaviour];
388389
}
389-
}];
390-
}
390+
}
391+
}];
391392
}
392393

393394
#pragma mark - Message cell layout utilities

0 commit comments

Comments
 (0)