Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
bin/
gen/

# Gradle files
# Gradle & Kotlin build files
.gradle/
.kotlin/
build/

# Local configuration file (sdk path, etc)
Expand Down
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ buildscript {
dependencies {
classpath(libs.plugin.android.cache.fix)
classpath(libs.plugin.androidgradleplugin)
classpath(libs.plugin.compose)
classpath(libs.plugin.compose.multiplatform)
classpath(libs.plugin.dokka)
classpath(libs.plugin.kotlin)
classpath(libs.plugin.licensee)
Expand Down
10 changes: 10 additions & 0 deletions emoji-compose/api/current.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Signature format: 4.0
package com.vanniktech.emoji.compose {

public final class EmojiPickerKt {
}

public final class EmojiPickerVariantPopupKt {
}

}
69 changes: 69 additions & 0 deletions emoji-compose/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
plugins {
id("org.jetbrains.dokka")
id("org.jetbrains.kotlin.multiplatform")
id("org.jetbrains.compose")
id("org.jetbrains.kotlin.plugin.compose")
id("com.android.library")
id("org.jetbrains.kotlin.plugin.parcelize")
id("me.tylerbwong.gradle.metalava")
id("com.vanniktech.maven.publish")
id("app.cash.licensee")
}

licensee {
allow("Apache-2.0")
}

metalava {
filename.set("api/current.txt")
}

kotlin {
applyDefaultHierarchyTemplate()

androidTarget {
publishLibraryVariants("release")
}

sourceSets {
val commonMain by getting {
dependencies {
api(project(":emoji"))
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.ui)
implementation(compose.components.resources)
}
}

val commonTest by getting {
dependencies {
implementation(libs.kotlin.test)
}
}

val androidMain by getting {
dependencies {
}
}

val androidUnitTest by getting {
dependencies {
implementation(libs.kotlin.test.junit)
}
}
}
}

android {
namespace = "com.vanniktech.emoji.compose"

compileSdk = libs.versions.compileSdk.get().toInt()

defaultConfig {
minSdk = libs.versions.minSdk.get().toInt()
}

resourcePrefix = "emoji_"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2016 - Niklas Baudy, Ruben Gees, Mario Đanić and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.vanniktech.emoji.compose

import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
import androidx.compose.ui.graphics.nativeCanvas
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.sp
import com.vanniktech.emoji.Emoji
import com.vanniktech.emoji.EmojiAndroidProvider
import com.vanniktech.emoji.EmojiProvider
import kotlin.math.roundToInt

/**
* Android actual implementation of [EmojiImage].
* Renders the provider drawable via Canvas, falling back to unicode text font.
*/
@Composable actual fun EmojiImage(
emoji: Emoji,
provider: EmojiProvider?,
modifier: Modifier,
) {
val context = LocalContext.current
val drawable = remember(emoji, provider, context) {
if (provider is EmojiAndroidProvider) {
try {
provider.getDrawable(emoji, context)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hmmm can we use skia or the normal resource system to make this truly multiplatform?

} catch (_: Exception) { null }
} else null
}

if (drawable != null) {
Canvas(modifier = modifier) {
drawIntoCanvas { canvas ->
drawable.setBounds(0, 0, size.width.roundToInt(), size.height.roundToInt())
drawable.draw(canvas.nativeCanvas)
}
}
} else {
BoxWithConstraints(
modifier = modifier,
contentAlignment = Alignment.Center,
) {
val fontSize = (minOf(maxWidth, maxHeight).value * 0.75f).sp
Text(
text = emoji.unicode,
fontSize = fontSize,
textAlign = TextAlign.Center,
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2016 - Niklas Baudy, Ruben Gees, Mario Đanić and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.vanniktech.emoji.compose
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import com.vanniktech.emoji.recent.RecentEmoji
import com.vanniktech.emoji.recent.RecentEmojiManager
import com.vanniktech.emoji.variant.VariantEmoji
import com.vanniktech.emoji.variant.VariantEmojiManager

/**
* Returns the default [RecentEmojiManager] for Android using [LocalContext].
*/
@Composable actual fun rememberDefaultRecentEmoji(): RecentEmoji {
val context = LocalContext.current

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

There must also be something for commonMain, right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

For commonMain, should we default to NoRecentEmoji / NoVariantEmoji or something like an in-memory session manager? And for other platforms native storage like NSUserDefaults for iOS and Preferences for Desktop?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

NSUserDefaults for iOS, Preferences for Desktop and then we don't need the NoOp, right?

return remember(context) { RecentEmojiManager(context) }
}

/**
* Returns the default [VariantEmojiManager] for Android using [LocalContext].
*/
@Composable actual fun rememberDefaultVariantEmoji(): VariantEmoji {
val context = LocalContext.current
return remember(context) { VariantEmojiManager(context) }
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M240,760L240,780Q240,805 222.5,822.5Q205,840 180,840Q155,840 137.5,822.5Q120,805 120,780L120,494Q120,487 121,480Q122,473 124,467L199,254Q207,230 228,215Q249,200 275,200L685,200Q711,200 732,215Q753,230 761,254L836,467Q838,473 839,480Q840,487 840,494L840,780Q840,805 822.5,822.5Q805,840 780,840Q755,840 737.5,822.5Q720,805 720,780L720,760L240,760ZM232,400L728,400L686,280Q686,280 686,280Q686,280 686,280L274,280Q274,280 274,280Q274,280 274,280L232,400ZM200,480L200,480L200,680L200,680L200,480ZM300,640Q325,640 342.5,622.5Q360,605 360,580Q360,555 342.5,537.5Q325,520 300,520Q275,520 257.5,537.5Q240,555 240,580Q240,605 257.5,622.5Q275,640 300,640ZM660,640Q685,640 702.5,622.5Q720,605 720,580Q720,555 702.5,537.5Q685,520 660,520Q635,520 617.5,537.5Q600,555 600,580Q600,605 617.5,622.5Q635,640 660,640ZM200,680L760,680L760,480L200,480L200,680Z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M200,840Q183,840 171.5,828.5Q160,817 160,800Q160,783 171.5,771.5Q183,760 200,760L760,760Q777,760 788.5,771.5Q800,783 800,800Q800,817 788.5,828.5Q777,840 760,840L200,840ZM320,680Q254,680 207,633Q160,586 160,520L160,209Q160,172 186,146Q212,120 249,120L800,120Q833,120 856.5,143.5Q880,167 880,200L880,320Q880,353 856.5,376.5Q833,400 800,400L720,400L720,520Q720,586 673,633Q626,680 560,680L320,680ZM320,200L560,200Q593,200 616.5,200Q640,200 640,200L640,200L240,200L240,200Q240,200 263.5,200Q287,200 320,200ZM720,320L800,320Q800,320 800,320Q800,320 800,320L800,200Q800,200 800,200Q800,200 800,200L720,200L720,320ZM560,600Q593,600 616.5,576.5Q640,553 640,520L640,200L400,200L400,216L472,274Q474,276 480,290L480,460Q480,468 474,474Q468,480 460,480L300,480Q292,480 286,474Q280,468 280,460L280,290Q280,288 288,274L360,216L360,200L240,200L240,520Q240,553 263.5,576.5Q287,600 320,600L560,600ZM360,200L360,200L400,200L400,200L360,200Z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M720,360L688,388Q674,401 655,401Q636,401 622,390Q608,379 603,362Q598,345 604,326L620,276L586,256Q570,247 563.5,230Q557,213 562,196Q567,179 582,169.5Q597,160 616,160L656,160L668,122Q674,103 688.5,91.5Q703,80 720,80Q737,80 751.5,91.5Q766,103 772,122L784,160L824,160Q843,160 857.5,169.5Q872,179 878,196Q885,214 878,231Q871,248 856,256L820,276L836,326Q842,345 837,362.5Q832,380 818,390Q803,401 784.5,401Q766,401 752,388L720,360ZM748.5,268.5Q760,257 760,240Q760,223 748.5,211.5Q737,200 720,200Q703,200 691.5,211.5Q680,223 680,240Q680,257 691.5,268.5Q703,280 720,280Q737,280 748.5,268.5ZM552,716Q575,776 537,828Q499,880 430,880Q397,880 367.5,863Q338,846 324,818Q241,830 186.5,775.5Q132,721 142,636Q112,619 96,589.5Q80,560 80,522Q80,461 135.5,423.5Q191,386 244,408L306,434Q326,403 359,383.5Q392,364 430,362L430,310Q430,297 438.5,288.5Q447,280 460,280Q473,280 481.5,288.5Q490,297 490,310L490,370Q527,381 551,404.5Q575,428 592,470L650,470Q663,470 671.5,478.5Q680,487 680,500Q680,513 671.5,521.5Q663,530 650,530L598,530Q596,568 577.5,601Q559,634 528,654L552,716ZM304,740Q304,713 308.5,687.5Q313,662 322,638Q299,649 272.5,653.5Q246,658 220,656Q220,695 242.5,717.5Q265,740 304,740ZM230,576Q262,576 286.5,568Q311,560 350,536L230,486Q201,474 180.5,486.5Q160,499 160,526Q160,552 177,564Q194,576 230,576ZM430,800Q455,800 470.5,782.5Q486,765 478,746L424,610Q405,642 394.5,674Q384,706 384,732Q384,765 395.5,782.5Q407,800 430,800ZM496,578Q506,568 512,551.5Q518,535 518,517Q518,485 497,463Q476,441 445,441Q427,441 411,447Q395,453 384,464L462,500L496,578ZM322,638Q322,638 322,638Q322,638 322,638Q322,638 322,638Q322,638 322,638Q322,638 322,638Q322,638 322,638Z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M480,880Q454,880 433,867.5Q412,855 400,834L400,834Q367,834 343.5,810.5Q320,787 320,754L320,612Q261,573 225.5,509Q190,445 190,370Q190,249 274.5,164.5Q359,80 480,80Q601,80 685.5,164.5Q770,249 770,370Q770,447 734.5,510Q699,573 640,612L640,754Q640,787 616.5,810.5Q593,834 560,834L560,834Q548,855 527,867.5Q506,880 480,880ZM400,754L560,754L560,718L400,718L400,754ZM400,678L560,678L560,640L400,640L400,678ZM392,560L450,560L450,452L383,385Q374,376 374,364Q374,352 383,343Q392,334 404,334Q416,334 425,343L480,398L535,343Q544,334 556,334Q568,334 577,343Q586,352 586,364Q586,376 577,385L510,452L510,560L568,560Q622,534 656,483.5Q690,433 690,370Q690,282 629,221Q568,160 480,160Q392,160 331,221Q270,282 270,370Q270,433 304,483.5Q338,534 392,560ZM480,398L480,398L480,398L480,398L480,398L480,398L480,398L480,398L480,398ZM480,360Q480,360 480,360Q480,360 480,360Q480,360 480,360Q480,360 480,360Q480,360 480,360Q480,360 480,360Q480,360 480,360Q480,360 480,360L480,360L480,360L480,360L480,360L480,360L480,360L480,360L480,360L480,360Z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M400,160L160,160Q143,160 131.5,148.5Q120,137 120,120Q120,103 131.5,91.5Q143,80 160,80L400,80Q417,80 428.5,91.5Q440,103 440,120Q440,137 428.5,148.5Q417,160 400,160ZM240,280L160,280Q143,280 131.5,268.5Q120,257 120,240Q120,223 131.5,211.5Q143,200 160,200L400,200Q417,200 428.5,211.5Q440,223 440,240Q440,257 428.5,268.5Q417,280 400,280L320,280L320,400Q320,417 308.5,428.5Q297,440 280,440Q263,440 251.5,428.5Q240,417 240,400L240,280ZM576,836Q565,847 548,847Q531,847 520,836Q509,825 509,808Q509,791 520,780L776,524Q787,513 804,513Q821,513 832,524Q843,535 843,552Q843,569 832,580L576,836ZM537,623Q520,606 520,580Q520,554 537,537Q554,520 580,520Q606,520 623,537Q640,554 640,580Q640,606 623,623Q606,640 580,640Q554,640 537,623ZM737,823Q720,806 720,780Q720,754 737,737Q754,720 780,720Q806,720 823,737Q840,754 840,780Q840,806 823,823Q806,840 780,840Q754,840 737,823ZM549.5,410.5Q520,381 520,340Q520,299 549.5,268.5Q579,238 620,238Q632,238 641.5,239.5Q651,241 660,244L660,120Q660,103 671.5,91.5Q683,80 700,80L800,80Q817,80 828.5,91.5Q840,103 840,120Q840,137 828.5,148.5Q817,160 800,160L720,160L720,340Q720,381 690.5,410.5Q661,440 620,440Q579,440 549.5,410.5ZM220,880Q179,880 149.5,849.5Q120,819 120,778Q120,760 127.5,741.5Q135,723 150,708L192,666L178,652Q163,637 155.5,619.5Q148,602 148,582Q148,541 177.5,511.5Q207,482 248,482Q289,482 318.5,511.5Q348,541 348,582Q348,602 341.5,619.5Q335,637 320,652L306,666L334,694L361,667Q373,655 389.5,655.5Q406,656 418,668Q429,680 429.5,696Q430,712 418,724L390,752L418,780Q429,791 429,808Q429,825 418,836Q407,847 390,847Q373,847 362,836L334,808L292,850Q277,865 258.5,872.5Q240,880 220,880ZM248,610L262,596Q265,593 266.5,590Q268,587 268,582Q268,573 262,567.5Q256,562 248,562Q240,562 234,567.5Q228,573 228,582Q228,585 229.5,589Q231,593 234,596L248,610ZM218,800Q221,800 226,798.5Q231,797 234,794L278,752L250,724L206,766Q203,769 201.5,773Q200,777 200,782Q200,790 205,795Q210,800 218,800Z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M280,560L280,800Q280,817 268.5,828.5Q257,840 240,840Q223,840 211.5,828.5Q200,817 200,800L200,200Q200,183 211.5,171.5Q223,160 240,160L527,160Q541,160 552,169Q563,178 566,192L576,240L760,240Q777,240 788.5,251.5Q800,263 800,280L800,600Q800,617 788.5,628.5Q777,640 760,640L553,640Q539,640 528,631Q517,622 514,608L504,560L280,560ZM586,560L720,560L720,320L543,320Q529,320 518,311Q507,302 504,288L494,240L280,240L280,480L537,480Q551,480 562,489Q573,498 576,512L586,560ZM500,400L500,400Q500,400 500,400Q500,400 500,400L500,400L500,400L500,400L500,400Q500,400 500,400Q500,400 500,400L500,400L500,400Z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M520,464L520,320Q520,303 508.5,291.5Q497,280 480,280Q463,280 451.5,291.5Q440,303 440,320L440,479Q440,487 443,494.5Q446,502 452,508L584,640Q595,651 612,651Q629,651 640,640Q651,629 651,612Q651,595 640,584L520,464ZM480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480ZM480,800Q613,800 706.5,706.5Q800,613 800,480Q800,347 706.5,253.5Q613,160 480,160Q347,160 253.5,253.5Q160,347 160,480Q160,613 253.5,706.5Q347,800 480,800Z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M480,700Q538,700 587,672Q636,644 666,596Q672,584 665,572Q658,560 644,560L316,560Q302,560 295,572Q288,584 294,596Q324,644 373.5,672Q423,700 480,700ZM356,398L377,419Q386,428 398,428Q410,428 419,419Q428,410 427.5,398Q427,386 419,377L384,341Q372,329 355.5,329Q339,329 327,341L291,377Q282,386 282,398Q282,410 291,419Q299,427 311.5,427.5Q324,428 333,420L356,398ZM604,398L627,420Q636,428 648,428Q660,428 669,419Q678,410 678,398Q678,386 669,377L633,341Q621,329 604.5,329Q588,329 576,341L540,377Q532,386 532,398Q532,410 541,419Q550,428 562,428Q574,428 583,419L604,398ZM324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880Q397,880 324,848.5ZM480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480ZM707,707Q800,614 800,480Q800,346 707,253Q614,160 480,160Q346,160 253,253Q160,346 160,480Q160,614 253,707Q346,800 480,800Q614,800 707,707Z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM680,380L734,362L750,308Q718,260 673,225.5Q628,191 574,174L520,212L520,268L680,380ZM280,380L440,268L440,212L386,174Q332,191 287,225.5Q242,260 210,308L226,362L280,380ZM238,688L284,684L314,630L256,456L200,436L160,466Q160,531 178,584.5Q196,638 238,688ZM531,796Q556,792 580,784L608,724L582,680L378,680L352,724L380,784Q404,792 429,796Q454,800 480,800Q506,800 531,796ZM390,600L570,600L626,440L480,338L336,440L390,600ZM722,688Q764,638 782,584.5Q800,531 800,466L760,438L704,456L646,630L676,684L722,688Z"/>
</vector>
Loading