Skip to content

Add support for emoji-only messages#222

Merged
SD10 merged 7 commits into
MessageKit:v0.9.0from
SirArkimedes:v0.9.0
Oct 4, 2017
Merged

Add support for emoji-only messages#222
SD10 merged 7 commits into
MessageKit:v0.9.0from
SirArkimedes:v0.9.0

Conversation

@SirArkimedes

Copy link
Copy Markdown
Contributor

Adds a new message type that handles text that doubles the font size and removes the message background to model how iMessage displays emoji-only messages.

Issue: #182

Previews of how they look:

@SirArkimedes

SirArkimedes commented Oct 3, 2017

Copy link
Copy Markdown
Contributor Author

I do have a question, though. Should I force the "text" MessageData to use this "emoji" MessageData or should I leave it up to the user?

I know the issue talks about parsing, but was unsure if I should parse the message at all.

@SD10

SD10 commented Oct 3, 2017

Copy link
Copy Markdown
Member

@SirArkimedes This is a good start!! 👍 I was hoping we didn't have to create another subclass of MessagesCollectionViewCell and could just use TextMessageCell (I'm trying to decrease the number of different cell types we have).

I'll be able to review this a little more in-depth later.

About parsing, nothing to do there. It should be the user's responsibility to determine if a message contains only emojis or not.

cc @cwalo for some extra eyes

@fbartho

fbartho commented Oct 3, 2017

Copy link
Copy Markdown
Contributor

Re: parsing, you could add a utility method that trivially detects emoji (minus spaces), and add an example in documentation of how to use wire this together to return the right message type.

Adds a new message type that handles text that doubles the font size and removes the message background to model how iMessage displays emoji-only messages.
@eliburke

eliburke commented Oct 4, 2017

Copy link
Copy Markdown

If you don't want to embed emoji detection code, I'd suggest a comment pointing users at:
https://stackoverflow.com/a/39425959/1758224

Using these two extensions, the appropriate logic is:

if messageText.containsOnlyEmoji, messageText.glyphCount < 5 {
    // do the thing
}

@SD10

SD10 commented Oct 4, 2017

Copy link
Copy Markdown
Member

@fbartho @eliburke Both great points, thank you!!

@cwalo

cwalo commented Oct 4, 2017

Copy link
Copy Markdown
Contributor

Seconded @eliburke. Here's a gist with our extension (mostly lifted from the referenced SO answer). I'll check out what's been done so far.

Removes EmojiTextCell and takes what it used to doand  adds it to TextMessageCell.
@SirArkimedes

Copy link
Copy Markdown
Contributor Author

I can understand that adding a comment to make it clear how to use the emoji type, but where would I put that comment?

@SD10

SD10 commented Oct 4, 2017

Copy link
Copy Markdown
Member

@SirArkimedes This would be reflected in external docs. Don't worry about merging v0.9.0 too much. It's changing quickly. We'll rebase when I review this

// MARK: - Properties

open var messageLabelFont: UIFont
open var emojiLabelFont: UIFont

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be private if we're going to override it by doubling messageLabelFont

@@ -30,6 +30,8 @@ open class MessagesCollectionViewFlowLayout: UICollectionViewFlowLayout {
// MARK: - Properties

open var messageLabelFont: UIFont

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably needs a didSet to reflect the changes in emojiLabelFont

Comment thread Sources/MessagesViewController.swift Outdated
case .text, .attributedText:
let cell = messagesCollectionView.dequeueReusableCell(TextMessageCell.self, for: indexPath)
case .text, .attributedText, .emoji:
let cell = collectionView.dequeueReusableCell(TextMessageCell.self, for: indexPath)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be messagesCollectionView but maybe its because this branch is not current with v0.9.0

Comment thread Sources/TextMessageCell.swift Outdated
case .attributedText(let text):
messageContentView.attributedText = text
case .emoji(let text):
messageContainerView.backgroundColor = .clear

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking how to handle the style. Maybe we shouldn't set the color to .clear here and expect the user to apply a style of .none to the .emoji case.

@SirArkimedes SirArkimedes Oct 4, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was originally thinking the same thing, by just setting the style to .none here. But the MessageCollectionViewCell sets the background color from the delegate, which creates just a colored rectangle behind the message.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tough one. Can we just do this in the delegate then? You'll have to do an if case let or switch on the MessageType. If it is emoji return a .clear background color. Until we find a better way to handle it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to the delegate.

Also adds a didSet to the main font, to set the emoji’s font to double the set font.
@SD10

SD10 commented Oct 4, 2017

Copy link
Copy Markdown
Member

@SirArkimedes This looks good to me! We need to add a CHANGELOG entry under Added. This would be a breaking change notifying the users that we added a new .emoji(String) case to the MessageData type.

Please take care to follow the existing CHANGELOG in v0.9.0. We also have a CHANGELOG_GUIDELINES file in that PR

Adds .emoji(String) breaking change to CHANGELONG.md.
@SirArkimedes

Copy link
Copy Markdown
Contributor Author

Done!

@SD10 SD10 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SirArkimedes Thank you for your contribution to MessageKit 💯 🎉 I've invited you to join the MessageKit organization. No pressure if you aren't feeling up to it 😎

@SD10 SD10 merged commit c55db41 into MessageKit:v0.9.0 Oct 4, 2017
This was referenced Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants