After tapping on a conversation, the chat screen will start at the top and then scroll all the way to the bottom. How can i bypass starting at the top and the scrolling to immediately displaying the most recent message at the bottom. This line of code is the closest thing i have found to doing what i want
messagesCollectionView.scrollToLastItem(animated: true)
This is how it's currently displaying and then it will scroll to the bottom when i enter into the conversation (notice date)
This is how i want it do display upon entering the conversation (notice date)
private func listenForMessages(id: String) {
Networking.shared.getComments(requestId: 15836, completionHandler: { [weak self] (result) in
switch result {
case .success(let comments):
guard !comments.isEmpty else {
return
}
self?.messages = comments
DispatchQueue.main.async {
self?.messagesCollectionView.reloadData()
self?.messagesCollectionView.scrollToLastItem()
}
case .failure(let error):
print("failed to get messages: \(error)")
}
})
}