steve228uk / MessengerKit

:speech_balloon: A UI framework for building messenger interfaces on iOS
MIT License
1.48k stars 129 forks source link

Fails to detect emoji only message when there are more than 4 messages #27

Closed saurabhPV closed 5 years ago

saurabhPV commented 5 years ago

simulator screen shot - iphone x - 2019-02-01 at 16 34 07

sjoness commented 5 years ago

@saurabhPV This behaviour is intentional and can be seen in Messages.app.

You can override this behaviour by handling the inputViewPrimaryActionTriggered method in your MSGMessengerViewController subclass:

First, check if the message contains only emojis, if it does then set the MSGMessageBody type to .emoji, else default to .text, then instantiate your message variable and insert it into the collection view or dataSource.

override func inputViewPrimaryActionTriggered(inputView: MSGInputView) {
    id += 1

    let body: MSGMessageBody = inputView.message.containsOnlyEmoji ? .emoji(inputView.message) : .text(inputView.message)

    let message = MSGMessage(id: id, body: body, user: user, sentAt: Date())
    insert(message)
}
sjoness commented 5 years ago

However, any more than 5 emojis, and the message will truncate. You will need to create a custom style in order to handle the wrapping of the emoji messages if that's what you want.