How to remove bottom padding for custom cells using MessageKit with Swift?

54 Views Asked by At

This is my custom cell:

class DocumentCollectionViewCell: MessageContentCell {
    // ...
    override init(frame _: CGRect) {
        super.init(frame: .zero)
        setupView()
    }

    required init?(coder _: NSCoder) {
        nil
    }

    func configure(
        message: ChatMessageable,
        indexPath: IndexPath,
        view: MessagesCollectionView,
        theme: Themeable,
        isMe: Bool
    ) {
        // ...
        configure(with: message, at: indexPath, and: view)
    }

    private func setupView() {
        // ...
    }
}

and its calculator:

class DocumentCollectionViewCellSizeCalculator: MessageSizeCalculator {
    private let message: ChatMessageable

    private var size: CGSize {
        guard let layout = layout as? MessagesCollectionViewFlowLayout, let attachment = message.attachment else {
            return .zero
        }
        let height = attachment.type.isDocument ? 60.0 : 110.0
        return CGSize(width: layout.itemWidth, height: height)
    }

    // MARK: - Initialization

    init(message: ChatMessageable, layout: MessagesCollectionViewFlowLayout?) {
        self.message = message
        super.init(layout: layout)
        outgoingAvatarSize = .zero
        incomingMessagePadding = UIEdgeInsets(top: 0, left: 4, bottom: -15, right: 30) //doesn't work
        outgoingMessagePadding = UIEdgeInsets(top: 0, left: 30, bottom: -15, right: 4) //doesn't work
    }

    // MARK: - Overriden

    override func messageContainerSize(for _: MessageType) -> CGSize {
        size
    }

    override func sizeForItem(at _: IndexPath) -> CGSize {
        size
    }
}

And it look like this:

enter image description here

Images are my custom cells. Whatever I do it doesn't change the space between them. Why? It is only applied for predefined cells. Not for my custom ones. Why?

In my Controller, the following method:

func messageBottomLabelHeight(for message: MessageType, at _: IndexPath, in _: MessagesCollectionView) -> CGFloat {
    16
}

doesn't change anything for my custom cells, in opposite to predefined cells.

0

There are 0 best solutions below