I tried added in my app the same animation which, we can find in messenger, after click on some message, app shows date label. I can showed this date, but i can't add smooth animation. I tried added uiview.animate(withDuration), but in another topic I readed, that I need called method layoutIfNeed, but i can't handle any object from messagekit. Somebody can help me, or maybe gives me another way to do this sliding animation
func didTapMessage(in cell: MessageCollectionViewCell) {
if isClicked {
isClicked = false
if let layout = messagesCollectionView.collectionViewLayout as? MessagesCollectionViewFlowLayout {
layout.setMessageOutgoingMessagePadding(UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0))
}
} else {
isClicked = true
if let layout = messagesCollectionView.collectionViewLayout as? MessagesCollectionViewFlowLayout {
UIView.animate(withDuration: 3) {
//MARK: how called layoufIfNeeded()? or how do this animation another way
layout.collectionView?.layoutIfNeeded()
layout.setMessageOutgoingMessagePadding(UIEdgeInsets(top: 10, left: 0, bottom: 0, right: 0))
}
}
}
let indexPath = self.messagesCollectionView.indexPath(for: cell)!
messagesCollectionView.reloadItems(at: [indexPath])
}
First: You should create an array [IndexPath] to save indexPath of messages you tapped in
Second: You should use some function of MessagesLayoutDelegate protocol and MessagesDataSource protocol to set height or content for top, bottom message such as Date time, status message, ...
In there function, will check indexPath equal your saved indexPath tapped to show or hide Date time. It's up to your logical.