
Display and parse emoji in strings, extract and list emoji, replace short-codes/emoticons; render using Noto images or animations with system-font fallback and customizable download handling.
= Emoji.kt: Kotlin/Multiplatform Emoji :icons: font :toc: preamble :version: 2.3.0
Emoji.kt Core provides Kotlin/Multiplatform support for:
"Hello ${Emoji.Wink}, have a great day ${Emoji.WavingHand.mediumDark}, ${Emoji.RedHeart} you!".
String to locate and extract its emojis. +
Such as: finder.findEmoji("Hello π, have a great day ππΎ, β€οΈ you!").
Emoji.all().
String with short-codes and emoticons. +
Such as: catalog.replace("Hello :wink:, have a great day :waving-hand~medium-dark:, <3 you!").
Emoji.Wink.details.description.
Emoji.allEmojiGroups() and Emoji.subgroupsOf(group).
Emoji.Compose provides Compose/Multiplatform support for:
TextWithNotoImageEmoji(text).
TextWithNotoAnimatedEmoji(text).
TextWithPlatformEmoji(text).
ProvideEmojiDownloader(myDownloadFunction) { content() }.
image::img/compose-demo.gif[Demo, 350]
== Emoji.kt Core
=== Displaying Emoji in a Kotlin String
You can insert Emoji in a Kotlin String with the Emoji companion object extensions:
Some emoji can be specialized with skin tones:
=== Parsing a String to locate and extract its emojis
To parse a String with emojis, you first need to create an EmojiFinder.
Note that creating an EmojiFinder is expensive and can take a few milliseconds.
It is therefore advised that you:
EmojiFinder in background (for example in Dispatchers.Default if using coroutines).You can then use this EmojiFinder to extract emojis in your strings:
val emojiFinder = withContext(Dispatchers.Default) { EmojiFinder() }
=== Listing Emojis.
You can access a list of all known emoji with Emoji.all().
Note that creating the list of all known emoji with Emoji.all is expensive and can take a few milliseconds (this is a list of 1898 Emoji objects).
It is therefore advised that you:
Dispatchers.Default if using coroutines).=== Parsing a String with short-codes and emoticons.
To parse a String, with short-codes and emoticons you first need to create an EmojiTemplateCatalog.
Note that creating an EmojiTemplateCatalog is expensive and can take a few milliseconds.
It is therefore advised that you:
EmojiTemplateCatalog in background (for example in Dispatchers.Default if using coroutines).To create the EmojiTemplateCatalog, you need to pass to its constructor the list obtained with Emoji.all.
val allEmoji = withContext(Dispatchers.Default) { Emoji.all() } val emojiCatalog = withContext(Dispatchers.Default) { EmojiTemplateCatalog(allEmoji) }
An emoji can be described with:
:wink:
:waving-hand~medium-dark:
:people-holding-hands~medium-light,medium-dark:
You can add your own short-codes and emoticons when constructing the EmojiTemplateCatalog:
=== Getting emoji information
All emojis are described through their Emoji.Details data class. +
You can access:
emoji.details.string: The UTF-16 String containing the emoji.emoji.details.description: The description of this emoji as given by the Unicode standard.emoji.details.unicodeVersion: The emoji unicode definition minimum version where this emoji appears.emoji.details.aliases: The list of emoji aliases, as defined by the Unicode standard and the Noto font.emoji.details.emoticons: The list of emoticons that links to that emoji (such as ;) or \^_^;.emoji.details.notoAnimated: Whether this emoji is provided as an animation by the Noto font.emoji.details.codePoints(): The list of Unicode code-points of this emoji.=== Exploring emoji by groups subgroups
You can get:
val groups: List<String> = Emoji.allGroups()
val groups: List<Pair<String, String>> = Emoji.allSubgroups()
val groups: List<String> = Emoji.subgroupsOf(group)
val groupEmoji: List<Emoji> = Emoji.allOf(group)
val groupEmoji: List<Emoji> = Emoji.allOf(group, subgroup)
== Emoji.Compose
Emoji.Compose is not needed if you simply wish to display platform Emojis in a Compose application. + It is needed if any of the following is true:
=== Initializing the Emoji Service
The first time you use emoji composable functions, the emoji service will need to initialise, which may take a few milliseconds. You can initialise the emoji service ahead of time so that even the first emoji composable function invocation will be instantaneous:
<1> Service initialization happens in the background and will not block the UI thread.
=== Displaying Emoji with Noto vector images
You can display an Emoji Image with NotoImageEmoji:
You can display a String by replacing all of its emojis by images downloaded from the Noto font image library.
Note that if you want to use short-codes and emoticons, you need to parse the string with String.withEmoji first:
=== Displaying Emoji with Noto vector animations
Instead of using Noto images, you can use animations, if the emoji supports it.
NOTE: If the emoji does not support animation, than it will be displayed as a still image.
=== Using system font if supported and reverting to Noto images if it is not (on Wasm).
At the moment, Compose Wasm does not support displaying system font emoticons.
To circumvent that, WithPlatformEmoji changes the provided text only on Wasm to insert images instead of font emoticons.
On all other platforms, however, the emoji will not be replaced.
=== Handling downloads
Emoji.Compose does not depend on a particular HTTP library. It therefore offers the simplest of downloader: no retry support, no cache or offline support, etc.
If you are using Ktor, Coil, or any other multiplatform HTTP library, you can easily use it in Emoji.Compose:
=== Creating AnnotatedString
If you want to manipulate the annotatedString produced by the TextWith*Emoji functions, you can instead use the With*Emoji functions:
<1> text: AnnotatedString
<2> inlineContent: Map<String, InlineTextContent>
=== Customizing the Emoji Service
The EmojiService is the global reference to the EmojiFinder and EmojiTemplateCatalog used by this library. +
You can access it with:
@Composable fun EmojiService.get(): EmojiService?suspend fun EmojiService.await(): EmojiService.Before accessing it, you can add your own aliases and emoticons to the catalog:
== Supported by
image::https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg[JetBrains logo.,link=https://jb.gg/OpenSourceSupport]
= Emoji.kt: Kotlin/Multiplatform Emoji :icons: font :toc: preamble :version: 2.3.0
Emoji.kt Core provides Kotlin/Multiplatform support for:
"Hello ${Emoji.Wink}, have a great day ${Emoji.WavingHand.mediumDark}, ${Emoji.RedHeart} you!".
String to locate and extract its emojis. +
Such as: finder.findEmoji("Hello π, have a great day ππΎ, β€οΈ you!").
Emoji.all().
String with short-codes and emoticons. +
Such as: catalog.replace("Hello :wink:, have a great day :waving-hand~medium-dark:, <3 you!").
Emoji.Wink.details.description.
Emoji.allEmojiGroups() and Emoji.subgroupsOf(group).
Emoji.Compose provides Compose/Multiplatform support for:
TextWithNotoImageEmoji(text).
TextWithNotoAnimatedEmoji(text).
TextWithPlatformEmoji(text).
ProvideEmojiDownloader(myDownloadFunction) { content() }.
image::img/compose-demo.gif[Demo, 350]
== Emoji.kt Core
=== Displaying Emoji in a Kotlin String
You can insert Emoji in a Kotlin String with the Emoji companion object extensions:
Some emoji can be specialized with skin tones:
=== Parsing a String to locate and extract its emojis
To parse a String with emojis, you first need to create an EmojiFinder.
Note that creating an EmojiFinder is expensive and can take a few milliseconds.
It is therefore advised that you:
EmojiFinder in background (for example in Dispatchers.Default if using coroutines).You can then use this EmojiFinder to extract emojis in your strings:
val emojiFinder = withContext(Dispatchers.Default) { EmojiFinder() }
=== Listing Emojis.
You can access a list of all known emoji with Emoji.all().
Note that creating the list of all known emoji with Emoji.all is expensive and can take a few milliseconds (this is a list of 1898 Emoji objects).
It is therefore advised that you:
Dispatchers.Default if using coroutines).=== Parsing a String with short-codes and emoticons.
To parse a String, with short-codes and emoticons you first need to create an EmojiTemplateCatalog.
Note that creating an EmojiTemplateCatalog is expensive and can take a few milliseconds.
It is therefore advised that you:
EmojiTemplateCatalog in background (for example in Dispatchers.Default if using coroutines).To create the EmojiTemplateCatalog, you need to pass to its constructor the list obtained with Emoji.all.
val allEmoji = withContext(Dispatchers.Default) { Emoji.all() } val emojiCatalog = withContext(Dispatchers.Default) { EmojiTemplateCatalog(allEmoji) }
An emoji can be described with:
:wink:
:waving-hand~medium-dark:
:people-holding-hands~medium-light,medium-dark:
You can add your own short-codes and emoticons when constructing the EmojiTemplateCatalog:
=== Getting emoji information
All emojis are described through their Emoji.Details data class. +
You can access:
emoji.details.string: The UTF-16 String containing the emoji.emoji.details.description: The description of this emoji as given by the Unicode standard.emoji.details.unicodeVersion: The emoji unicode definition minimum version where this emoji appears.emoji.details.aliases: The list of emoji aliases, as defined by the Unicode standard and the Noto font.emoji.details.emoticons: The list of emoticons that links to that emoji (such as ;) or \^_^;.emoji.details.notoAnimated: Whether this emoji is provided as an animation by the Noto font.emoji.details.codePoints(): The list of Unicode code-points of this emoji.=== Exploring emoji by groups subgroups
You can get:
val groups: List<String> = Emoji.allGroups()
val groups: List<Pair<String, String>> = Emoji.allSubgroups()
val groups: List<String> = Emoji.subgroupsOf(group)
val groupEmoji: List<Emoji> = Emoji.allOf(group)
val groupEmoji: List<Emoji> = Emoji.allOf(group, subgroup)
== Emoji.Compose
Emoji.Compose is not needed if you simply wish to display platform Emojis in a Compose application. + It is needed if any of the following is true:
=== Initializing the Emoji Service
The first time you use emoji composable functions, the emoji service will need to initialise, which may take a few milliseconds. You can initialise the emoji service ahead of time so that even the first emoji composable function invocation will be instantaneous:
<1> Service initialization happens in the background and will not block the UI thread.
=== Displaying Emoji with Noto vector images
You can display an Emoji Image with NotoImageEmoji:
You can display a String by replacing all of its emojis by images downloaded from the Noto font image library.
Note that if you want to use short-codes and emoticons, you need to parse the string with String.withEmoji first:
=== Displaying Emoji with Noto vector animations
Instead of using Noto images, you can use animations, if the emoji supports it.
NOTE: If the emoji does not support animation, than it will be displayed as a still image.
=== Using system font if supported and reverting to Noto images if it is not (on Wasm).
At the moment, Compose Wasm does not support displaying system font emoticons.
To circumvent that, WithPlatformEmoji changes the provided text only on Wasm to insert images instead of font emoticons.
On all other platforms, however, the emoji will not be replaced.
=== Handling downloads
Emoji.Compose does not depend on a particular HTTP library. It therefore offers the simplest of downloader: no retry support, no cache or offline support, etc.
If you are using Ktor, Coil, or any other multiplatform HTTP library, you can easily use it in Emoji.Compose:
=== Creating AnnotatedString
If you want to manipulate the annotatedString produced by the TextWith*Emoji functions, you can instead use the With*Emoji functions:
<1> text: AnnotatedString
<2> inlineContent: Map<String, InlineTextContent>
=== Customizing the Emoji Service
The EmojiService is the global reference to the EmojiFinder and EmojiTemplateCatalog used by this library. +
You can access it with:
@Composable fun EmojiService.get(): EmojiService?suspend fun EmojiService.await(): EmojiService.Before accessing it, you can add your own aliases and emoticons to the catalog:
== Supported by
image::https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg[JetBrains logo.,link=https://jb.gg/OpenSourceSupport]