How do we show Emojis in Jetpack Compose? I came a...
# compose
k
How do we show Emojis in Jetpack Compose? I came across this open issue. Any updates on the same?
p
We created an EmojiPainter for that
k
@Paul Woitaschek thanks for the reply! Could you share the code? Have you tried using
androidx.emoji
?
p
Well we only use it to draw the emojis, not emojis in text
a
This has nothing to do with EmojiCompat. Java uses UTF-16 and
\uD83D\uDE02
is the UTF-16 representation of
U+1F602
. For more details see https://en.wikipedia.org/wiki/UTF-16#Code_points_from_U+010000_to_U+10FFFF.
🤯 2
k
Okay @Albert Chang 😮, so we will be maintaining these strings for custom Emoji Panel. Should we maintain the strings in UTF-8 or UTF-16 format, considering better support? If UTF-16, how to convert a UTF-8 string to UTF-16
a
If you want to use code points, you have to their UTF-16 representations. However you can directly use emojis as literals (e.g.
const val emoji = "😂"
).
p
Yeah but they will only work if they are supported by the system font
https://developer.android.com/jetpack/androidx/releases/emoji2 This has no integration with compose at all I guess?
k
Yup
p
And compose takes no spannable. So the only way is an androidView here
k
Which I don't think is a good idea in terms of performance.
375 Views