1

I have been using MessageKit for my live chat feature for my application. One of the issues I am running into is that long messages just look very weird on the screen as the width of the bubbles doesn't seem to be restricted. I wanted to figure out a way to be able to set the maximum width of the chat bubbles so that they format more like a text conversation on the native imessage application.

Currently my messages look like this, but I would want the message below to be less wide and taller: enter image description here

Wana_B3_Nerd
  • 613
  • 3
  • 7
  • 21

2 Answers2

1

You can adjust the right/left padding for incoming/outgoing messages respectively.

The default padding is:

public var incomingMessagePadding = UIEdgeInsets(top: 0, left: 4, bottom: 0, right: 30)
public var outgoingMessagePadding = UIEdgeInsets(top: 0, left: 30, bottom: 0, right: 4)

And you can set the padding on the layout object in your messages view controller like this:

let layout = messagesCollectionView.collectionViewLayout as? MessagesCollectionViewFlowLayout
layout?.setMessageIncomingMessagePadding(UIEdgeInsets(top: 0, left: 4, bottom: 0, right: 50))
layout?.setMessageOutgoingMessagePadding(UIEdgeInsets(top: 0, left: 60, bottom: 0, right: 4))

You can see more examples of layout changes in the AdvancedExampleViewController in the MessageKit example project.

Kino Roy
  • 206
  • 2
  • 5
0

It seems that the library that you are using has already a width set, but in my chat (which is customised) I have a greater than or equal than 0 width constraint a a less than or equal than MAX_WIDTH constraint a leading constraint = 0 and a 'trailing constraint = 0' and those last two I get rid of the leading or trailing depending on if it is the sender or receiver of the message.

ERP
  • 325
  • 2
  • 11