mirror of
https://github.com/MessageKit/MessageKit.git
synced 2026-02-06 19:03:19 +00:00
Remove different delegates for different message types
This commit is contained in:
@@ -234,7 +234,9 @@ extension ConversationViewController: MessagesDataSource {
|
||||
|
||||
// MARK: - MessagesDisplayDelegate
|
||||
|
||||
extension ConversationViewController: MessagesDisplayDelegate, TextMessageDisplayDelegate {
|
||||
extension ConversationViewController: MessagesDisplayDelegate {
|
||||
|
||||
// MARK: - All Messages
|
||||
|
||||
func backgroundColor(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UIColor {
|
||||
return isFromCurrentSender(message: message) ? UIColor(red: 69/255, green: 193/255, blue: 89/255, alpha: 1) : UIColor(red: 230/255, green: 230/255, blue: 230/255, alpha: 1)
|
||||
@@ -251,6 +253,28 @@ extension ConversationViewController: MessagesDisplayDelegate, TextMessageDispla
|
||||
// return .custom(configurationClosure)
|
||||
}
|
||||
|
||||
// MARK: - Location Messages
|
||||
|
||||
func annotationViewForLocation(message: MessageType, at indexPath: IndexPath, in messageCollectionView: MessagesCollectionView) -> MKAnnotationView? {
|
||||
let annotationView = MKAnnotationView(annotation: nil, reuseIdentifier: nil)
|
||||
let pinImage = #imageLiteral(resourceName: "pin")
|
||||
annotationView.image = pinImage
|
||||
annotationView.centerOffset = CGPoint(x: 0, y: -pinImage.size.height / 2)
|
||||
return annotationView
|
||||
}
|
||||
|
||||
func animationBlockForLocation(message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> ((UIImageView) -> Void)? {
|
||||
return { view in
|
||||
view.layer.transform = CATransform3DMakeScale(0, 0, 0)
|
||||
view.alpha = 0.0
|
||||
UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0, options: [], animations: {
|
||||
view.layer.transform = CATransform3DIdentity
|
||||
view.alpha = 1.0
|
||||
}, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// MARK: - MessagesLayoutDelegate
|
||||
@@ -286,11 +310,7 @@ extension ConversationViewController: MessagesLayoutDelegate {
|
||||
return CGSize(width: messagesCollectionView.bounds.width, height: 10)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - LocationMessageLayoutDelegate
|
||||
|
||||
extension ConversationViewController: LocationMessageLayoutDelegate {
|
||||
// MARK: - Location Messages
|
||||
|
||||
func heightForLocation(message: MessageType, at indexPath: IndexPath, with maxWidth: CGFloat, in messagesCollectionView: MessagesCollectionView) -> CGFloat {
|
||||
return 200
|
||||
@@ -298,10 +318,6 @@ extension ConversationViewController: LocationMessageLayoutDelegate {
|
||||
|
||||
}
|
||||
|
||||
// MARK: - MediaMessageLayoutDelegate
|
||||
|
||||
extension ConversationViewController: MediaMessageLayoutDelegate {}
|
||||
|
||||
// MARK: - MessageCellDelegate
|
||||
|
||||
extension ConversationViewController: MessageCellDelegate {
|
||||
@@ -346,31 +362,6 @@ extension ConversationViewController: MessageLabelDelegate {
|
||||
|
||||
}
|
||||
|
||||
// MARK: - LocationMessageDisplayDelegate
|
||||
|
||||
extension ConversationViewController: LocationMessageDisplayDelegate {
|
||||
|
||||
func annotationViewForLocation(message: MessageType, at indexPath: IndexPath, in messageCollectionView: MessagesCollectionView) -> MKAnnotationView? {
|
||||
let annotationView = MKAnnotationView(annotation: nil, reuseIdentifier: nil)
|
||||
let pinImage = #imageLiteral(resourceName: "pin")
|
||||
annotationView.image = pinImage
|
||||
annotationView.centerOffset = CGPoint(x: 0, y: -pinImage.size.height / 2)
|
||||
return annotationView
|
||||
}
|
||||
|
||||
func animationBlockForLocation(message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> ((UIImageView) -> Void)? {
|
||||
return { view in
|
||||
view.layer.transform = CATransform3DMakeScale(0, 0, 0)
|
||||
view.alpha = 0.0
|
||||
UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0, options: [], animations: {
|
||||
view.layer.transform = CATransform3DIdentity
|
||||
view.alpha = 1.0
|
||||
}, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - MessageInputBarDelegate
|
||||
|
||||
extension ConversationViewController: MessageInputBarDelegate {
|
||||
|
||||
Reference in New Issue
Block a user