Skip to content

Commit

Permalink
Merge pull request #7 from quipper/fix_reload
Browse files Browse the repository at this point in the history
avoid unneeded offset update
  • Loading branch information
m-sugawara authored Sep 17, 2019
2 parents ca81444 + 49d70ac commit 2c7ebe2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class AnnouncementExampleViewController: MessagesViewController {
conversationMessages = ConversationMessageMockFactory.getConversations()
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

messagesCollectionView.reloadDataAndKeepOffset()
}

func configureMessageCollectionView() {

if let layout = messagesCollectionView.collectionViewLayout as? MessagesCollectionViewFlowLayout {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Views/MessagesCollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ open class MessagesCollectionView: UICollectionView {
let newOffset = CGPoint(
x: contentOffset.x + (afterContentSize.width - beforeContentSize.width),
y: contentOffset.y + (afterContentSize.height - beforeContentSize.height))
// if offset.y is smaller than contentSize, no need to update contentOffset
guard newOffset.y >= contentSize.height else {
return
}
setContentOffset(newOffset, animated: false)
}

Expand Down

0 comments on commit 2c7ebe2

Please sign in to comment.