Skip to content

Commit

Permalink
Force Modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
SalomonBrys committed May 13, 2024
1 parent c74b04c commit 241083a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 27 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

allprojects {
group = "org.kodein.emoji"
version = "1.4.0"
version = "1.5.0"
}

allprojects {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.kodein.emoji.compose.demo

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.ProvideTextStyle
import androidx.compose.material.Text
Expand Down Expand Up @@ -34,22 +31,22 @@ fun App() {
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxSize()
) {
// ProvideTextStyle(TextStyle(fontSize = 32.sp)) {
// WithPlatformEmoji(
// "Platform:\nWhen I see :people-holding-hands~medium-light,medium-dark:, my <3 goes :collision: :D!".withEmoji()
// ) { text, inlineContent ->
// Text(text = text, inlineContent = inlineContent)
// }
//
// WithNotoAnimatedEmoji(
// "Animated:\nWhen I see ${Emoji.PeopleHoldingHands.mediumLight_mediumDark}, my ${Emoji.RedHeart} goes ${Emoji.Collision} ${Emoji.Smile}!"
// ) { text, inlineContent ->
// Text(text = text, inlineContent = inlineContent)
// }
// }
ProvideTextStyle(TextStyle(fontSize = 32.sp)) {
WithPlatformEmoji(
"Platform:\nWhen I see :people-holding-hands~medium-light,medium-dark:, my <3 goes :collision: :D!".withEmoji()
) { text, inlineContent ->
Text(text = text, inlineContent = inlineContent)
}

WithNotoAnimatedEmoji(
"Animated:\nWhen I see ${Emoji.PeopleHoldingHands.mediumLight_mediumDark}, my ${Emoji.RedHeart} goes ${Emoji.Collision} ${Emoji.Smile}!"
) { text, inlineContent ->
Text(text = text, inlineContent = inlineContent)
}
}
NotoAnimatedEmoji(
emoji = Emoji.ImpSmile,
modifier = Modifier.size(128.dp),
modifier = Modifier.size(64.dp).padding(top = 16.dp),
iterations = 2,
stopAt = 0.76f
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ public fun TextWithNotoAnimatedEmoji(
onTextLayout: (TextLayoutResult) -> Unit = {},
style: TextStyle = LocalTextStyle.current
) {
WithNotoAnimatedEmoji(text) { emojiAnnotatedString, emojiInlineContent ->
WithNotoAnimatedEmoji(
text = text,
iterations = iterations,
speed = speed
) { emojiAnnotatedString, emojiInlineContent ->
Text(
text = emojiAnnotatedString,
modifier = modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ internal expect fun PlatformEmojiPlaceholder(emoji: Emoji, modifier: Modifier)
* Shows an Emoji as an image downloaded from the Noto image library.
*
* @param emoji The Emoji to render
* @param modifier The modifier to be applied to the layout.
* @param modifier The **madatory** modifier that **must define the size of the displayed emoji**, to be applied to the layout.
* @param placeholder Composable that will be rendered in place during the download of the image.
*/
@Composable
public fun NotoImageEmoji(
emoji: Emoji,
modifier: Modifier = Modifier,
modifier: Modifier,
placeholder: @Composable () -> Unit = { PlatformEmojiPlaceholder(emoji, modifier) }
) {
val download = LocalEmojiDownloader.current
Expand All @@ -73,11 +73,25 @@ public fun NotoImageEmoji(
}
}

@Deprecated(
message = "Modifier that defines size (width & height) is mandatory",
replaceWith = ReplaceWith("NotoImageEmoji(emoji, Modifier.size(16.dp), placeholder)"),
level = DeprecationLevel.ERROR
)
@Composable
public fun NotoImageEmoji(
emoji: Emoji,
placeholder: @Composable () -> Unit = { PlatformEmojiPlaceholder(emoji, Modifier) }
) {
NotoImageEmoji(emoji, Modifier, placeholder)
}


/**
* Shows an animated Emoji if it is [Emoji.Details.notoAnimated], or defers to [NotoImageEmoji] if it is not.
*
* @param emoji The Emoji to render
* @param modifier The modifier to be applied to the layout.
* @param modifier The **madatory** modifier that **must define the size of the displayed emoji**, to be applied to the layout.
* @param iterations The number of times that the animation will be played (default is infinite).
* @param stopAt Progress that the emoji will stop at during its last iteration.
* @param speed Speed at which the animation will be rendered.
Expand All @@ -86,7 +100,7 @@ public fun NotoImageEmoji(
@Composable
public fun NotoAnimatedEmoji(
emoji: Emoji,
modifier: Modifier = Modifier,
modifier: Modifier,
iterations: Int = Int.MAX_VALUE,
stopAt: Float = 1f,
speed: Float = 1f,
Expand Down Expand Up @@ -120,3 +134,19 @@ public fun NotoAnimatedEmoji(
placeholder()
}
}

@Deprecated(
message = "Modifier that defines size (width & height) is mandatory",
replaceWith = ReplaceWith("NotoAnimatedEmoji(emoji, Modifier.size(16.dp), iterations, stopAt, speed, placeholder)"),
level = DeprecationLevel.ERROR
)
@Composable
public fun NotoAnimatedEmoji(
emoji: Emoji,
iterations: Int = Int.MAX_VALUE,
stopAt: Float = 1f,
speed: Float = 1f,
placeholder: @Composable () -> Unit = { PlatformEmojiPlaceholder(emoji, Modifier) }
) {
NotoAnimatedEmoji(emoji, Modifier, iterations, stopAt, speed, placeholder)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.kodein.emoji.compose

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.text.InlineTextContent
import androidx.compose.foundation.text.appendInlineContent
import androidx.compose.runtime.Composable
Expand All @@ -12,6 +13,7 @@ import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.Placeholder
import androidx.compose.ui.text.PlaceholderVerticalAlign
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.em
import kotlinx.coroutines.launch
import org.kodein.emoji.Emoji
Expand Down Expand Up @@ -88,7 +90,7 @@ private suspend fun createNotoSvgInlineContent(emoji: Emoji, download: suspend (
return InlineTextContent(
placeholder = Placeholder(1.em, 1.em / svg.sizeRatio(), PlaceholderVerticalAlign.Center),
children = {
SVGImage(svg, "${emoji.details.description} emoji", Modifier.fillMaxSize())
SVGImage(svg, "${emoji.details.description} emoji", Modifier.size(20.dp))
}
)
} catch (t: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal expect class SVGImage {
}

@Composable
internal expect fun SVGImage(image: SVGImage, contentDescription: String, modifier: Modifier = Modifier)
internal expect fun SVGImage(image: SVGImage, contentDescription: String, modifier: Modifier)

internal expect class LottieAnimation {
fun sizeRatio(): Float
Expand All @@ -28,5 +28,5 @@ internal expect fun LottieAnimation(
stopAt: Float,
speed: Float,
contentDescription: String,
modifier: Modifier = Modifier
modifier: Modifier
)

0 comments on commit 241083a

Please sign in to comment.