Migration to 1.0.0 MessageKit Cocoapod with MessagesLayoutDelegate

117 Views Asked by At

When I try to upgrade to v1.0.0 of MessageKit, I get the following errors:

enter image description here

I'd be appreciative of a migration path to convert this to the new API. Thanks!

1

There are 1 best solutions below

3
On

It looks like there has been a change made to the LabelAlignment Class. It no longer has predefined .messageLeading but instead has a property for the textAlignment as a part of the LabelAlignment object. If you hold Command and click the LabelAlignment you can see its definition.

public var textAlignment: NSTextAlignment
public var textInsets: UIEdgeInsets

So all you need to do is adjust yours calls to the new constructor.

func cellTopLabelAlignment(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> LabelAlignment {
    if isFromCurrentSender(message: message) {
        return LabelAlignment(textAlignment: NSTextAlignment.left, textInsets: UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10))
    }
    return LabelAlignment(textAlignment: NSTextAlignment.right, textInsets: UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10))
}

If you want to find out all the changes that have happed in each release check out the ChangeLog here

Good luck