Skip to content

Commit

Permalink
Added two public methods to control collectionview scroll animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Deepak committed Nov 28, 2014
1 parent fd7f27b commit 7234f10
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
20 changes: 12 additions & 8 deletions JSQMessagesViewController/Controllers/JSQMessagesViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,6 @@
*/
@property (assign, nonatomic) BOOL automaticallyScrollsToMostRecentMessage;

/**
* A boolean flag to disable the animation while scrolling to the latest message on entering the view
* and later reset to allow scroll animation.
*
*/

@property (assign, nonatomic) BOOL disableScrollToBottomAnimationOnEntry;

/**
* The collection view cell identifier to use for dequeuing outgoing message collection view cells
* in the collectionView for text messages.
Expand Down Expand Up @@ -258,4 +250,16 @@
*/
- (void)scrollToBottomAnimated:(BOOL)animated;

/**
* The following two methods are to take control of the animation while scrolling to the latest message (enable/disable it) on
* entering the view.
*/


- (void)finishSendingMessageAnimated:(BOOL)animated;


- (void)finishReceivingMessageAnimated:(BOOL)animated;

@end
43 changes: 34 additions & 9 deletions JSQMessagesViewController/Controllers/JSQMessagesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ - (void)jsq_configureMessagesViewController

self.automaticallyScrollsToMostRecentMessage = YES;

self.disableScrollToBottomAnimationOnEntry=YES;

self.outgoingCellIdentifier = [JSQMessagesCollectionViewCellOutgoing cellReuseIdentifier];
self.outgoingMediaCellIdentifier = [JSQMessagesCollectionViewCellOutgoing mediaCellReuseIdentifier];

Expand Down Expand Up @@ -339,15 +337,42 @@ - (void)finishReceivingMessage
[self.collectionView reloadData];

if (self.automaticallyScrollsToMostRecentMessage && ![self jsq_isMenuVisible]) {
if(self.disableScrollToBottomAnimationOnEntry){
[self scrollToBottomAnimated:NO];
self.disableScrollToBottomAnimationOnEntry=NO;
}
else{
[self scrollToBottomAnimated:YES];
}
[self scrollToBottomAnimated:YES];
}
}

- (void)finishSendingMessageAnimated:(BOOL)animated{

UITextView *textView = self.inputToolbar.contentView.textView;
textView.text = nil;
[textView.undoManager removeAllActions];

[self.inputToolbar toggleSendButtonEnabled];

[[NSNotificationCenter defaultCenter] postNotificationName:UITextViewTextDidChangeNotification object:textView];

[self.collectionView.collectionViewLayout invalidateLayoutWithContext:[JSQMessagesCollectionViewFlowLayoutInvalidationContext context]];
[self.collectionView reloadData];

if (self.automaticallyScrollsToMostRecentMessage) {
[self scrollToBottomAnimated:animated];
}


}

- (void)finishReceivingMessageAnimated:(BOOL)animated{

self.showTypingIndicator = NO;

[self.collectionView.collectionViewLayout invalidateLayoutWithContext:[JSQMessagesCollectionViewFlowLayoutInvalidationContext context]];
[self.collectionView reloadData];

if (self.automaticallyScrollsToMostRecentMessage && ![self jsq_isMenuVisible]) {
[self scrollToBottomAnimated:animated];
}


}

- (void)scrollToBottomAnimated:(BOOL)animated
Expand Down

0 comments on commit 7234f10

Please sign in to comment.